Python的爱心代码
时间: 2023-05-24 12:05:02 浏览: 56
把以下代码复制到你的编辑器中:
```python
import turtle
import time
# 设置画面大小
turtle.setup(width=600, height=600)
# 隐藏海龟画笔
turtle.hideturtle()
# 将海龟画笔移动到起始点
turtle.up()
turtle.goto(0, -230)
turtle.down()
# 设置画笔颜色
turtle.color('red', 'pink')
# 开始填充颜色
turtle.begin_fill()
# 循环画半圆弧
turtle.left(45)
turtle.forward(300)
turtle.circle(150, 180)
turtle.left(180)
turtle.circle(150, 180)
turtle.forward(300)
# 结束填充颜色
turtle.end_fill()
# 写上表白话语
turtle.up()
turtle.goto(0, 50)
turtle.color('black', 'white')
turtle.write("我爱你", font=('Arial', 40, 'bold'), align="center")
# 循环闪烁三次
for i in range(3):
# 重新设置颜色
turtle.pencolor('red')
# 等待1秒钟
time.sleep(1)
# 重新设置颜色
turtle.pencolor('white')
# 等待1秒钟
time.sleep(1)
# 关闭画布
turtle.done()
```
运行代码之后,你就可以看到一个漂亮的爱心画出来了,同时还伴随着闪烁的效果以及表白话语。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)