2024年4月15日发(作者:)
```python
import turtle
import random
# 设置画布
(800, 600)
r("skyblue")
# 创建画笔
pen = ()
(0)
(3)
# 定义颜色列表
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
# 定义圣诞树的层数
tree_layers = 5
# 画圣诞树
def draw_tree(x, y, size):
()
(x, y)
()
((colors))
_fill()
for _ in range(3):
d(size)
(120)
_fill()
if size > 30:
draw_tree(x - size / 2, y - size * 2 / 3, size / 2)
draw_tree(x + size / 2, y - size * 2 / 3, size / 2)
# 画雪花
def draw_snowflake(x, y, size):
()
(x, y)
()
((colors))
_fill()
for _ in range(3):
d(size)
rd(size)
(120)
_fill()
# 画星星
def draw_star(x, y, size):
()
(x, y)
()
((colors))
_fill()
for _ in range(5):
d(size)
(144)
_fill()
# 主程序
for i in range(tree_layers):
draw_tree(0, -i * 30, 30 + i * 10)
for _ in range(100):
x = t(-350, 350)
y = t(-250, 250)
size = t(5, 20)
draw_snowflake(x, y, size)
for _ in range(50):
x = t(-350, 350)
y = t(-250, 250)
size = t(3, 10)
draw_star(x, y, size)
()
```
发布者:admin,转转请注明出处:http://www.yc00.com/web/1713131686a2189135.html
评论列表(0条)