Esempio n. 1
0
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!

}
Esempio n. 2
0
int main(){
	Simple_window win2(Point(100, 100), 600, 400, "lines: +");

	Lines x;

	x.add(Point(100, 100), Point(200, 100));	// 1つ目のライン: 水平
	x.add(Point(150, 50), Point(150, 150));		// 2つ目のライン: 垂直

	win2.attach(x);
	win2.wait_for_button();		// 表示!
}
Esempio n. 3
0
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();
    }
}
Esempio n. 5
0
int main(){
	Simple_window win3(Point(100, 100), 600, 400, "grid");

	int x_size = win3.x_max();	// ウインドウのサイズを取得する
	int y_size = win3.y_max();
	int x_grid = 80;
	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));
	for(int y = y_grid; y < y_size; y += y_grid)
		grid.add(Point(0, y), Point(x_size, y));

	win3.attach(grid);
	win3.wait_for_button();		// 表示!
}
Esempio n. 6
0
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();
}
Esempio n. 7
0
int main()
{
	Simple_window win(Point{ 10,10 }, 800, 1000, "Chapter 13 task");

	Lines grid;
	for (int i = 0; i <= 800; i += 100)
	{
		grid.add(Point(0, i), Point(800, i));
		grid.add(Point(i, 0), Point(i, 800));
	}
	win.attach(grid);

	Vector_ref<Graph_lib::Rectangle> diag_rects;
	for (int i = 0; i < 800; i+=100)
	{
		diag_rects.push_back(new Graph_lib::Rectangle{ Point(i,i),101, 101 });
		diag_rects[diag_rects.size() - 1].set_fill_color(Color::red);
		win.attach(diag_rects[diag_rects.size() - 1]);
	};
	Image im1{ Point{200,0}, "f35.jpg" };
	win.attach(im1);
	Image im2{ Point{ 500,200 }, "f35.jpg" };
	win.attach(im2);
	Image im3{ Point{ 0,300 }, "f35.jpg" };
	win.attach(im3);

	Image im{ Point{0,0}, "f35.jpg" };
	im.set_mask(Point{50,50}, 100, 100);
	win.attach(im);
	win.put_on_top(im);

	while (true)
	{
		win.wait_for_button();
		int dx = randint(-1, 1) * 100;
		if ( (im.point(0).x + dx) < 0 || (im.point(0).x + dx) >= 800 )
			dx = -dx;
		int dy = randint(-1, 1) * 100;
		if ((im.point(0).y + dy) < 0 || (im.point(0).y + dy) >= 800)
			dy = -dy;

		im.move(dx, dy);
	}
}
Esempio n. 8
0
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();
}
Esempio n. 9
0
int main()
{
	//Error Check
	//Runs program until it's finished or error is found
	//Goes through catch to find source of error
	//If error is found tells user of error before quitting
	try {
		
		//Declaring top left corner:
		Point top_left {100,100};
		
		Simple_window canvas {top_left, 800, 1000, "Canvas"};
		
		
		//Grid
		//8x8 grid on top 800x800 square
		//	get size of window and sizes of squares
		//	use for loop to create grid
		//	attaches grid to window
		int x_max = 800;
		int y_max = 800;
		int x_size = 100;
		int y_size = 100;
		
		Lines grid;
		for (int x= x_size; x<=x_max; x = x+x_size)
		{
			grid.add(Point{x,0},Point{x,y_max});
		}
		for (int y=y_size; y<=y_max; y = y+y_size)
		{
			grid.add(Point{0,y},Point{x_max,y});
		}
		canvas.attach(grid);
		
		//Red squares
		//	creates 8 squares, places them, and fills them with red
		//	attaches squares to window
		Rectangle s1 {Point{1,1}, 100, 100};
		s1.set_fill_color(Color::red);
		
		Rectangle s2 {Point{100,100}, 100, 100};
		s2.set_fill_color(Color::red);
		
		Rectangle s3 {Point{200,200}, 100, 100};
		s3.set_fill_color(Color::red);
		
		Rectangle s4 {Point{300,300}, 100, 100};
		s4.set_fill_color(Color::red);
		
		Rectangle s5 {Point{400,400}, 100, 100};
		s5.set_fill_color(Color::red);
		
		Rectangle s6 {Point{500,500}, 100, 100};
		s6.set_fill_color(Color::red);
		
		Rectangle s7 {Point{600,600}, 100, 100};
		s7.set_fill_color(Color::red);
		
		Rectangle s8 {Point{700,700}, 100, 100};
		s8.set_fill_color(Color::red);
		
		canvas.attach(s1);
		canvas.attach(s2);
		canvas.attach(s3);
		canvas.attach(s4);
		canvas.attach(s5);
		canvas.attach(s6);
		canvas.attach(s7);
		canvas.attach(s8);
				
		//Images
		//	adds 200x200 image and sets location
		//	attaches warios to window
		Image wario1 {Point{300,1}, "wario.jpeg"};
		Image wario2 {Point{400,600}, "wario.jpeg"};
		Image wario3 {Point{1,200}, "wario.jpeg"};
		
		canvas.attach(wario1);
		canvas.attach(wario2);
		canvas.attach(wario3);
		
		//Moving Image
		// 	opens image and attaches to canvas
		//	moves image for a certain number of squares, using the next button as a waiting option
		Image wa {Point{100,1}, "wawawa.jpeg"};
		canvas.attach(wa);
		
		for (int i = 100; i <= 600; i= i+ 100)
		{
			wa.move(100,100);
			canvas.wait_for_button();
			if (i == 600)
			{
					break;
			}
		}
		
	}
	
	
	
	catch (exception& e)
	{
		cerr << "error: " << e.what() << endl;
		return 1;
	}
	catch(...)
	{
		cerr << "Oops: unknown exception!" << endl;
		return 2;
	}
	
	return 0;
}
Esempio n. 10
0
int main()
{
	using namespace Graph_lib; // our graphics facilities are in Graph_lib

try
{
	Point tl(50,50); // top left corner of window
	Simple_window win(tl,500,500,"ch13ex02"); // make a simple window

	// get the size of the window
	// create a grid
	Lines grid;
	const int g_size = 4; // grid size
	const int g_space = 50; // grid spacing
	// horizonal lines
	for (int x=g_space; x<=g_size*g_space; x+=g_space)
		grid.add(Point(x,0),Point(x,g_size*g_space));
	// vertical lines
	for (int y=g_space; y<=g_size*g_space; y+=g_space)
		grid.add(Point(0,y),Point(g_size*g_space,y));
	win.attach(grid);

	// arc definition based on Circle
	Arc_c arc_c_1(Point(100,200),50,0,90);
	arc_c_1.set_color(Color::red);
	win.attach(arc_c_1);

	Arc_c arc_c_2(Point(100,200),50,90,180);
	arc_c_2.set_color(Color::blue);
	win.attach(arc_c_2);

	Arc_c arc_c_3(Point(100,200),50,180,270);
	arc_c_3.set_color(Color::yellow);
	win.attach(arc_c_3);

	Arc_c arc_c_4(Point(100,200),50,270,360);
	arc_c_4.set_color(Color::green);
	win.attach(arc_c_4);

	Text t_1(Point(5,130),"arcs based on Circle.");
	t_1.set_font(Font::times_bold);
	t_1.set_font_size(16);
	win.attach(t_1);

	// arc definition based on Ellipse
	Arc arc_1(Point(300,200),75,50,0,90);
	arc_1.set_color(Color::red);
	win.attach(arc_1);

	Arc arc_2(Point(300,200),75,50,90,180);
	arc_2.set_color(Color::blue);
	win.attach(arc_2);

	Arc arc_3(Point(300,200),75,50,180,270);
	arc_3.set_color(Color::yellow);
	win.attach(arc_3);

	Arc arc_4(Point(300,200),75,50,270,360);
	arc_4.set_color(Color::green);
	win.attach(arc_4);

	Text t_2(Point(205,130),"arcs based on Ellipse.");
	t_2.set_font(Font::times_bold);
	t_2.set_font_size(16);
	win.attach(t_2);

	Point bp(200,200);

	Box b(Point(200,200),100,250);
	win.attach(b);
	//b.move(100,100);
	Box b1(Point(200,200),125,250);
	win.attach(b1);
	Box b2(Point(200,200),150,250);
	win.attach(b2);
	Box b3(Point(200,200),175,250);
	win.attach(b3);
	Box b4(Point(200,200),200,250);
	win.attach(b4);
	Box b5(Point(200,200),225,250);
	win.attach(b5);
	Box b6(Point(200,200),250,250);
	win.attach(b6);
	Box b7(Point(200,200),275,250);
	win.attach(b7);
	Box b8(Point(200,200),300,250);
	win.attach(b8);
	Box b9(bp, 325,250);
	win.attach(b9);
	Box b10(bp, 350,250);
	win.attach(b10);
	Box b11(bp, 375,250);
	win.attach(b11);
	Box b12(bp, 400,250);
	win.attach(b12);

	win.wait_for_button(); // display

	cout << "We're finished now!\n";

}
catch(exception& e) {
	cerr <<"exception: " << e.what() << endl;
	return 1;
}
catch(...) {
	cerr << "Some exception\n";
	return 2;
}
} // main()
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();
}