Class: Sketch::Triangle

Inherits:
Element
  • Object
show all
Defined in:
lib/sketch/triangle.rb

Instance Method Summary collapse

Methods inherited from Element

central_point, #svg_node

Methods included from Base

#svg_attributes

Instance Method Details

#draw(canvas) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sketch/triangle.rb', line 10

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