【Python】中秋月饼

运行结果:

 代码部分:

import turtle as turtle
import math

turtle.hideturtle()
turtle.speed(20)


class MoonCake(object):
    def __init__(self, name: str):
        self.name = name

    def external_pattern(self, r: int, n: int):
        turtle.penup()
        turtle.goto(0, -r)
        turtle.pendown()

        round_r = math.sin(math.pi / n) * r

        for i in range(n):
            turtle.penup()
            turtle.home()
            turtle.seth((360 / n) * i)
            turtle.fd(r)
            turtle.left((360 / n) * 0.5)
            turtle.pendown()
            turtle.color('#F0BE7C')
            turtle.begin_fill()
            turtle.circle(round_r, 180)
            turtle.end_fill()

    def internal_pattern(self):
        turtle.color('#F5E16F')
        turtle.goto(0, -180)
        for _ in range(8):
            turtle.begin_fill()
            turtle.circle(60, 120)
            turtle.left(180)
            turtle.circle(60, 120)
            turtle.end_fill()

    def draw_circle(self, r: int, pensize: int, color1: str, color2: str):
        turtle.penup()
        turtle.goto(0, -r)
        turtle.seth(0)
        turtle.pendown()
        turtle.pensize(pensize, )
        turtle.color(color1, color2)
        turtle.begin_fill()
        turtle.circle(r)
        turtle.end_fill()

    #
    def draw(self):
        turtle.title("祝大家中秋快乐!!!")
        self.external_pattern(200, 12)
        self.draw_circle(200, 10, '#F0BE7C', '#F0BE7C')
        self.draw_circle(180, 10, '#F8CD32', '#FBA92D')
        self.internal_pattern()
        self.write_text(-105, -60)
        turtle.done()

    def write_text(self, x: float, y: float):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.color('Gold')
        turtle.write(self.name, font=("华文隶书", 60, "bold"))


if __name__ == '__main__':
    MoonCake('中秋快乐').draw()

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈 迷学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值