From: Michael Katz-H. <mi...@go...> - 2001-09-10 04:41:01
|
A friend and I were remembering the days of LOGO... He downloaded an implementation of LOGO and wrote a function to draw the 'dragon' fractal. I did them same but in VPython...it is attached here. -Michael P.S. - I get some weird screen artifacts when using curves to draw the fractals, I am assuming this is just a bug in the OpenGL implementation (I have only tried this in Linux) ## The dragon fractal ## ## The arguements to dragon are the iterations and the "size" ## dragon(iterations,size) size has little meaning since vpython ## autoscales from visual import * curr = vector(0,0,0) dir = vector(0,1,0) colors = [color.red,color.green,color.blue,color.yellow,color.magenta] col = color.red def forward(size): global curr global col global drag for s in arange(0,size,size/50.): drag.append(pos=(curr+dir),color=col) curr = curr+dir def right(ang): global dir dir = rotate(dir,angle=-ang,axis=(0,0,1)) def left(ang): global dir dir = rotate(dir,angle=ang,axis=(0,0,1)) def step(iter,size,rev,pc): global curr global dir if iter==0: forward(size) return if rev==0: step(iter-1,size,rev,pc) right(pi/2) step(iter-1,size,1-rev,pc) else: global col if pc==0: col = colors[(iter%5)] step(iter-1,size,1-rev,1) left(pi/2) step(iter-1,size,rev,1) def dragon(iter,size): global drag drag = curve() step(iter,size,0,0) dragon(11,10) -- /-------------------------------------------------------------\ | Michael Katz-Hyman mz...@an... | | Pittsburgh, PA USA http://www.andrew.cmu.edu/~mzk | \-------------------------------------------------------------/ |