An iterative method for the (mentally retarded) function of a fractal tree using Python

Source: Internet
Author: User

Start with every branch of the tree

The basic idea is to draw a "Y" type, start from the root, then return to the root, and then turn and iterate as needed. Just pay attention to the direction of the nib.

1 defGreeny ():2TURTLE.FD (40)3Turtle.left (30)4TURTLE.FD (20)5Turtle.backward (20)6Turtle.right (60)7TURTLE.FD (20)8Turtle.backward (20)9Turtle.left (30)TenTurtle.backward (40) One defDoublegreeny (): ATurtle.color ("Green") - Turtle.pendown () - #Turtle.left (+) the      forIinch[30,-60]: - Turtle.left (i) - Greeny () -Turtle.left (30)

and follow the red trunks.

1 defredy ():2     #3Turtle.color ("Red")4 #Turtle.left (+)5TURTLE.FD (50)6Turtle.left (30)7TURTLE.FD (50)8 Doublegreeny ()9Turtle.color ("Red")   TenTurtle.backward (50) OneTurtle.left (-60) ATURTLE.FD (50) - Doublegreeny () -Turtle.color ("Red")   theTurtle.backward (50) -Turtle.left (30) -Turtle.backward (50) - defdoubleredy (): + #Turtle.setup (400,400) -Turtle.color ("Red") +TURTLE.FD (50) A      forIinch[30,-60]: at Turtle.left (i) - redy () -Turtle.left (30) -Turtle.backward (50)

The result is the final output.

For aesthetics, fine-tuned the length and angle of the trunk.

Ps. This is the author's own 1.1-point fine-tuning out, modification and maintenance are not easy. and the "Artificial function iteration" makes the dependency between each other too strong.

The first program to be a beginner python.

Have the opportunity to optimize the code later

An iterative method for the (mentally retarded) function of a fractal tree using Python

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.