add basic polygon.

Johnathon E. Wright committed Nov 10, 2011
commit c8931a92d6a8299fbf316c38b45efb923e98c8cf
Showing 3 changed files with 38 additions and 0 deletions
sketch.rb b/lib/sketch.rb +1 -0
@@ @@ -43,6 +43,7 @@ require 'sketch/element'
require 'sketch/canvas'
require 'sketch/circle'
+ require 'sketch/polygon'
require 'sketch/ellipse'
require 'sketch/rect'
require 'sketch/rectangle'
sketch/polygon.rb b/lib/sketch/polygon.rb +16 -0
@@ @@ -0,0 +1,16 @@
+ class Sketch::Polygon < Sketch::Element
+
+ has_collection :points
+ has_value :fill
+ has_value :stroke
+ has_value :stroke_width
+ has_value :fill_rule
+
+ def svg_attributes
+ out = super
+ out['points'] = attributes[:points].map{|point| point.join(',')}.join(' ')
+ out
+ end
+
+ end
+
sketch/star.rb b/lib/sketch/star.rb +21 -0
@@ @@ -0,0 +1,21 @@
+ class Sketch::Star < Sketch::Element
+
+ has_value :x
+ has_value :y
+ has_value :radius
+ has_value :orientation, :default => 0
+
+ central_point :x, :y
+
+ def draw(canvas)
+ top = [x, y - radius]
+ mid_right = [x + radius, y-(.3*radius)]
+ lower_right = [x + (0.6 * radius), y + radius]
+ lower_left = [x - (0.6 * radius), y + radius]
+ mid_left = [x - radius, y-(0.3*radius)]
+ points = [ top, lower_right, mid_left, mid_right, lower_left, top ]
+ points.each{|point| point.join(',')}
+ points = points.join(' ')
+ canvas.polygon( :points => points)
+ end
+ end