Hey I'm very new to the programming world, and what i am trying to do is produce a Koch Snowflake via turtle from python2.5.
this is what I have so far...

from turtle import *

def snowflake(lengthSide, levels):
    if levels == 0:
        return forward(lengthSide), right(120), forward(lengthSide), right(120), forward(lengthSide)
    
    forward(lengthSide)
    left(60)
    forward(lengthSide)
    right(60)
    right(60)
    forward(lengthSide)
    left(60)
    forward(lengthSide)
    right(120)
    snowflake(lengthSide, levels)

as you can see i've only solved for levels 0 and 1... the problem is i dont understand how to recursively redraw it from a certain location. If anyone has any ideas or tip, it would be helpful.

I suggest this

from turtle import *

def snowflake(lengthSide, levels):
    if levels == 0:
        forward(lengthSide)
        return
    lengthSide /= 3.0
    snowflake(lengthSide, levels-1)
    left(60)
    snowflake(lengthSide, levels-1)
    right(120)
    snowflake(lengthSide, levels-1)
    left(60)
    snowflake(lengthSide, levels-1)


if __name__ == "__main__":
    speed(0)
    length = 300.0
    penup()
    backward(length/2.0)
    pendown()
    snowflake(length, 4)

how do you modify the code so that it can make a full snowflake?

Simply define

def full_snowflake(lengthside, levels):
    for i in range(3):
        snowflake(lengthside, levels)
        right(120)
from turtle import *

def snowflake(lengthSide, levels):
    if levels == 0:
        forward(lengthSide)
        return
    lengthSide /= 3.0
    snowflake(lengthSide, levels-1)
    left(60)
    snowflake(lengthSide, levels-1)
    right(120)
    snowflake(lengthSide, levels-1)
    left(60)
    snowflake(lengthSide, levels-1)

def full_snowflake(lengthside, levels):
    for i in range(3):
        snowflake(lengthside, levels)
        right(120)

if __name__ == "__main__":
    speed(0)
    length = 300.0
    penup()
    backward(length/2.0)
    pendown()
    full_snowflake(length, 4)
    mainloop()

Here is a snowflakes containing printable characters

from turtle import *
import random, string

fact = (2.0/(3.0*sqrt(3.0)), sqrt(3.0)/2.0, 0.5)

def writers(cx, cy, lengthside, levels):
    if levels == 0:
        penup()
        goto(cx, cy)
        pendown()
        write(random.choice(string.printable))
        return
    r = lengthside * fact[0]
    a = r * fact[1]
    b = r * fact[2]
    centers = [(cx, cy), (cx, cy+r), (cx, cy-r), (cx+a, cy+b), (cx+a, cy-b), (cx-a, cy+b), (cx-a, cy-b)]
    for ux, uy in centers:
        writers(ux, uy, lengthside/3.0, levels-1)

if __name__ == "__main__":
    speed(0)
    length = 500.0
    writers(0.0, 0.0, length, 4)
    mainloop()
This question has already been answered. Start a new discussion instead.