add svg_element Triangle

Johnathon E. Wright committed Nov 10, 2011
commit b612f817915e5e2fabef370bbcbae435d2034f66
Showing 1 changed file with 27 additions and 0 deletions
sketch/triangle.rb b/lib/sketch/triangle.rb +27 -0
@@ @@ -0,0 +1,27 @@
+ class Sketch::Triangle < Sketch::Element
+
+ has_value :point
+ has_value :height
+ has_value :direction
+ has_value :stroke
+ has_value :stroke_width
+ has_value :fill
+
+ def draw(canvas)
+ case direction
+ when :up
+ point1 = "M#{point.join(',')}"
+ point2 = "l-#{0.5*height},#{height*0.5}"
+ point3 = "l#{height},0"
+ point4 = "l-#{height*0.5},-#{height*0.5}"
+ when :down
+ point1 = "M#{point.join(',')}"
+ point2 = "l-#{0.5*height},-#{height*0.5}"
+ point3 = "l#{height},0"
+ point4 = "l-#{height*0.5},#{height*0.5}"
+ end
+
+ Sketch::Path.new(:stroke_width => self.stroke_width, :fill => self.fill, :stroke => self.stroke, :commands => [point1, point2, point3, point4]).draw(canvas)
+ end
+ end
+