Writing my own turtle class (I understand that Python has it's own turtle class, but this is for an assignment) with an imported graphics.py to draw a koch snowflake and c-curve.

What I have came up with so far are all the functions I need. I just need some assistance in writing them...

class turtle:
    def __init__(self, location, direction):

    def forward(self, length):

    def turn(self, degrees):

    def setLocation(self, newX, newY):

    def setDirection(#can't think of arguments)

There is no need to provide the rest of the code for me, as I would like to understand for myself. Just some hints or criticism towards which direction I should head is helpful enough. Thanks!

8 Years
Discussion Span
Last Post by Lardmeister

Should your turtle support a pen up / pen down setting?

Should your turtle support a pen color?

It should be straight-forward to write the 'forward' code...

You have a current location and a direction and a distance.

for each step in the distance:
   If the pen is down:
      set the current location to the current pen color
   advance the current location to the next location based on the direction

Your proposed 'set direction' method should probably take a degrees (like turn does) but instead of turning relatively, it should do an absolute turn.


The initial letter of your class name should be in upper case. In your class constructor you may want to add args for turtle symbol and speed. Let location default to center of screen, direction to up, speed to 'slow' and symbol to 'triangle'.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.