python代码画一个流星雨
时间: 2023-12-10 18:04:02 浏览: 113
一起来看流星雨源代码
下面是Python代码画一个流星雨的示例:
```python
import turtle as tu
import random as ra
import math
tu.setup(1.0, 1.0)
tu.screensize(1.0, 1.0)
tu.bgcolor('black')
t = tu.Pen()
t.ht()
colors = ['red', 'yellow', 'white', 'purple', 'blue', 'green']
def draw_star(x, y, size, color):
t.pencolor(color)
t.penup()
t.goto(x, y)
t.pendown()
t.begin_fill()
for i in range(5):
t.forward(size)
t.right(144)
t.end_fill()
def draw_meteor(x, y, size, color):
t.pencolor(color)
t.penup()
t.goto(x, y)
t.pendown()
t.right(45)
t.forward(size)
t.right(135)
t.forward(size * 2)
t.right(135)
t.forward(size)
t.right(45)
while True:
x = ra.randint(-500, 500)
y = ra.randint(-300, 300)
size = ra.randint(10, 50)
color = ra.choice(colors)
draw_meteor(x, y, size, color)
draw_star(x, y, size / 5, color)
t.clear()
```
阅读全文