Python爱心粒子代码
时间: 2023-10-06 08:13:42 浏览: 337
表白python画出心心相印爱心代码
Python爱心粒子代码如下:
```python
import turtle
def draw_heart(x, y, size):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.fillcolor('red')
turtle.begin_fill()
turtle.left(140)
turtle.forward(size)
turtle.circle(-size, 200)
turtle.right(120)
turtle.circle(-size, 200)
turtle.forward(size)
turtle.end_fill()
def main():
turtle.setup(800, 600)
turtle.speed(3)
turtle.pensize(3)
turtle.color('red')
# 绘制爱心粒子
for i in range(30):
x = random.randint(-400, 400)
y = random.randint(-300, 300)
size = random.randint(10, 100)
draw_heart(x, y, size)
turtle.hideturtle()
turtle.done()
if __name__ == '__main__':
main()
```
阅读全文