//Part 2. Chapter 13. Exercise 8
//------------------------------------------------------------------------------
struct Hexagon : Shape {
Hexagon(Point Center, double radius)
: rCircumCircle(radius)
{
add(Center);
}
void draw_lines() const;
private:
double rCircumCircle;
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void Hexagon::draw_lines() const {
if (fill_color().visibility()) {
fl_color(fill_color().as_int());
fl_begin_complex_polygon();
for (int i = 0; i < 6; i++)
fl_vertex(point(0).x + rCircumCircle*cos(2*M_PI*i/6),
point(0).y + rCircumCircle*sin(2*M_PI*i/6));
fl_end_complex_polygon();
fl_color(color().as_int()); // reset color
}
if (color().visibility()) {
fl_color(color().as_int());
for (int i = 0; i < 6; i++) {
int p;
if (i < 5) p = i + 1;
else p = 0;
fl_line(point(0).x + rCircumCircle*cos(2*M_PI*i/6),
point(0).y + rCircumCircle*sin(2*M_PI*i/6),
point(0).x + rCircumCircle*cos(2*M_PI*p/6),
point(0).y + rCircumCircle*sin(2*M_PI*p/6));
}
}
}
//------------------------------------------------------------------------------