代码如下:
import turtle
class OlympicTurtle(turtle.Turtle):
def __init__(self):
turtle.Turtle.__init__(self, shape="turtle")
screen = turtle.Screen()
screen.bgcolor("red")
self.pensize(3) # 设置画笔大小
self.speed(10) # 设置速度
self.hideturtle()
def wuxing(self,sizes):
for i in range(5):
self.forward(sizes)
self.right(180-180/5)
def draw_xingxing(self, x, y, color,sizes):
self.penup() # 抬起画笔
self.setposition(x, y) # 找到位置
self.pendown() # 画笔落下
self.color(color) # 设置颜色
self.begin_fill()
self.wuxing(sizes)
self.end_fill()
def draw_olympic_symbol(self):
circle_lst = [(-350,250, "yellow",100), (-200, 300, "yellow",30), (-150, 250, "yellow",30),
(-150, 200, "yellow",30), (-200, 150, "yellow",30)]
for x, y, color, sizes in circle_lst:
self.draw_xingxing(x, y, color,sizes)
if __name__ == "__main__":
t = OlympicTurtle()
t.draw_olympic_symbol()
turtle.hideturtle()
turtle.getscreen().mainloop()
效果图: