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):
        <code>

    def forward(self, length):
        <code>

    def turn(self, degrees):
       <code>

    def setLocation(self, newX, newY):
       <code>

    def setDirection(#can't think of arguments)
      <code>

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!

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'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.