Hi,
I am playing around with some Fractal drawing using the canvas module. My scripts use recursion and I am finding that if I go to many levels deep (10ish) and “wide” then the output flashes up briefly and disappears. By “wide” l am referring to the fact that my recursion doubles each time I go down a level as it calls itself twice. The result is that the stack probably resembles the Fractal Tree I am trying to draw.
Adding begin_updates and end_updates just causes a crash.
Any advice on how I might get around this?
import random
import canvas
from math import pi
def drawBranch( angle, length):
if length < 10:
return
canvas.draw_line( 0, 0, 0, length)
canvas.translate( 0, length)
canvas.save_gstate()
canvas.rotate( angle * pi / 180)
drawBranch( angle, length -10)
canvas.restore_gstate()
canvas.save_gstate()
canvas.rotate( - angle * pi / 180)
drawBranch( angle, length -10)
canvas.restore_gstate()
width = 800
height = 800
canvas.set_size( width, height)
canvas.translate( width / 2, 0)
drawBranch( 17, 120)