# L-26 MCS 260 Fri 11 Mar 2016 : spirbot
"""
Karl the Robot is a simple programming model based on turtle graphics.
The class below provides an encapsulation of the turtle module.
We let the robot make a spiral walk.
"""
from turtle import Turtle

class Robot(object):
    """
    Plots the path of a robot in a turtle window.
    """
    def __init__(self, a=0, b=0, d=10):
        """
        Initializes the robot at position (a,b)
        and sets the step size to d pixels.
        """
        self.bob = Turtle()
        self.bob.penup()
        self.bob.goto(a, b)
        self.stp = d   # step size
        self.xdr = 0   # x-direction
        self.ydr = 1   # y-direction
        self.bob.pendown()

    def turn(self):
        """
        Makes one right turn of 90 degrees.
        """
        (self.xdr, self.ydr) = (self.ydr, -self.xdr)

    def step(self):
        """
        Does one step in the current direction.
        """
        (xps, yps) = self.bob.position()
        xps = xps + self.stp*self.xdr
        yps = yps + self.stp*self.ydr
        self.bob.goto(xps, yps)

def main():
    """
    Lets the robot draw a spiral path.
    """
    karl = Robot()
    karl.step()
    nbs = 1  # number of steps
    for k in range(0, 50):
        karl.turn()
        for _ in range(0, nbs):
            karl.step()
        if k % 2 == 0:
            nbs = nbs + 1
    input('hit enter to exit')

main()
