使用Python完成一套優美的中秋節程式碼

專注的阿熊發表於2022-09-13

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.com math.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()


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2914383/,如需轉載,請註明出處,否則將追究法律責任。

相關文章