python圣诞树粒子代码
时间: 2023-12-25 08:30:23 浏览: 127
以下是一个使用Python的turtle模块绘制圣诞树粒子的例子:
```python
import turtle
def draw_tree():
turtle.speed(10)
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.color("green")
turtle.begin_fill()
turtle.left(90)
turtle.forward(200)
turtle.right(135)
turtle.forward(280)
turtle.left(135)
turtle.forward(280)
turtle.right(135)
turtle.forward(200)
turtle.end_fill()
def draw_particle(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
def main():
turtle.setup(800, 600)
turtle.bgcolor("black")
turtle.title("Christmas Tree Particle")
turtle.hideturtle()
turtle.speed(0)
draw_tree()
for _ in range(100):
x = random.randint(-400, 400)
y = random.randint(-200, 200)
draw_particle(x, y)
turtle.done()
if __name__ == "__main__":
main()
```
阅读全文