python法国国旗
时间: 2024-01-04 13:20:07 浏览: 112
以下是使用Python绘制法国国旗的代码示例:
```python
import turtle
def draw_rectangle(x, y, width, height, color):
turtle.penup()
turtle.goto(x, y)
turtle.fillcolor(color)
turtle.begin_fill()
for _ in range(2):
turtle.forward(width)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.end_fill()
def draw_france_flag(x, y, width, height):
draw_rectangle(x, y, width, height, "blue")
draw_rectangle(x + width/3, y, width/3, height, "white")
draw_rectangle(x + 2*width/3, y, width/3, height, "red")
# 设置画布大小
turtle.setup(800, 600)
# 设置画笔速度
turtle.speed(3)
# 隐藏画笔
turtle.hideturtle()
# 绘制法国国旗
draw_france_flag(-200, 100, 400, 200)
# 显示绘图窗口
turtle.done()
```
阅读全文