pythonturtle画操场加国旗
时间: 2023-06-26 19:08:08 浏览: 161
使用Python的turtle模块画国旗
好的,以下是代码:
```python
import turtle
# 设置画布大小和背景色
turtle.setup(800, 600)
turtle.bgcolor("#1E90FF")
# 画操场
turtle.speed(10)
turtle.penup()
turtle.goto(-400, -200)
turtle.pendown()
turtle.color("green")
turtle.begin_fill()
turtle.forward(800)
turtle.left(90)
turtle.forward(400)
turtle.left(90)
turtle.forward(800)
turtle.left(90)
turtle.forward(400)
turtle.end_fill()
# 画国旗
turtle.penup()
turtle.goto(-280, 100)
turtle.pendown()
turtle.color("red")
turtle.begin_fill()
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(280)
turtle.right(90)
turtle.forward(200)
turtle.end_fill()
# 画小星星
turtle.penup()
turtle.goto(-250, 50)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
turtle.right(162)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-200, 100)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
turtle.right(162)
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
turtle.hideturtle()
turtle.done()
```
运行代码后,会弹出一个窗口,里面画出了操场和国旗。如下图所示:
![image](https://user-images.githubusercontent.com/26738575/120219304-399c9000-c28b-11eb-8e5d-8a067b7b4ce8.png)
阅读全文