making fractals in python
evil_daffid
dfmolyneux at hotmail.co.uk
Mon Dec 12 09:56:57 EST 2005
hi,
Im reseaching fractals, and how to make them in python using recursion.
I've written a bit of code to make the koch isalnd but something isn't
right, I have the basic shape but there's something wrong with the
recursion i've used, could someone help me.
Here is the code im using:
import turtle
turtle.clear
def koch_line(line_length, smallest):
third = line_length/3
if (third <= smallest):
turtle.forward(line_length)
else:
koch_line(third,smallest)
turtle.right(90)
if(third<=smallest):
turtle.forward(line_length/2)
else:
koch_line(line_length/2, smallest)
turtle.right(90)
if (third <= smallest):
turtle.forward(third)
else:
koch_line(line_length/2, smallest)
turtle.left(90)
if (third <= smallest):
turtle.forward(third)
else:
koch_line(line_length,smallest)
if (third <= smallest):
turtle.forward(line_length)
else:
koch_line(third,smallest)
turtle.right(90)
if(third<=smallest):
turtle.forward(line_length/2)
else:
koch_line(line_length/2, smallest)
turtle.right(90)
if (third <= smallest):
turtle.forward(third)
else:
koch_line(line_length/2, smallest)
turtle.left(90)
if (third <= smallest):
turtle.forward(third)
else:
koch_line(line_length,smallest)
return
def koch(line_length, smallest):
koch_line(line_length, smallest)
turtle.left(90)
koch_line(line_length, smallest)
turtle.left(90)
koch_line(line_length, smallest)
return
koch(500,10)
Thank you for your help
More information about the Python-list
mailing list