# FILENAME: fractreemodule.py from visual import * ####### FUNCTION fractree - DON'T NEED TO MODIFY THIS FUNCTION DEFN. ## Arguments: ## parentframe - frame for this tree or branch ## shrink - factor to shrink at each level ## axislist - list of branch orientations (3-tuples or vectors) ## poslist - position of subbranches along main branch ## scale - current length scale (how big branch is) ## level - how many generations to go. ## Returns: ## a real number that is the surface area of the tree. ## returns surface area of tree for calculating ## the fractal dimension. def fractree(parentframe,shrink,axislist,poslist,scale,level): newscale=scale*shrink ### draw a branch cylinder(frame=parentframe, radius=scale*0.1, axis=(scale,0,0)) ### surface area of branch - not counting caps of cylinder. surfarea = 2.0 * pi * (scale * 0.1) * scale if (level == 0): ## draws a leaf - doesn't count as bark area - just decoration cylinder(radius=scale*0.5,axis=(newscale*0.2,0,0), pos=(scale,0,0), color=color.green,frame=parentframe) if (level != 0): for i in range(len(axislist)): childframe=frame(frame=parentframe, axis=axislist[i], x=poslist[i]*scale) surfarea = surfarea + fractree(childframe,shrink,axislist,poslist,newscale,level-1) return surfarea