我要一个python粒子爱心代码
时间: 2024-05-20 09:09:42 浏览: 134
python代码~爱心源码
以下是一个简单的Python粒子爱心代码,你可以在Python环境中运行它。
```python
import turtle
def draw_heart(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color('red')
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 draw_particle(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.color('pink')
turtle.begin_fill()
turtle.circle(3)
turtle.end_fill()
turtle.speed(0)
turtle.hideturtle()
turtle.getscreen().bgcolor('black')
for x in range(-400, 400, 5):
for y in range(-400, 400, 5):
distance = ((x**2) + (y**2))**0.5
if distance < 200:
draw_particle(x, y)
draw_heart(0, -150)
turtle.done()
```
阅读全文