Module: Salamander::Drawing::Shapes
- Includes:
- Line
- Defined in:
- lib/salamander/drawing/shapes.rb
Instance Method Summary collapse
-
#polygon(sides, length) ⇒ Object
Draws a regular polygon with ‘sides’ sides, each of length ‘length’.
-
#star(points, length) ⇒ Object
Draws a star-like shape with number ‘points’ of points.
Methods included from Line
Instance Method Details
#polygon(sides, length) ⇒ Object
Draws a regular polygon with ‘sides’ sides, each of length ‘length’
17 18 19 20 21 22 |
# File 'lib/salamander/drawing/shapes.rb', line 17 def polygon (sides, length) sides.times do line length turn (360.0/sides).degrees end end |
#star(points, length) ⇒ Object
Draws a star-like shape with number ‘points’ of points.
‘points’ must be odd.
8 9 10 11 12 13 14 |
# File 'lib/salamander/drawing/shapes.rb', line 8 def star (points, length) raise "The star must have an odd number of points" if points % 2 == 0 points.times do line length turn (720.0/points).degrees end end |