Python编程教程中关于樱花树部分的代码如下:
import turtle as tu
import random as ra
def flower():
tu.hideturtle()
tu.pensize(2)
tu.pencolor("pink")
flowersize = ra.randint(1,5)
for j in range(5):
tu.forward(int(flowersize))
tu.backward(int(flowersize))
tu.right(72)
def tree(n,k):
tu.pendown()
tu.pencolor("black")
tu.pensize(n/4)
tu.forward(k)
if n>0:
r=ra.random()10+10
l=ra.random()10+10
x=k(ra.random()0.25+0.7)
tu.right(r)
暂无评论