Untitled


SUBMITTED BY: Guest

DATE: May 17, 2013, 9:20 a.m.

FORMAT: Text only

SIZE: 1.9 kB

HITS: 2919

  1. //Part 2. Chapter 13. Exercise 8
  2. //------------------------------------------------------------------------------
  3. struct Hexagon : Shape {
  4. Hexagon(Point Center, double radius)
  5. : rCircumCircle(radius)
  6. {
  7. add(Center);
  8. }
  9. void draw_lines() const;
  10. private:
  11. double rCircumCircle;
  12. };
  13. //------------------------------------------------------------------------------
  14. //------------------------------------------------------------------------------
  15. void Hexagon::draw_lines() const {
  16. if (fill_color().visibility()) {
  17. fl_color(fill_color().as_int());
  18. fl_begin_complex_polygon();
  19. for (int i = 0; i < 6; i++)
  20. fl_vertex(point(0).x + rCircumCircle*cos(2*M_PI*i/6),
  21. point(0).y + rCircumCircle*sin(2*M_PI*i/6));
  22. fl_end_complex_polygon();
  23. fl_color(color().as_int()); // reset color
  24. }
  25. if (color().visibility()) {
  26. fl_color(color().as_int());
  27. for (int i = 0; i < 6; i++) {
  28. int p;
  29. if (i < 5) p = i + 1;
  30. else p = 0;
  31. fl_line(point(0).x + rCircumCircle*cos(2*M_PI*i/6),
  32. point(0).y + rCircumCircle*sin(2*M_PI*i/6),
  33. point(0).x + rCircumCircle*cos(2*M_PI*p/6),
  34. point(0).y + rCircumCircle*sin(2*M_PI*p/6));
  35. }
  36. }
  37. }
  38. //------------------------------------------------------------------------------

comments powered by Disqus