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! }
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}, 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(){ double a, b, m, n; // スーパー楕円のパラメータ int N; // 選択する点の数 cin >> a >> b >> m >> n >> N; Simple_window win(Point(100, 100), 640, 480, "q12_12"); const int sx = win.x_max() / 2; // 原点 const int sy = win.y_max() / 2; const int scale = 100; // スケール int x, y; // 座標 double angle = 0; // 角度(θ) Mark m0(Point(sx, sy), 'X'); // 中心点 Lines lines; vector<Point> vp; m = 1 / (m / 2); // 2乗になるようにし、逆数をとる n = 1 / (n / 2); for(int i = 0; i < N; ++i){ int rs = sin(angle) < 0 ? -1 : 1; // sinの符号をとる int rc = cos(angle) < 0 ? -1 : 1; // cosの符号をとる x = sx + a * scale * pow(abs(sin(angle)), m) * rs; // 絶対値を累乗し、後で符号をかける y = sy - b * scale * pow(abs(cos(angle)), n) * rc; vp.push_back(Point(x, y)); angle += 2 * M_PI / N; // N角形の内角 } for(int i = 0; i < vp.size(); ++i){ for(int j = i + 1; j < vp.size(); ++j){ lines.add(vp[i], vp[j]); } } lines.set_style(Line_style(Line_style::solid, 2)); lines.set_color(Color::blue); win.attach(lines); win.attach(m0); win.wait_for_button(); }
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(); }