效果如下:

clipboard.png

代码如下:

from turtle import *
from random import *
from math import *


def tree(n, l):
    pd()
    t = cos(radians(heading() + 45)) / 8 + 0.25

    pencolor(t, t, t)
    pensize(n / 4)
    forward(l)
    if n > 0:
        b = random() * 15 + 10
        c = random() * 15 + 10
        d = l * (random() * 0.35 + 0.6)
        right(b)
        tree(n - 1, d)
        left(b + c)
        tree(n - 1, d)
        right(c)
    else:
        right(90)
        n = cos(radians(heading() - 45)) / 4 + 0.5
        pencolor(n, n, n)
        circle(2)
        left(90)
    pu()
    backward(l)


bgcolor(0.5, 0.5, 0.5)
ht()
speed(0)
tracer(0, 0)
left(90)
pu()
backward(300)
tree(13, 100)
done()

Mixtual悦岚
47 声望3 粉丝

python矿粉,技术型宅,王者也666,爱分享