Class: Oekaki::Turtle
Instance Attribute Summary collapse
Attributes inherited from Tool
#height, #width, #window
Instance Method Summary
collapse
Methods inherited from Tool
#arc, #clear, #get_pic, #get_window_size, #line, #lines, #load_pic, #point, #polygon, #rectangle, #save_pic, #show_pic, #star, #text, #timer_stop
Constructor Details
#initialize ⇒ Turtle
Returns a new instance of Turtle.
196
197
198
199
200
201
202
203
|
# File 'lib/oekaki.rb', line 196
def initialize
super
@pen = Tool.new
@pen_po = Vector[0, 0]
@dir = Vector[1, 0]
@color_t = [65535, 65535, 65535]
@width, @height = @pen.get_window_size
end
|
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
204
205
206
|
# File 'lib/oekaki.rb', line 204
def dir
@dir
end
|
#pen_po ⇒ Object
Returns the value of attribute pen_po.
204
205
206
|
# File 'lib/oekaki.rb', line 204
def pen_po
@pen_po
end
|
Instance Method Details
#back(length) ⇒ Object
225
226
227
|
# File 'lib/oekaki.rb', line 225
def back(length)
forward(-length, false)
end
|
#circle(radius, fill = false) ⇒ Object
234
235
236
237
|
# File 'lib/oekaki.rb', line 234
def circle(radius, fill = false)
@pen.color(*@color_t)
@pen.circle(fill, @width / 2 + @pen_po[0], @height / 2 - @pen_po[1], radius)
end
|
#color(r, g, b) ⇒ Object
229
230
231
232
|
# File 'lib/oekaki.rb', line 229
def color(r, g, b)
@color_t = [r, g, b]
@pen.color(*@color_t)
end
|
#forward(length, draw = true) ⇒ Object
215
216
217
218
219
220
221
222
223
|
# File 'lib/oekaki.rb', line 215
def forward(length, draw = true)
next_po = @pen_po + @dir * length
if draw
@pen.color(*@color_t)
@pen.line(@width / 2 + next_po[0], @height / 2 - next_po[1],
@width / 2 + @pen_po[0], @height / 2 - @pen_po[1])
end
@pen_po = next_po
end
|
#left(deg) ⇒ Object
206
207
208
209
|
# File 'lib/oekaki.rb', line 206
def left(deg)
θ = PI * deg / 180
@dir = Matrix[[cos(θ), -sin(θ)], [sin(θ), cos(θ)]] * @dir
end
|
#move(x, y) ⇒ Object
239
240
241
|
# File 'lib/oekaki.rb', line 239
def move(x, y)
@pen_po = Vector[x, y]
end
|
#right(deg) ⇒ Object
211
212
213
|
# File 'lib/oekaki.rb', line 211
def right(deg)
left(-deg)
end
|