"Python" draws a tree with the Turtle Library

Source: Internet
Author: User

#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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.