Class: Oekaki::Star

Inherits:
Tool
  • Object
show all
Defined in:
lib/oekaki.rb

Defined Under Namespace

Modules: Add

Instance Attribute Summary

Attributes inherited from Tool

#height, #width, #window

Instance Method Summary collapse

Methods inherited from Tool

#arc, #circle, #clear, #color, #get_pic, #get_window_size, #line, #lines, #load_pic, #point, #polygon, #rectangle, #save_pic, #show_pic, #star, #text, #timer_stop

Constructor Details

#initialize(fill, x1, y1, x2, y2, color) ⇒ Star

Returns a new instance of Star.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/oekaki.rb', line 159

def initialize(fill, x1, y1, x2, y2, color)
  @fill = fill
  @o = []; @a = []; @b = []
  @o[0], @o[1] = x1, y1
  @a[0] = Vector[x2 - x1, y1 - y2]
  θ = PI / 5
  rt1 = Matrix[[cos(θ), -sin(θ)], [sin(θ), cos(θ)]]
  rt2 = rt1 * rt1
  1.upto(4) {|i| @a[i] = rt2 * @a[i - 1]}
  t = cos(2 * θ) / cos(θ)
  @b[0] = rt1 * @a[0] * t
  1.upto(4) {|i| @b[i] = rt2 * @b[i - 1]}
  super()
  @color = color
end

Instance Method Details

#drawObject



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/oekaki.rb', line 181

def draw
  if @fill
    5.times {|i| draw_triangle(i)}
    ar = []
    5.times {|i| ar << @b[i].to_w(@o)}
    polygon(@fill, ar)
  else
    ar = []
    5.times {|i| ar << @a[i].to_w(@o); ar << @b[i].to_w(@o)}
    polygon(@fill, ar)
  end
end