粒子爱心代码编程python复制
时间: 2023-11-17 20:02:55 浏览: 844
是Python编程语言中绘制粒子爱心的代码,你可以将其复制到你的.py文件中并运行它:
```python
import turtle
import time
import random
def drawHeart(x, y):
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.color('pink', 'pink')
turtle.begin_fill()
turtle.left(45)
turtle.forward(100)
turtle.circle(50, 180)
turtle.right(90)
turtle.circle(50, 180)
turtle.forward(100)
turtle.end_fill()
def drawParticle(x, y):
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.color('red', 'red')
turtle.begin_fill()
turtle.circle(2)
turtle.end_fill()
turtle.speed(0)
turtle.hideturtle()
turtle.bgcolor('black')
for i in range(50):
x = random.randint(-300, 300)
y = random.randint(-200, 200)
drawParticle(x, y)
drawHeart(0, 0)
while True:
x = random.randint(-300, 300)
y = random.randint(-200, 200)
drawParticle(x, y)
time.sleep(0.1)
```
阅读全文