用python代码turtle库画一个党徽
时间: 2024-06-09 07:09:08 浏览: 21
好的,以下是使用Python的turtle库画党徽的代码:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor("#DE2910")
# 画黄色的五角星
turtle.color("#FFDE00")
turtle.begin_fill()
for i in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
# 画红色的大圆
turtle.penup()
turtle.goto(0, -80)
turtle.pendown()
turtle.color("#FF0000")
turtle.begin_fill()
turtle.circle(80)
turtle.end_fill()
# 画黄色的小圆
turtle.penup()
turtle.goto(0, -60)
turtle.pendown()
turtle.color("#FFDE00")
turtle.begin_fill()
turtle.circle(60)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 保持窗口不关闭
turtle.done()
```
运行以上代码,即可在窗口中看到画好的党徽。效果如下:
![党徽](https://img-blog.csdnimg.cn/20210622180436703.png)
相关问题
用python的turtle库画一个爱心
好的,以下是用 Python 的 turtle 库画一个爱心的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(width=600, height=600)
turtle.bgcolor("white")
# 设置画笔颜色和粗细
turtle.color("red", "pink")
turtle.pensize(3)
# 移动画笔到起始点
turtle.up()
turtle.goto(0, -150)
turtle.down()
# 开始画爱心
turtle.begin_fill()
turtle.left(45)
turtle.forward(200)
turtle.circle(100, 180)
turtle.right(90)
turtle.circle(100, 180)
turtle.forward(200)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画布
turtle.done()
```
运行以上代码,即可在画布上看到一个粉色的爱心。
用python的turtle库画一个人脸
好的,以下是用 Python 的 turtle 库画一个人脸的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(600, 600)
turtle.bgcolor("#F0EAD6")
# 画圆形的脸
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.fillcolor("#F8E4C9")
turtle.begin_fill()
turtle.circle(200)
turtle.end_fill()
# 左眼
turtle.penup()
turtle.goto(-80, 80)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(-65, 100)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 右眼
turtle.penup()
turtle.goto(80, 80)
turtle.pendown()
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(95, 100)
turtle.pendown()
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 嘴巴
turtle.penup()
turtle.goto(-100, -40)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.circle(60, 180)
turtle.end_fill()
# 鼻子
turtle.penup()
turtle.goto(0, 40)
turtle.pendown()
turtle.fillcolor("#FFC0CB")
turtle.begin_fill()
turtle.circle(40)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 20)
turtle.pendown()
turtle.fillcolor("#FF69B4")
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 完成
turtle.hideturtle()
turtle.done()
```
运行以上代码,可以得到如下图所示的人脸:
![人脸](https://cdn.jsdelivr.net/gh/Yijiujiu/MarkdownPhotos//small/Python/Python-turtle-face.png)
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.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)
![](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)