Code offer:
from Random Import *
from Math Import *
DEF Tree (n-, L):
Setup (1000, 800)
PD () # write
# shadow effect
T = COS (radians (heading () + 45)) /. 8 + 0.25
penColor (T , T, T)
Pensize (R) (n-/. 3)
Forward (L) Videos branches #
n-IF> 0:
B = Random () * + 10 # 15 right branch displacement angle
c = random () * 15 + 10 # deflected left branch angle
d = l * (random () * 0.25 + 0.7) of the length of the next branch #
# right turn at an angle, right branch Videos
right (B)
Tree (n--. 1, D)
# left angle, the left branch Videos
left (B + C)
Tree (n--. 1, D)
# turn back
right (C)
the else:
# leaves Videos
right (90)
n-= COS (radians (heading () - 45)) /. 4 + 0.5
penColor (n-, n-* 0.8, n-* 0.8)
Circle (. 3)
left (90)
# 0.3 times the falling leaves
if ( Random ()> 0.7):
PU ()
# falling
T = heading ()
AN = -40 + Random () * 40
setHeading (AN)
DIS = int (800 * Random () * 0.5 + 400 * Random () * 0.3 Random 200 is * + () * 0.2)
Forward (DIS)
setHeading (T)
# Videos leaves
PD ()
right (90)
n-= COS (radians (heading () - 45)) / + 0.5. 4
penColor (n-* 0.5 + 0.5, 0.4 + n-* 0.4, 0.4 + n-* 0.4)
Circle (2)
left (90)
PU ()
# Returns
T = heading ()
setHeading (AN)
Backward (DIS)
setHeading (T)
PU ()
Backward (L) # return
bgcolor (0.5, 0.5, 0.5) # background color
ht () # Hide Turtle
speed (0) # velocity, progressive 1-10, 0 fastest
Tracer (0, 0)
PU () # pen-
backward (100)
left (90) # 90 degrees left
PU () # pen-
backward (300) # back 300
Tree (12 is, 100) layer 7 # recursive
done ()
operation result:
Past Events: painting pig in Python Page https://blog.csdn.net/weixin_44015669/article/details/105169549