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<=small est):
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<=small est):
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_lengt h, 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
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<=small est):
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<=small est):
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_lengt h, 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
Comment