Need help? Post your question and get tips & solutions from a community of 375,873 IT Pros & Developers. It's quick & easy.

making fractals in python

 P: n/a 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 Dec 12 '05 #1