class Sketch::Star
Public Instance Methods
angle_between_points()
click to toggle source
# File lib/sketch/star.rb, line 20 def angle_between_points 360 / number_of_points end
degrees_to_radians( degrees )
click to toggle source
# File lib/sketch/star.rb, line 16 def degrees_to_radians( degrees ) degrees * Math::PI / 180 end
draw(canvas)
click to toggle source
# File lib/sketch/star.rb, line 43 def draw(canvas) if x && y && radius atts = {} atts['points'] = points_in_drawing_order.each{|point| point.join(',')}.join(' ') atts['fill'] = attributes[:fill] if attributes.has_key?(:fill) atts['stroke'] = attributes[:stroke] if attributes.has_key?(:stroke) atts['stroke-width'] = attributes[:stroke_width] if attributes.has_key?(:stroke_width) canvas.polygon( atts ) end end
drawing_order_indexes()
click to toggle source
# File lib/sketch/star.rb, line 24 def drawing_order_indexes self.number_of_points.times.map do |n| (n*2) % self.number_of_points end end
points()
click to toggle source
# File lib/sketch/star.rb, line 36 def points @points ||= list = number_of_points.times.map do |point_number| current_angle = orientation + ( angle_between_points * point_number ) [ x + (radius * Math.sin( degrees_to_radians( current_angle ))), y - (radius * Math.cos( degrees_to_radians( current_angle ))) ] end end
points_in_drawing_order()
click to toggle source
# File lib/sketch/star.rb, line 30 def points_in_drawing_order drawing_order_indexes.map do |index| points[index] end end