shield


import turtle
import math

t = turtle.Turtle()
print(type(t))
# 0最快, 9最慢
t.speed(5)
# 将画笔定位封装成函数使用,就能有效去除重复代码
def setpen(x, y):
t.penup()
t.goto(x, y)
t.pendown()
# Set the orientation of the turtle to to_angle.
t.setheading(0)


def circle(x, y, r, color):
"""
起点 x,y 半径r, 颜色的 ,36边形,多边形就是圆
:param x:
:param y:
:param r:
:param color:
:return:
"""
n = 36 # 36多边形就是圆
angle = 360 / n
c = 2 * math.pi * r
# 36多边形边长就是
lenth = c / 36
start_x = x - lenth / 2
start_y = y + r
setpen(start_x, start_y)
t.pencolor(color)
t.fillcolor(color)
t.begin_fill()

for i in range(n):
t.forward(lenth)
t.right(angle)

t.end_fill()


def five_star(l):

setpen(0, 0)
# 五角星第一笔的角度是162度
t.setheading(162)
# 半径是150的地方
t.forward(150)
# 调整到水平
t.setheading(0)

t.fillcolor('WhiteSmoke')

t.begin_fill()

t.hideturtle()

t.penup()

for i in range(5):

t.forward(l)

t.right(144)

t.end_fill()



circle(0, 0, 300, "red")
circle(0, 0, 250, "white")
circle(0, 0, 200, "red")
circle(0, 0, 150, "blue")

# 五角星的边长是284
five_star(284)


turtle.done()
Standard