python用turtle画国徽
时间: 2023-07-12 17:57:30 浏览: 225
好的,下面是使用Python中的turtle库画中国国徽的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor('red')
# 画黄色的五角星
turtle.penup()
turtle.goto(-150, 100)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(300)
turtle.right(144)
turtle.end_fill()
# 画大圆
turtle.penup()
turtle.goto(0, -120)
turtle.pendown()
turtle.circle(120)
# 画小圆
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画四个小五角星
turtle.penup()
turtle.goto(-40, 20)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(40, 20)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-70, -70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 显示画板
turtle.done()
```
运行以上代码,即可得到中国国徽的图形。
阅读全文