# [Quiz] Turtle Graphics (#104)

Here is my quick solution.
( Quick, so, it will fail the unit test, since it does not check the
parameters and throw the expected exception; however, it shows the
example graphics correctly )

pointing

# Y-axis (north) in degrees.

class Turtle
include Math # turtles understand math methods
DEG = Math::PI / 180.0

attr_accessor :track
alias run instance_eval

def initialize
clear
end

changes

def xy=(coords)
@xy = coords.dup
end

end

given.
def pen_up
@pen = false
end

def pen_down
@pen = true
end

def pen_up?
!pen_down?
end

def pen_down?
@pen
end

def home
@xy = [0.0, 0.0]
pen_up
end

def clear
home
@track = []
end

# Turn right through the angle .

def right(degrees)
end

# Turn left through the angle .

def left(degrees)
right(-degrees)
end

# Move forward by turtle steps.

def forward(steps)
x = @xy[0] + steps * cos((90 - @heading) * DEG)
y = @xy[1] + steps * sin((90 - @heading) * DEG)
go([x,y])
end

def back(steps)
forward(-steps)
end

# Move to the given point.

def go(pt)
if @pen
if !@track.empty? && @track.last.last == @xy
@track.last << pt.dup
else
@track << [@xy.dup, pt.dup]
end
end
@xy = pt.dup
end

# Turn to face the given point.

def toward(pt)
@heading = 90 - acos((pt[0] - @xy[0]) / distance(pt)) / DEG
end

# Return the distance between the turtle and the given point.

def distance(pt)
sqrt((@xy[0] - pt[0]) ** 2 + (@xy[1] - pt[1]) ** 2)
end

# Traditional abbreviations for turtle commands.

alias fd forward
alias bk back
alias rt right
alias lt left
alias pu pen_up
alias pd pen_down
alias pu? pen_up?
alias pd? pen_down?