python画漂亮的树一束鲜花送情人_火树红花_作者:李兴球

python画漂亮的树一束鲜花送情人_火树红花_李兴球

from turtle import *
from random import randint
from time import sleep

color_list = ["yellow","purple","red","cyan","green","blue"]
r = [1.2,1.6]

screen = Screen()
screen.setup(800,800)
screen.bgcolor("black")
screen.bgpic("background.png")
screen.title("一束鲜花送情人_火树红花_作者:李兴球")

t = Turtle(visible=False)            # 新建海龟,先写字,再画树
t.penup()                            # 抬笔
t.color("white")                     # 画笔颜色为白色
t.setheading(90)                     # 朝上
t.bk(130)
t.pendown()                          # 落笔

     
def draw_tree(length,level):
    
    if level == 0: return    
    t.pencolor(color_list[level-1])  # 随机从颜色列表中选择一种颜色作为画笔颜色
    t.fd(length)
    t.left(20)
    i = randint(0,1)
    draw_tree(length/r[i],level-1);t.dot(10,"red")    # 注意 r[i],它的值可能是1.2也可能是1.6
    t.right(40)
    draw_tree(length/r[(1-i)],level-1);t.dot(10,"red")# 注意 r[i],它的值可能是1.2也可能是1.6

    t.left(20)
    t.pencolor(color_list[level-1])
    t.bk(length)

You must log in to read the rest of this article. Please log in or register as a user.