int main() try { using namespace Graph_lib; Point tl(200,50); Simple_window win(tl,1200,800,"My window"); Vector_ref<Star> stars; int min = 10; int max = 150; for (int i = 0; i<50; ++i) { stars.push_back(new Star(Point(randint(0,win.x_max()), randint(0,win.y_max())), randint(4,25), randint(min,max))); stars[stars.size()-1].set_fill_color(randint(255)); stars[stars.size()-1].set_color(randint(255)); win.attach(stars[stars.size()-1]); } win.wait_for_button(); } catch (exception& e) { cerr << "exception: " << e.what() << endl; keep_window_open(); } catch (...) { cerr << "exception\n"; keep_window_open(); }
void exercises(Simple_window &win) { Arc a1 {Point{200, 100}, 100, 50, 45, 210}; Ellipse c1 {Point{200, 100}, 100, 50}; a1.set_color(Color::green); const Point p1 {500, 10}, p2 {300, 700}; Arrow arr1 {p1, p2, 30, 11}; Arrow arr2 {p2, p1}; arr1.set_color(Color::blue); const Point p3 {400, 100}, p4 {600, 200}; Arrow arr3 {p3, p4}; Arrow arr4 {p4, p3, 30, 90}; const Point p5 {200, 500}, p6 {600, 500}; Arrow arr5 {p5, p6, 15, 17}; Arrow arr6 {p6, p5}; const Point p7 {700, 200}, p8 {700, 400}; Arrow arr7 {p7, p8}; Arrow arr8 {p8, p7, 50, 198}; arr7.set_color(Color::red); Box b1 {Point{200, 100}, 100, 50, 0, 0}; b1.set_color(Color::red); win.attach(b1); Box b2 {Point{50, 400}, 200, 150, 80, 30}; b2.set_color(Color::red); win.attach(b2); Rectangle r {Point{50, 200}, 50, 80}; win.attach(r); Point pnw {nw(r)}; Mark m1 {pnw, '0'}; win.attach(m1); Point pn {n(r)}; Mark m11 {pn, '1'}; win.attach(m11); Point pne {ne(r)}; Mark m2 {pne, '2'}; win.attach(m2); Point ps {s(r)}; Mark m21 {ps, '3'}; win.attach(m21); Point psw {sw(r)}; Mark m3 {psw, '4'}; win.attach(m3); Point pw {w(r)}; Mark m31 {pw, '5'}; win.attach(m31); Point pse {se(r)}; Mark m4 {pse, '6'}; win.attach(m4); Point pe {e(r)}; Mark m41 {pe, '7'}; win.attach(m41); Point pc {center(r)}; Mark m5 {pc, '9'}; win.attach(m5); constexpr int x0 {70}, y0 {300}, rad {50}; Vector_ref<Regular_polygon> v; for (int i {0}; i < 8; ++i) { v.push_back(new Regular_polygon{Point{x0 + i * (rad + rad / 2), y0 + static_cast<int>(0.5 * rad * pow(-1, i % 2))}, 6, rad}); v[v.size() - 1].set_color(Color::blue); v[v.size() - 1].set_fill_color(Color::blue); win.attach(v[v.size() - 1]); } Regular_polygon rp1 {Point{150, 600}, 6, 50}; rp1.set_color(Color::cyan); rp1.set_fill_color(Color::magenta); win.attach(rp1); Regular_polygon rp2 {Point{450, 600}, 9, 70}; rp2.set_color(Color::yellow); rp2.set_fill_color(Color::blue); win.attach(rp2); win.attach(c1); win.attach(a1); win.attach(arr1); win.attach(arr2); win.attach(arr3); win.attach(arr4); win.attach(arr5); win.attach(arr6); win.attach(arr7); win.attach(arr8); 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(); }
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(); }
int main(){ Simple_window win10(Point(100, 100), 600, 400, "16*16 color matrix"); Vector_ref<Graph_lib::Rectangle> vr; for(int i = 0; i < 16; ++i) for(int j = 0; j < 16; ++j){ vr.push_back(new Graph_lib::Rectangle(Point(i * 20, j * 20), 20, 20)); vr[vr.size() - 1].set_fill_color(Color(i * 16 + j)); win10.attach(vr[vr.size() - 1]); } win10.wait_for_button(); // 表示! }
int main() { constexpr int width = 800; constexpr int height = 600; Simple_window win{ Point{ 100, 100 }, width, height, "Chapter 13. Exercise 16-17. Mosaic" }; constexpr double radius = 10; Vector_ref<Regular_Polygon> mosaic; Point start = { 120, 120}; Point end = {width - 150, height - 150}; int x = start.x; int y = start.y; int row_num = 1; while (y <= end.y + radius * 0.5 * sqrt(3)) { while (x <= end.x + radius) { mosaic.push_back(new Regular_Polygon(Point{ x, y }, 6, radius)); x += 3 * radius; } if (row_num % 2) x = start.x + 1.5 * radius; else x = start.x; y += radius * 0.5 * sqrt(3); ++row_num; } for (int i = 0; i < mosaic.size(); ++i) { mosaic[i].set_fill_color(randint(255)); win.attach(mosaic[i]); } Graph_lib::Rectangle rect{start, end}; rect.set_style( Line_style{ Line_style::dot, 4} ); rect.set_color( Color::dark_magenta ); win.attach(rect); std::ostringstream ss; ss << "Tiles = " << mosaic.size(); Text t{ Point {10, 20}, ss.str()}; t.set_color(Color::black); win.attach(t); win.put_on_top(t); win.wait_for_button(); }
int main() try { https://www.google.co.uk/search?q=stack+programming+definition&ie=utf-8&oe=utf-8&gws_rd=cr&ei=eoZ6V5HFJ8uQgAbR_qrIAw // ---------------------------------------------------------- // EXERCISE 8 // ---------------------------------------------------------- Point tl{100,100}; Simple_window win(tl,1000,500,"Olympic"); //Let's have rings of 50 radius, with 6 pixels inbetween them //and a thickness of 10 pixels // Let's use a loop with a conditional property // to put the circles into a vector ref Vector_ref<Circle> olympic; for (int i = 200; i<450; i+=58) if(olympic.size()%2 == 0) olympic.push_back(new Circle(Point{i,200},50)); else olympic.push_back(new Circle(Point{i,260},50)); //Manually code in the colors as the fltk color map is //not intuitive olympic[0].set_color(4); olympic[1].set_color(3); olympic[2].set_color(0); olympic[3].set_color(2); olympic[4].set_color(1); //Use loop to set line thickness and attach to window for (int i = 0; i < olympic.size(); ++i) { olympic[i].set_style(Line_style(Line_style::solid,10)); win.attach(olympic[i]); } win.wait_for_button(); } catch(std::exception& e) { std::cout << e.what() << std::endl; return 1; }
int main() { Simple_window win {Point{100, 100}, 800, 1000, "Chapter 13 Drill"}; Lines ls; for (int x = 100; x <= 800; x += 100) ls.add(Point{x, 0}, Point{x, 800}); for (int y = 100; y <= 800; y += 100) ls.add(Point{0, y}, Point{800, y}); string pic = "Instruments 1.jpg"; string another_pic = "Instruments 2.jpg"; Image im1 {Point{0, 0}, pic}; im1.set_mask(Point{0, 0}, 200, 200); win.attach(im1); Image im2 {Point{200, 300}, pic}; im2.set_mask(Point{0, 0}, 200, 200); win.attach(im2); Image im3 {Point{400, 600}, pic}; im3.set_mask(Point{0, 0}, 200, 200); win.attach(im3); Vector_ref<Rectangle> rectangles; for (int i = 0; i < 8; ++i) { rectangles.push_back(new Rectangle{Point{100 * i, 100 * i}, 100, 100}); rectangles[i].set_fill_color(Color::red); win.attach(rectangles[i]); } ls.set_color(Color::white); win.attach(ls); int row = 0; int col = 0; for (int i = 0; i < 100; ++i) { col = i % 8; if (i / 8 > row) ++row; Image im4 {Point{100 * row, 100 * col}, another_pic}; im4.set_mask(Point{0, 0}, 100, 100); win.attach(im4); 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 () try { srand (time(NULL)); Simple_window win(Point(10,10),800,600,"Chapter 13:"); int length = 150, count = 14, angle, height = sqrt(pow(length,2) - pow(length/2,2)); Vector_ref<Triangle> VT; for (unsigned int h = 0; h < count*height; h += height) { for (unsigned int j = 0; j < count; j += 1) { VT.push_back(new Triangle(Point(j*length,h),length,180)); int k = randint(14); VT[VT.size()-1].set_fill_color(Color(k)); VT[VT.size()-1].set_color(Color(k)); win.attach(VT[VT.size()-1]); VT.push_back(new Triangle(Point(j*length - length/2,h),length,0)); k = randint(14); VT[VT.size()-1].set_fill_color(Color(k)); VT[VT.size()-1].set_color(Color(k)); win.attach(VT[VT.size()-1]); } } win.wait_for_button(); } catch(exception& e) { // some error reporting return 1; } catch(...) { // some more error reporting return 2; }
void drill(Simple_window &win) { static const int x_size {win.x_max()}, y_size {win.y_max()}; constexpr int num_x {8}, num_y {8}; const int x_grid {x_size / num_x}, y_grid {y_size / num_y}; 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}); Vector_ref<Rectangle> vr; for (int i {0}; i < num_x; ++i) { vr.push_back(new Rectangle{Point{x_grid * i, y_grid * i}, x_grid, y_grid}); vr[vr.size() - 1].set_fill_color(Color::red); win.attach(vr[vr.size() - 1]); } grid.set_color(Color::yellow); grid.set_style(Line_style{Line_style::dash, 2}); win.attach(grid); Image img1 {Point{x_grid * 2, 0}, "../snow_cpp.gif", Suffix::gif}; img1.set_mask(Point{0, 0}, 200, 200); Image img2 {Point{0, y_grid * 4}, "../snow_cpp.gif", Suffix::gif}; img2.set_mask(Point{0, 0}, 200, 200); Image img3 {Point{x_grid * 3, y_grid * 6}, "../snow_cpp.gif", Suffix::gif}; img3.set_mask(Point{0, 0}, 200, 200); win.attach(img1); win.attach(img2); win.attach(img3); for (int i {0}; i < num_x; ++i) { for (int j {0}; j < num_y; ++j) { Image img4 {Point{x_grid * i, y_grid * j}, "img.jpg", Suffix::jpg}; img4.set_mask(Point{0, 0}, 100, 100); win.attach(img4); win.wait_for_button(); } } win.wait_for_button(); }
int main(){ Simple_window win(Point(100, 100), 600, 400, "RGB color chart"); Vector_ref<Graph_lib::Rectangle> vr; int x = 0, y = 0; // 座標 const int a = 15; // 正方形の一辺 const int step = 51; // Webセーフカラー( = 0x33 ) for(int r = 0; r <= 255; r += step, y += a, x = 0){ for(int g = 0; g <= 255; g += step){ for(int b = 0; b <= 255; b += step, x += a){ vr.push_back(new Graph_lib::Rectangle(Point(x, y), a, a)); vr[vr.size() - 1].set_fill_color(Color(r * pow(2, 24) + g * pow(2, 16) + b * pow(2, 8))); win.attach(vr[vr.size() - 1]); } } } win.wait_for_button(); }
int main() try { Point tl(300,50); Simple_window win(tl,1000,800,"My window"); win.wait_for_button(); win.set_label("My window"); // add grid on leftmost 800-by-800 part Lines grid; int x_size = 800; int y_size = 800; for (int i = 100; i<=x_size; i+=100) { grid.add(Point(i,0),Point(i,y_size)); grid.add(Point(0,i),Point(x_size,i)); } win.attach(grid); //win.resize(1000,800); win.wait_for_button(); // make squares on the diagonal red Vector_ref<Graph_lib::Rectangle> vr; for (int i = 0; i<8; ++i) { vr.push_back(new Graph_lib::Rectangle(Point(i*100,i*100),101,101)); vr[vr.size()-1].set_fill_color(Color::red); win.attach(vr[vr.size()-1]); } //win.resize(1000,800); win.wait_for_button(); // place 3 copies of a 200-by-200 image, don't cover the red squares Image plane1(Point(200,0),"pics_and_txt/image.jpg"); plane1.set_mask(Point(200,0),200,200); win.attach(plane1); Image plane2(Point(500,200),"pics_and_txt/image.jpg"); plane2.set_mask(Point(200,0),200,200); win.attach(plane2); Image plane3(Point(100,500),"pics_and_txt/image.jpg"); plane3.set_mask(Point(200,0),200,200); win.attach(plane3); //win.resize(1000,800); win.wait_for_button(); // add a 100-by-100 image, have it move around Image snow(Point(0,0),"pics_and_txt/snow_cpp.gif"); snow.set_mask(Point(110,70),100,100); win.attach(snow); //win.resize(1000,800); win.wait_for_button(); int x = 0; int y = 0; int dx = 0; int dy = 0; while (true) { x = randint(8); y = randint(8); dx = 100*x - snow.point(0).x; dy = 100*y - snow.point(0).y; snow.move(dx,dy); //win.resize(1000,800); win.wait_for_button(); } } catch (exception& e) { cerr << "exception: " << e.what() << endl; keep_window_open(); } catch (...) { cerr << "exception\n"; keep_window_open(); }
void hexagon_push(){ kind.hide(); shapes.push_back(new Regular_polygon(Point(inbox_x.get_int(), inbox_y.get_int()), radius, 6)); attach(shapes[shapes.size() - 1]); menu.show(); }
void circle_push(){ kind.hide(); shapes.push_back(new Circle(Point(inbox_x.get_int(), inbox_y.get_int()), radius)); attach(shapes[shapes.size()-1]); menu.show(); }
int main(){ Simple_window win(Point(100, 100), 600, 400, "ClassDiagram"); Vector_ref<Box> boxes; Vector_ref<Arrow> arrows; boxes.push_back(new Box(Point(50, 50), 100, 30, 10, "Window")); boxes.push_back(new Box(Point(200, 50), 100, 30, 10, "Line style")); boxes.push_back(new Box(Point(350, 50), 70, 30, 10, "Color")); boxes.push_back(new Box(Point(25, 150), 150, 30, 10, "Simple window")); boxes.push_back(new Box(Point(400, 150), 70, 30, 10, "Point")); boxes.push_back(new Box(Point(240, 120), 70, 30, 10, "Shape")); boxes.push_back(new Box(Point(15, 300), 50, 30, 10, "Line")); boxes.push_back(new Box(Point(70, 300), 70, 30, 10, "Lines")); boxes.push_back(new Box(Point(145, 300), 100, 30, 10, "Polygon")); boxes.push_back(new Box(Point(250, 300), 50, 30, 10, "Axis")); boxes.push_back(new Box(Point(305, 300), 100, 30, 10, "Rectangle")); boxes.push_back(new Box(Point(410, 300), 60, 30, 10, "Text")); boxes.push_back(new Box(Point(475, 300), 70, 30, 10, "Image")); Arrow a(n(boxes[3]), s(boxes[0]), 10); a.set_style(Line_style(Line_style::solid, 3)); win.attach(a); for(int i = 6; i <= 12; ++i){ arrows.push_back(new Arrow(n(boxes[i]), Point(s(boxes[5]).x - 30 + (i - 6) * 10, s(boxes[5]).y), 10)); arrows[arrows.size() - 1].set_style(Line_style(Line_style::solid, 3)); win.attach(arrows[arrows.size() - 1]); } for(int i = 0; i < boxes.size(); ++i){ boxes[i].set_style(Line_style(Line_style::solid, 3)); boxes[i].set_fill_color(Color(220)); // 青 win.attach(boxes[i]); } win.wait_for_button(); }