Python代码,用海龟绘图制作奥运五环
时间: 2024-05-24 10:05:50 浏览: 80
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 创建五个海龟
blue = turtle.Turtle()
yellow = turtle.Turtle()
black = turtle.Turtle()
green = turtle.Turtle()
red = turtle.Turtle()
# 设置海龟的颜色
blue.color("blue")
yellow.color("yellow")
black.color("black")
green.color("green")
red.color("red")
# 设置海龟的起始位置和方向
blue.penup()
yellow.penup()
black.penup()
green.penup()
red.penup()
blue.goto(-150, -50)
yellow.goto(0, -50)
black.goto(150, -50)
green.goto(-75, -100)
red.goto(75, -100)
blue.pendown()
yellow.pendown()
black.pendown()
green.pendown()
red.pendown()
blue.left(60)
yellow.left(60)
black.left(60)
green.left(60)
red.left(60)
# 绘制五环
for i in range(60):
blue.forward(5)
blue.right(6)
yellow.forward(5)
yellow.right(6)
black.forward(5)
black.right(6)
green.forward(5)
green.right(6)
red.forward(5)
red.right(6)
# 隐藏海龟
blue.hideturtle()
yellow.hideturtle()
black.hideturtle()
green.hideturtle()
red.hideturtle()
# 程序结束后不关闭窗口
turtle.done()
阅读全文