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
|
#include <Simple_window.h>
struct Hexagon : Shape {
Hexagon(Point p, int d): d(d)
{ add(Point(p)); }
void draw_lines() const
{
fl_line(point(0).x-d,point(0).y, point(0).x-d/2,point(0).y-(d-d/20*3),
point(0).x+d/2,point(0).y-(d-d/20*3));
fl_line(point(0).x+d/2,point(0).y-(d-d/20*3), point(0).x+d,point(0).y,
point(0).x+d/2,point(0).y+(d-d/20*3));
fl_line(point(0).x+d/2,point(0).y+(d-d/20*3), point(0).x-d/2,point(0).y+(d-d/20*3),
point(0).x-d, point(0).y);
}
private:
int d;
};
int main() {
using namespace Graph_lib;
Simple_window win(Point(100,100), 600,400, "Hexagon");
Graph_lib::Rectangle r(Point (50,50), 400,200);
Point p(100,100);
int d = 50;
Hexagon h(p,d);
win.attach(h);
win.wait_for_button();
}
|