python满天星代码可复制
时间: 2023-10-06 07:14:55 浏览: 473
你可以使用以下Python代码生成一个满天星的效果:
```python
from turtle import *
import random
def cell(l1):
down()
for i in range(6):
forward(l1)
left(60)
forward(l1)
right(120)
up()
def lrk(l1, l2):
up()
width(random.randint(1,4))
colormode(255)
color(random.randint(0,255), random.randint(0,255), random.randint(0,255))
goto(random.randint(0,300), random.randint(0,300))
cell(l1)
global t
t = not t
if l1/3 < l2:
return
elif t == 1:
l1 *= random.randint(1,2)
else:
l1 /= random.randint(1,4)
lrk(l1, l2)
def stars():
t = 1
speed(10)
lrk(10, 0.1)
stars()
done()
```
阅读全文