用python画一个爱心的代码是什么
时间: 2024-04-30 19:17:28 浏览: 67
python画爱心代码
代码如下:
```python
import turtle
# function to draw a heart
def heart(turtle, x, y, size):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
turtle.setheading(45)
turtle.begin_fill()
for i in range(2):
turtle.circle(size, 180)
turtle.right(90)
turtle.forward(size*2)
turtle.end_fill()
# create a turtle object
pen = turtle.Turtle()
pen.speed(0)
pen.color('red')
# draw a heart
heart(pen, 0, 0, 100)
# hide the turtle object
pen.hideturtle()
# keep the window open
turtle.done()
```
运行程序,就能看到一个大红色的爱心啦!
阅读全文