Hi, I just received a project in my class where i have to write my own turtle class in python which I will have to use to draw a Koch snowflake. Currently I have no idea on how to get started on the turtle class? If anyone knows or has any tip please reply! Thanks.

You could implement the turtle movements using complex number support in Python.

commented: great idea +13

Actually I am new to python so I'm not really sure what you mean???

Well, now I understand koch snowflake, but how would I write the turtle class to draw it because for this project we have to write our own turtle class, this is what I have so far:

class Turtle:
    def __init__(self, location, direction):
        self.location = location
        self.direction = direction * math.pi / 180

    def moveTo(self, somePoint):
        some code..
    def draw(self, length, win):
        some code..
    def turn(self, degrees):
        some code..

I don't understand how to actually draw the line and then rotate it in python????

You need to start out with a GUI toolkit like Tkinter that comes with Python. That will do the actual drawing.

The turtle will point in a certain direction and you have to use trigonometry to calculate the length of the line and its end point (x, y) from the angle the line has to be drawn.

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.