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