废话不多说了,直接上代码吧!
#!/usr/bin/env python
# coding=utf-8
# 画一棵樱花
import turtle
import random
from turtle import *
from time import sleep
# 画樱花的躯干(60,t)
def tree(branchLen,t):
sleep(0.0005)
if branchLen >3:
if 8<= branchLen <=12:
if random.randint(0,2) == 0:
t.color('snow') # 白
else:
t.color('lightcoral') # 淡珊瑚色
t.pensize(branchLen / 3)
elif branchLen <8:
if random.randint(0,1) == 0:
t.color('snow')
else:
t.color('lightcoral') # 淡珊瑚色
t.pensize(branchLen / 2)
else:
t.color('sienna') # 赭(zhě)色
t.pensize(branchLen / 10) # 6
t.forward(branchLen)
a = 1.5 * random.random()
t.right(20*a)
b = 1.5 * r