```python
import turtle
import random
# 设置画布
turtle.setup(800, 600)
turtle.bgcolor("skyblue")
# 创建画笔
pen = turtle.Turtle()
pen.speed(0)
pen.width(3)
# 定义颜列表
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
# 定义圣诞树的层数
tree_layers = 5
# 画圣诞树
def draw_tree(x, y, size):
pen.up()
(x, y)
pen.down()
lor(random.choice(colors))
pen.begin_fill()
for _ in range(3):
pen.forward(size)
pen.left(120)
d_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):
pen.up()
(x, y)
pen.down()
lor(random.choice(colors))
pen.begin_fill()
for _ in range(3):
pen.forward(size)
pen.backward(size)
pen.right(120)
random python d_fill()
# 画星星
def draw_star(x, y, size):
pen.up()
(x, y)
pen.down()
lor(random.choice(colors))
pen.begin_fill()
for _ in range(5):
pen.forward(size)
pen.right(144)
d_fill()
# 主程序
for i in range(tree_layers):
draw_tree(0, -i * 30, 30 + i * 10)
for _ in range(100):
x = random.randint(-350, 350)
y = random.randint(-250, 250)
size = random.randint(5, 20)
draw_snowflake(x, y, size)
for _ in range(50):
x = random.randint(-350, 350)
y = random.randint(-250, 250)
size = random.randint(3, 10)
draw_star(x, y, size)
turtle.done()
```
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论