int main() { using namespace Graph_lib; Simple_window win {Point{100, 100}, x_max(), y_max(), "Exercise 5"}; Rectangle r {Point{150, 150}, static_cast<int>(0.75 * x_max()), static_cast<int>(0.75 * y_max())}; int width = pixels(0.25); Rectangle b1 {Point{150 - width, 150 - width}, static_cast<int>(0.75 * x_max() + 2 * width), width}; Rectangle b2 {Point{150 - width, static_cast<int>(150 + 0.75 * y_max())}, static_cast<int>(0.75 * x_max() + 2 * width), width}; Rectangle b3 {Point{150 - width, 150}, width, static_cast<int>(0.75 * y_max())}; Rectangle b4 {Point{static_cast<int>(150 + 0.75 * x_max()), 150}, width, static_cast<int>(0.75 * y_max())}; r.set_fill_color(Color::white); b1.set_fill_color(Color::red); b2.set_fill_color(Color::red); b3.set_fill_color(Color::red); b4.set_fill_color(Color::red); win.attach(r); win.attach(b1); win.attach(b2); win.attach(b3); win.attach(b4); win.wait_for_button(); }
void test_rects(Simple_window &win) { Rectangle r00 {Point{150, 100}, 200, 100}; Rectangle r11 {Point{50, 50}, Point{250, 150}}; Rectangle r12 {Point{50, 150}, Point{250, 250}}; Rectangle r21 {Point{250, 50}, 200, 100}; Rectangle r22 {Point{250, 150}, 200, 100}; r00.set_color(Color::invisible); r11.set_color(Color::invisible); r12.set_color(Color::invisible); r21.set_color(Color::invisible); //r22.set_color(Color::invisible); r00.set_fill_color(Color::yellow); r11.set_fill_color(Color::blue); r12.set_fill_color(Color::red); r21.set_fill_color(Color::green); r11.move(400, 0); r11.set_fill_color(Color::white); win.attach(r00); win.attach(r11); win.attach(r12); win.attach(r21); win.attach(r22); win.put_on_top(r00); win.wait_for_button(); }
int main() { Point t1 {100,100}; Simple_window win {t1, 600, 400, "My window"}; win.wait_for_button(); }
int main () { using namespace Graph_lib; // our graphics facilities are in Graph_lib namespace constexpr Point pt{100,100}; // to become top left corner of window Simple_window win {pt, 600, 400,"ch13.5_LineStile"}; // make a simple window, {top_left, width, hight, title} const int x_size = win.x_max(); const int y_size = win.y_max(); const int x_grid = 80; const int y_grid = 40; Lines grid; for (int x=x_grid; x<x_size; x+=x_grid) grid.add(Point{x,0},Point{x,y_size}); // vertical line for (int y=y_grid; y<y_size; y+=y_grid) grid.add(Point{0,y},Point{x_size,y}); // horizontal line grid.set_color(Color::red); // set color (chould affect both lines //grid.set_style(Line_style{Line_style::dot,2}); //grid.set_style(Line_style::dashdot); grid.set_style(Line_style{Line_style::dashdot,2}); win.attach(grid); win.wait_for_button(); // display! }
int main() { using namespace Graph_lib; Simple_window win {Point{100, 100}, 800, 600, "Exercise 9"}; Checker ck {50}; ck.set_color(Color::green); Circle c {Point{200, 200}, 30}; c.set_color(Color::black); c.set_fill_color(Color::white); Rectangle r {Point{100, 50}, 30, 40}; r.set_color(Color::red); r.set_fill_color(Color::yellow); ck.add_shape(c); ck.add_shape(r); ck.move(0, 4, 1); ck.move(1, 5, 3); win.attach(ck); win.attach(ck.shape(0)); win.attach(ck.shape(1)); win.wait_for_button(); }
int main () { using namespace Graph_lib; // our graphics facilities are in Graph_lib namespace constexpr Point pt{100,100}; // to become top left corner of window Simple_window win {pt, 600, 400,"ch13.6_OpenPolyline"}; // make a simple window, {top_left, width, hight, title} // did not work: Open_polyline opl={ {100,100}, {150,200},{250,250},{300,200} }; win.attach(opl); /* Open_polyline opl_two; opl_two.add({100,100}); opl_two.add({150,200}); opl_two.add({250,250}); opl_two.add({300,200}); win.attach(opl_two); */ win.wait_for_button(); // display! }
int main() { int times; cout << "Number of times to move around the circle: "; cin >> times; double radius = 150; using namespace Graph_lib; Simple_window win {Point{100, 100}, 800, 600, "Exercise 12"}; Circle c {Point{500, 400}, int(radius)}; c.set_color(Color::white); c.set_fill_color(Color::green); win.attach(c); const double start_angle = 3.141592 * 2 / times; double angle = 0; for (int i = 0; i <= times; ++i) { double x = radius * sin(angle); double y = radius * cos(angle); Mark m {Point{int(x + 500), int(y + 400)}, 'x'}; m.set_color(Color::red); win.attach(m); win.wait_for_button(); angle += start_angle; } }
int main () { using namespace Graph_lib; // our graphics facilities are in Graph_lib namespace constexpr Point pt{100,100}; // to become top left corner of window Simple_window win {pt, 600, 400,"ch13.13_Ellipse"}; // make a simple window, {top_left, width, hight, title} Ellipse e1{Point{200,200},50,50}; Ellipse e2{Point{200,200},100,50}; Ellipse e3{Point{200,200},100,150}; win.attach(e1); win.attach(e2); win.attach(e3); Text t{Point{50,390},"Three ellipses, with a common center, but different-size axes"}; t.set_color(Color::blue); win.attach(t); /* Polygon pgn={ {100,100}, {150,200},{250,250},{300,200} }; //pgn.add({100,250}); // this point should break it win.attach(pgn); */ win.wait_for_button(); // display! }
int main() { Simple_window win {Point{100,200},600,400,"Rectangle"}; Graph_lib::Rectangle r {Point{250,185},100, 30}; Graph_lib::Text t {Point{280, 205}, "Howdy!"}; win.attach(r); win.attach(t); win.wait_for_button(); }
int main() { Simple_window win {x,800,600,"Binary Tree with Triangles"}; Graph_lib::Binary_tree_triangle btt {Point{400,50}, 5, 20, "ad", Graph_lib::Color::Color_type::red}; win.attach(btt); btt.set_label("Test","rlll"); btt.set_label("Test1",""); btt.set_label("Test2","lrr"); win.wait_for_button(); }
void show_palette(Simple_window &win) { Vector_ref<Rectangle> vr; for (int i {0}; i < 16; ++i) for (int j {0}; j < 16; ++j) { vr.push_back(new Rectangle{Point{i * 20, j * 20}, 20, 20}); vr[vr.size() - 1].set_fill_color(Color{i * 16 + j}); win.attach(vr[vr.size() - 1]); } win.wait_for_button(); }
int main() { Simple_window win {Point{100, 100}, 800, 600, "Test mark"}; Point c {200, 450}; Ellipse e {c, 150, 100}; win.attach(e); Axis x {Axis::x, c, 400, 10, "x axis"}; win.attach(x); Axis y {Axis::y, c, 300, 10, "y axis"}; win.attach(y); Mark f1 {e.focus1(), 'x'}; win.attach(f1); Mark f2 {e.focus2(), 'x'}; win.attach(f2); const double pi {3.14159265359}; int x1 = static_cast<int>(e.major()*cos(pi/6)); int y1 = -static_cast<int>(e.minor()*sin(pi/6)); Point p1 {Point{e.center().x + x1, e.center().y + y1}}; Mark p {p1, 'x'}; win.attach(p); Line l1 {e.focus1(), p1}; Line l2 {e.focus2(), p1}; win.attach(l1); win.attach(l2); win.wait_for_button(); }
int main() { using namespace Graph_lib; Simple_window win {Point{100, 100}, 800, 600, "Exercise 19"}; Star s {Point{300, 300}, 100, 20, 8, true}; s.set_color(Color::green); s.set_fill_color(Color::white); win.attach(s); win.wait_for_button(); }
int main() { using namespace Graph_lib; Point tl {100, 100}; Simple_window win {tl, 600, 400, "My window"}; win.wait_for_button();// give control to the display engine and thus // display the window on screen }
int main() { Simple_window win {Point{100, 100}, 600, 600, "Exercise 1"}; Arc a {Point{200, 200}, 50, 40, 0, 70}; a.set_color(Color::red); a.set_fill_color(Color::white); win.attach(a); win.wait_for_button(); }
int main() { Simple_window win {Point{300, 200}, 600, 400, "Exercise 2"}; Rectangle r {Point{100, 100}, 100, 30}; r.set_color(Color::black); Text t {Point{140, 110}, "Howdy!"}; t.set_color(Color::red); win.attach(r); win.attach(t); win.wait_for_button(); }
int main () { using namespace Graph_lib; // our graphics facilities are in Graph_lib namespace constexpr Point pt{100,100}; // to become top left corner of window Simple_window win {pt, 600, 400,"ch13.8_Polygon_math"}; // make a simple window, {top_left, width, hight, title} /* Closed_polyline cpl={ {100,100}, {150,200},{250,250},{300,200} }; //cpl.add(Point{100,250}); cpl.add({100,250}); win.attach(cpl); */ Polygon pgn={ {100,100}, {150,150},{250,70},{300,70} }; pgn.set_fill_color(Color::yellow); //pgn.add({100,250}); // this point should break it win.attach(pgn); /* // aandree 13 Nov 2016 // we will need to explicitly declare the initializer_list constructor for Polygons. // It is ends up being derived from Shape, and therefore mimics the Shape::Shape(initializer_list<Point> lst), // but the add(p) function for Polygon was modified // to include an extra checker, which is not present in the Shape::add(Point p) Polygon pgn={ {100,100}, {150,200},{250,250},{300,200}, {100,250} }; // the last point was supposed to break it. // But if we use the constructor from a different class, we are using Shape::add(Point p) // which does not have error checking win.attach(pgn); */ win.wait_for_button(); // display! Point p1{0,0}; Point p2{1,1}; Point p3{0,7}; Point p4{1,7}; bool parallel = false; pair<double,double> u = line_intersect(p1,p2,p3,p4,parallel); cout << "Is the line parallel? "<< parallel << endl; cout << "Intersection: x=" << u.first << "; y="<< u.second << endl; }
int main() { Simple_window win {Point{100, 100}, 800, 600, "Exercise 12"}; Binary_tree_polygon btp {5, 10, 4}; btp.set_color(Color::black); btp.set_fill_color(Color::green); btp.add_text("lrr", "hello"); btp.add_text("rrrl", "world!"); win.attach(btp); win.wait_for_button(); }
void draw_rgb_chart(Simple_window &win) { constexpr int num {16}, sq_size {20}; Vector_ref<Rectangle> v; for (int i {0}; i < num; ++i) for (int j {0}; j < num; ++j) { v.push_back(new Rectangle{Point{i * sq_size, j * sq_size}, sq_size, sq_size}); v[v.size() - 1].set_color(Color::invisible); v[v.size() - 1].set_fill_color(Color{i * num + j}); win.attach(v[v.size() - 1]); } win.wait_for_button(); }
void test_grid(Simple_window &win) { static const int x_size {win.x_max()}, y_size {win.y_max()}; constexpr int x_grid {80}, y_grid {40}; Lines grid; for (int x {x_grid}; x < x_size; x += x_grid) grid.add(Point{x, 0}, Point{x, y_size}); for (int y {y_grid}; y < y_size; y += y_grid) grid.add(Point{0, y}, Point{x_size, y}); grid.set_color(Color::yellow); grid.set_style(Line_style{Line_style::dash, 2}); win.attach(grid); win.wait_for_button(); }
int main() { Simple_window win {Point{100, 100}, 600, 400, "Simple Window"}; Rectangle r {Point{50, 50}, 100, 30}; win.attach(r); ostringstream oss; oss << "Howdy!"; Text t {Point{70,70}, oss.str()}; win.attach(t); win.wait_for_button(); }
int main() { Simple_window win {Point{100, 100}, 800, 1000, "Simple_window"}; int re_width = 30; Vector_ref<Rectangle> vr; for (int i = 0; i < 8; ++i){ vr.push_back(new Rectangle{Point{i*re_width, i*re_width}, re_width, re_width}); vr[vr.size()-1].set_color(Color::red); win.attach(vr[vr.size()-1]); } win.wait_for_button(); }
int main() { Simple_window win {Point{100,100},800,600,"Olympic symbol"}; //Circle 1 Graph_lib::Circle o1 {Point{150,150},50}; o1.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid,2)); o1.set_color(Graph_lib::Color::blue); win.attach(o1); //Circle 2 Graph_lib::Circle o2 {Point{255,150},50}; o2.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid,2)); o2.set_color(Graph_lib::Color::black); win.attach(o2); //Circle 3 Graph_lib::Circle o3 {Point{360,150},50}; o3.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid,2)); o3.set_color(Graph_lib::Color::red); win.attach(o3); //Circle 4 Graph_lib::Circle o4 {Point{200,200},50}; o4.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid,2)); o4.set_color(Graph_lib::Color::yellow); win.attach(o4); //Circle 5 Graph_lib::Circle o5 {Point{305,200},50}; o5.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid,2)); o5.set_color(Graph_lib::Color::green); win.attach(o5); win.wait_for_button(); }
int main() { using namespace Graph_lib; Controller_test ct {true, 5}; ct.show(); ct.set_level(4); Simple_window win {Point{100, 100}, 800, 600, "Exercise 16"}; Controller_derived cd {false, 3}; Circle c {Point{200, 200}, 150}; cd.set_color(c, Color::red); cd.set_fill_color(c, Color::blue); cd.use_level(c, 60); win.attach(c); win.wait_for_button(); }
void test_win() { using namespace Graph_lib; Point tl {100, 100}; Simple_window win (tl, 600, 400, "Canvas"); Polygon poly; poly.add(Point{300, 200}); poly.add(Point{350, 100}); poly.add(Point{400, 200}); poly.set_color(Color::red); win.attach(poly); win.wait_for_button(); }
int main () { using namespace Graph_lib; // our graphics facilities are in Graph_lib namespace constexpr Point pt{100,100}; // to become top left corner of window Simple_window win {pt, 600, 400,"ch13.8_Polygon"}; // make a simple window, {top_left, width, hight, title} /* Closed_polyline cpl={ {100,100}, {150,200},{250,250},{300,200} }; //cpl.add(Point{100,250}); cpl.add({100,250}); win.attach(cpl); */ Polygon pgn={ {100,100}, {150,200},{250,250},{300,200} }; //pgn.add({100,250}); // this point should break it win.attach(pgn); /* // aandree 13 Nov 2016 // we will need to explicitly declare the initializer_list constructor for Polygons. // It is ends up being derived from Shape, and therefore mimics the Shape::Shape(initializer_list<Point> lst), // but the add(p) function for Polygon was modified // to include an extra checker, which is not present in the Shape::add(Point p) Polygon pgn={ {100,100}, {150,200},{250,250},{300,200}, {100,250} }; // the last point was supposed to break it. // But if we use the constructor from a different class, we are using Shape::add(Point p) // which does not have error checking win.attach(pgn); */ win.wait_for_button(); // display! }
int main() { using namespace Graph_lib; Simple_window win {Point{100, 100}, 800, 600, "Exercise 7"}; Striped_closed_polyline scp; scp.add(Point{50, 200}); scp.add(Point{100, 110}); scp.add(Point{150, 100}); scp.add(Point{160, 300}); scp.add(Point{170, 330}); /* scp.add(Point{200, 300}); scp.add(Point{150, 320}); scp.add(Point{175, 440}); */ scp.set_color(Color::black); win.attach(scp); win.wait_for_button(); }
int main() { using namespace Graph_lib; Simple_window win {Point{100, 100}, 1000, 600, "Exercise 9 - Paddra Nsu-Yeul"}; Image yeul {Point{100, 50}, "yeul.jpg"}; ostringstream oss; oss << "Paddra Nsu-Yeul, the Seeress from Final Fantasy XIII-2"; Text des {Point{500, 200}, oss.str()}; des.set_font(Font::times_bold); des.set_color(Color::black); win.attach(yeul); win.attach(des); win.wait_for_button(); }
int main() { const int ring_size = 300; // Ring diameter const int ring_line_width = ring_size / 8; const Point ring_origin { ring_size / 2 + 50, ring_size / 2 + 50 }; Simple_window win { Point{ 100,100 }, ring_size * 3 + ring_size , ring_size * 2 + ring_size, "Olympic rings" }; vector<Graph_lib::Color> ring_colors { Color::cyan, Color::black, Color::red, Color::yellow, Color::green }; vector<Graph_lib::Circle*> rings(5); for (int i = 0; i < 5; ++i) { int offset_y = ring_origin.y + (i / 3) * ring_size / 2; int offset_x = (i / 3) * ring_size / 2; if (i < 3) rings[i] = new Graph_lib::Circle{ Point{ring_origin.x + offset_x + (ring_size + ring_line_width)*i, offset_y }, ring_size / 2 }; else rings[i] = new Graph_lib::Circle{ Point{ring_origin.x + offset_x + (ring_size + ring_line_width)*(i-3), offset_y }, ring_size / 2 }; rings[i]->set_color(ring_colors[i]); rings[i]->set_style(Line_style{Line_style::solid, ring_line_width}); win.attach(*rings[i]); } win.wait_for_button(); }
int main() { Simple_window win {Point{100,200},600,400,"Initials"}; Graph_lib::Line a1 {Point{150,250}, Point{200,100}}; Graph_lib::Line a2 {Point{200,100}, Point{250,250}}; Graph_lib::Line a3 {Point{175,175}, Point{225,175}}; a1.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 4)); a2.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 4)); a3.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 4)); a1.set_color(Graph_lib::Color::dark_blue); a2.set_color(Graph_lib::Color::dark_blue); a3.set_color(Graph_lib::Color::dark_blue); win.attach(a1); win.attach(a2); win.attach(a3); Graph_lib::Line f1 {Point{300,100}, Point{300,250}}; Graph_lib::Line f2 {Point{300,100}, Point{400,100}}; Graph_lib::Line f3 {Point{300,175}, Point{350,175}}; f1.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 4)); f2.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 4)); f3.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 4)); f1.set_color(Graph_lib::Color::dark_green); f2.set_color(Graph_lib::Color::dark_green); f3.set_color(Graph_lib::Color::dark_green); win.attach(f1); win.attach(f2); win.attach(f3); win.wait_for_button(); }