如何用python画一朵樱花,pythonturtle绘图代码樱花

您所在的位置:网站首页 python樱花飘落代码手机 如何用python画一朵樱花,pythonturtle绘图代码樱花

如何用python画一朵樱花,pythonturtle绘图代码樱花

2024-07-10 11:49| 来源: 网络整理| 查看: 265

import turtle from random import * from math import * def tree(n, l): turtle.pendown() # 下笔 # 阴影效果 t = cos(radians(turtle.heading() + 45))/8 + 0.25 turtle.pencolor(t, t, t) turtle.pensize(n/3) turtle.forward(l) # 画树枝 if n > 0: b = random() * 15 + 10 # 右分支偏转角度 c = random() * 15 + 10 # 左分支偏转角度 d = l * (random() * 0.25 + 0.7) # 下一个分支的长度 # 右转一定角度,画右分支 turtle.right(b) tree(n - 1, d) # 左转一定角度,画左分支 turtle.left(b + c) tree(n - 1, d) # 转回来 turtle.right© else: # 画叶子 turtle.right(90) n = cos(radians(turtle.heading() - 45)) / 4 + 0.5 turtle.pencolor(n, n * 0.8, n * 0.8) turtle.circle(3) turtle.left(90) # 添加0.3倍的飘落叶子 if (random() > 0.7): turtle.pu()



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3