流星雨代码编程python可复制
时间: 2023-11-06 12:06:42 浏览: 161
代码流星雨
以下是一个简单的Python代码,用于生成流星雨的效果:
```python
import random
import time
WIDTH = 80
HEIGHT = 25
stars = []
for i in range(50):
star = {'x': random.randint(0, WIDTH),
'y': random.randint(0, HEIGHT),
'size': random.randint(1, 3)}
stars.append(star)
while True:
for star in stars:
print('\033[{};{}H{}'.format(star['y'], star['x'], '*' * star['size']))
star['y'] += 1
if star['y'] > HEIGHT:
star['x'] = random.randint(0, WIDTH)
star['y'] = random.randint(0, 1)
time.sleep(0.1)
print('\033[2J')
```
阅读全文