class Oekaki::Turtle

Attributes

dir[RW]
pen_po[RW]

Public Class Methods

new() click to toggle source
Calls superclass method Oekaki::Tool::new
# 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

Public Instance Methods

back(length) click to toggle source
# File lib/oekaki.rb, line 225
def back(length)
  forward(-length, false)
end
circle(radius, fill = false) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/oekaki.rb, line 206
def left(deg)
  θ = PI * deg / 180
  @dir = Matrix[[cos(θ), -sin(θ)], [sin(θ), cos(θ)]] * @dir
end
move(x, y) click to toggle source
# File lib/oekaki.rb, line 239
def move(x, y)
  @pen_po = Vector[x, y]
end
right(deg) click to toggle source
# File lib/oekaki.rb, line 211
def right(deg)
  left(-deg)
end