python代码画樱花-python画樱花树代码 具体代码介绍

  • Post author:
  • Post category:python


1、python画樱花树代码为:

import turtle as T

import random

import time

2、# 画樱花的躯干(60,t)

def Tree(branch, t):

time.sleep(0.0005)

if branch > 3:

if 8 <= branch <= 12:

if random.randint(0, 2) == 0:

t.color(‘snow’) # 白

else:

t.color(‘lightcoral’) # 淡珊瑚色

t.pensize(branch / 3)

elif branch < 8:

if random.randint(0, 1) == 0:

t.color(‘snow’)

else:

t.color(‘lightcoral’) # 淡珊瑚色

t.pensize(branch / 2)

else:

t.color(‘sienna’) # 赭(zhě)色

t.pensize(branch / 10) # 6

t.forward(branch)

a = 1.5 * random.random()

t.right(20 * a)

b = 1.5 * random.random()

Tree(branch – 10 * b, t)

t.left(40 * a)

Tree(branch – 10 * b, t)

t.right(20 * a)

t.up()

t.backward(branch)

t.dow