-
Notifications
You must be signed in to change notification settings - Fork 4
/
shape_primitives.cpp
76 lines (61 loc) · 2.47 KB
/
shape_primitives.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Graph.h"
#include "Simple_window.h"
using namespace Graph_lib;
int main() {
Point tl(100, 100); // top left corner of our window
Simple_window win(tl, 600, 400, "Canvas");
Axis xa(Axis::x, Point(20, 300), 280, 10, "x axis"); // make an Axis
win.attach(xa); // attach xa to the window, win
Axis ya(Axis::y, Point(20, 300), 280, 10, "y axis");
ya.set_color(Color::cyan); // choose a color
ya.label.set_color(Color::dark_red); // choose a color for the text
win.attach(ya);
Function sine(sin, 0, 100, Point(20, 150), 1000, 50, 50); // sine curve
sine.set_color(Color::blue);
win.attach(sine);
Graph_lib::Polygon poly;
poly.add(Point(300, 200)); // three points make a triangle
poly.add(Point(350, 100));
poly.add(Point(400, 200));
poly.set_color(Color::red);
poly.set_style(Line_style(Line_style::dash, 4));
win.attach(poly);
Graph_lib::Rectangle r(Point(200, 200), 100, 50); // top left corner, width, height
r.set_fill_color(Color::yellow); // color the inside of the rectangle
win.attach(r);
Closed_polyline poly_rect;
poly_rect.add(Point(100, 50));
poly_rect.add(Point(200, 50));
poly_rect.add(Point(200, 100));
poly_rect.add(Point(100, 100));
poly_rect.add(Point(50, 75));
poly_rect.set_style(Line_style(Line_style::dash, 2));
poly_rect.set_fill_color(Color::green);
win.attach(poly_rect);
Text t(Point(150, 150), "Hello, graphical world!");
t.set_font(Graph_lib::Font::times_bold);
t.set_font_size(20);
win.attach(t);
// 必须在ch12目录下运行程序,否则会找不到文件
Image ii(Point(100, 50), "img/image.jpg"); // 400*212-pixel jpg
ii.move(100, 200);
win.attach(ii);
Circle c(Point(100, 200), 50);
win.attach(c);
Graph_lib::Ellipse e(Point(100, 200), 75, 25);
e.set_color(Color::dark_red);
win.attach(e);
Mark m(Point(100, 200), 'x');
win.attach(m);
std::ostringstream oss;
oss << "screen size: " << x_max() << '*' << y_max()
<< "; window size: " << win.x_max() << '*' << win.y_max();
Text sizes(Point(100, 20), oss.str());
win.attach(sizes);
Image cal(Point(225, 225), "img/snow_cpp.gif"); // 320*240-pixel gif
cal.set_mask(Point(40, 40), 200, 150); // display center part of image
win.attach(cal);
win.set_label("Canvas #12"); // relabel the window
win.wait_for_button(); // display!
return 0;
}