#drawtree.py fromTurtleImportTurtle, MainloopdefTree (plist, L, A, f):"""plist is List of pens L are length of branch A is half of the angle between 2 branches F are factor by which B Ranch is shortened from level to level.""" ifL > 5:#LST = [] forPinchPlist:p.forward (L)#Draw Your move in the current direction the turtle forward by the specified distance, the direction of the turtle is headed.Q = P.clone ()#Create and return a clone of the turtle with same position, heading and turtle properties.P.left (a)#Turn Turtle left by angle unitsQ.right (a)#Turn turtle right by angle units, nits is by default degrees, but can is set via the degrees () and radians () functio NS.Lst.append (P)#adds an element to the end of the listlst.append (q) tree (LST, l*F, A, f)defMain (): P=Turtle () P.color ("Green") P.pensize (5) #P.setundobuffer (None)P.hideturtle ()#Make the turtle invisible. It's a good idea-to-do middle of doing some complex drawing, #because hiding the turtle speeds up the drawing observably. #P.speed (Ten) #P.getscreen (). Tracer (1,0) #Return The Turtlescreen object, the turtle on.P.speed (10) #Turtlescreen methods can then is called for that object.P.left (90)#Turn Turtle left by angle units. Direction Adjustment BrushP.penup ()#Pull the pen Up–no drawing when moving.P.goto (0,-200)#Move Turtle to an absolute position. If the pen is off, draw line. Don't change the Turtle ' s orientation.P.pendown ()#Pull the pen down–drawing when moving. These three statements are a combination of the equivalent of putting the pen away before moving it to the specified position, then putting the pen down and starting the drawing #otherwise the turtle will automatically draw the line as soon as it moves. #T = tree ([P], (+), 0.6375)t = tree ([p], 200, 65, 0.6375) Main ()
Http://www.jb51.net/article/116724.htm
"Python" draws a tree with the Turtle Library