分类: Python/Ruby
2022-09-13 11:57:59
class Mooncake2:
def __init__(self,x_distante,y_distante,name):
turtle.home()
turtle.setup(1100, 600)
# 月饼最外层边数
self.bian = 8
self.ext_r = 100
self.x_distante= x_distante
self.y_distante = y_distante
self.name = name
self.yuebing_zhong()
def yuebing_zhong(self):
turtle.color("#FFD700")
round_r = 跟单网gendan5.commath.sin(math.pi / self.bian) * self.ext_r # 月饼花圈的半径
# 从水平x轴出发
for i in range(self.bian):
turtle.home()
# print(turtle.xcor(), turtle.ycor())
turtle.penup() # 画笔抬起
turtle.goto(self.x_distante,0) # 恢复为初始位置
turtle.seth((360 / self.bian) * i) # 改变画笔方向,但不前进
turtle.fd(self.ext_r)
turtle.left((360 / self.bian) * 0.8) # 画笔左转一定的角度
turtle.color('#FF8C00') # 设置颜色
turtle.begin_fill() # 开始填充颜色
turtle.circle(round_r, extent=180)
turtle.end_fill()
self.inner_circle()
def inner_circle(self):
turtle.penup()
turtle.goto(0+self.x_distante,100+self.y_distante)
turtle.seth(0)
turtle.pendown()
turtle.color('#F0BE7C')
turtle.begin_fill()
turtle.circle(-self.ext_r)
turtle.end_fill()
self.Moon_inner()
def Moon_inner(self):
turtle.color('#FFD700')
turtle.goto(0+self.x_distante,-self.ext_r-self.y_distante)
turtle.left(0)
turtle.begin_fill()
turtle.circle(100,steps=6)
turtle.end_fill()
self.TP()
def TP(self):
self.pingan()
def pingan(self):
turtle.penup()
turtle.goto(-30+self.x_distante,0+self.y_distante)
turtle.color('#FF8C00')
turtle.write("平", font=("楷体", 50, "bold"))
turtle.goto(-30+self.x_distante, -60+self.y_distante)
turtle.write("安", font=("楷体", 50, "bold"))
turtle.ht()