昆工月饼,Kuster专属

一.前言

比较早期的代码了,22年中秋节,想给月饼上的昆工图案拍个照,发现月饼居然没有图案。原来云南的滇式月饼就是没有这个图案的,来之前,吃的更多是广式月饼。于是画了这个昆工的月饼,Kuster专属。这个代码主要麻烦的点就是自己kust的标志,是用ps读入图片,一条线一条线地量参数画出来的(PS:太菜,只会这个方法)

二.效果展示

三.代码

from turtle import *
from math import *


def body(flower_num:'花瓣数量',flower_color1:'花瓣颜色',flower_color2:'花瓣上花纹的颜色',fill_color:'中间饼身颜色'):
    #画月饼的花瓣
    color(flower_color1,flower_color1)
    for i in range(flower_num):
        up()
        left(360/flower_num)
        fd(200)
        pd()
        begin_fill()
        circle(60)
        end_fill()
        pu()
        backward(200)
    #画花瓣的花纹
    color(flower_color2)
    pensize(5)
    for i in range(flower_num):
        up()
        left(360/flower_num)
        fd(190)
        pd()
        circle(60)
        pu()
        backward(190)
    #画饼身中间
    up()
    forward(200)
    left(90)
    pensize(8)
    color(flower_color2,fill_color)
    down()
    begin_fill()
    circle(200)
    end_fill()

def figure(x,y,angle):
    penup()
    goto(x, y)
    pendown()
    setheading(angle)
    forward(20)
    right(90)
    circle(-100, 20)

    penup()
    goto(x, y)
    pendown()
    setheading(angle)
    right(90)
    circle(-100, 30)
    left(90)
    forward(45)
    left(95)
    circle(190, 50)
    left(95)
    forward(45)
    left(90)
    circle(-100, 31)
    setheading(angle)
    forward(20)
    left(90)
    circle(100, 20)
    penup()
    home()

def write_font(text_content: "文本内容", text_color: "文本颜色", size: "文字大小"):
    color(text_color)
    for x in text_content:
        penup()
        goto(text_content[x])
        write(x, align='center', font=('simhei', size, 'bold'))
    penup()
    home()
    color('#F29407')



def kust(l,x,y):
    up()
    goto(x,y)
    pensize(1)
    color('#F29407','#F29407')
    #画第一个方块
    setheading(4)
    pd()
    begin_fill()
    l1=l*3/4
    forward(l1)
    seth(90)
    forward(l)
    seth(174)
    fd(l1)
    seth(270)
    l2=l+l1*(sin(radians(4))+sin(radians(6)))
    fd(l2)
    end_fill()

    # 最下层左边制造立体感
    pu()
    seth(180)
    fd(l1)
    seth(88)

    fd(l2*3/5)
    pd()
    for i in range(1,7):
        pensize(i/2)
        fd(l2*2/5/6)
    seth(6)
    for i in range(1,7):
        pensize((7-i)/2)
        fd(l1*4/5/6)
    pu()
    backward(l1*3/5)
    setheading(268)
    fd(l2)
    seth(0)
    fd(l1)



    #第一二个方块的间隙
    pu()
    setheading(4)
    forward(l1)
    ll1=l*6/10
    forward(ll1)

    #画第二个方块
    pd()
    begin_fill()
    fd(ll1)
    seth(90)
    fd(l)
    seth(174)
    fd(ll1)
    seth(270)
    l4 = l + ll1 * (sin(radians(4)) + sin(radians(6)))
    fd(l4)
    end_fill()



    #上第二层
    pu()
    backward(l4)
    pu()
    seth(174)
    fd(ll1/5)

    # 画二层第一个方块
    k12=2/3
    l_2=l*k12
    l1_2=l_2*3/4
    setheading(4)
    backward(l1_2)
    pd()
    begin_fill()
    forward(l1_2)
    seth(90)
    forward(l_2)
    seth(174)
    fd(l1_2)
    seth(270)
    l2_2 = l_2 + l1_2 * (sin(radians(4)) + sin(radians(6)))
    fd(l2_2)
    end_fill()

    # 第二层左边制造立体感
    pu()
    seth(180)
    fd(l1_2)
    seth(88)
    fd(l2_2 * 3 / 5)
    pd()
    for i in range(1,6):
        pensize(i/2)
        fd(l2_2 * 2 / 5/5)
    seth(6)
    for i in range(1,6):
        pensize((6-i)/2)
        fd(l1_2 * 4 / 5/5)
    pu()
    backward(l1_2 * 3 / 5)
    setheading(268)
    fd(l2_2)
    seth(0)
    fd(l1_2)

    # 第二层第一二个方块的间隙
    pu()
    setheading(4)
    forward(l1_2)
    ll1_2=l_2*6/10
    #回调距离
    l2_back=ll1_2*4/9
    #/6继续距离修正
    forward(ll1_2/6+ll1)

    # 画第二层第二个方块
    pd()
    begin_fill()
    fd(ll1_2)
    seth(90)
    fd(l_2)
    seth(174)
    fd(ll1_2)
    seth(270)
    l4_2 = l_2+ll1_2*(sin(radians(4)) + sin(radians(6)))
    fd(l4_2)
    end_fill()





    # 上第三层
    pu()
    backward(l4_2)
    pu()
    seth(174)
    fd(ll1_2/5)

    # 画三层第一个方块
    k23=4/5
    l_3=l_2*k23
    l1_3=l_2*3/4
    setheading(4)
    backward(l1_3)
    pd()
    begin_fill()
    forward(l1_3*9/10)
    seth(90)
    forward(l_3*5/4)
    seth(174)
    fd(l1_3*9/10)
    seth(270)
    l2_3=l_3*5/4+l1_3*(sin(radians(4)) + sin(radians(6)))
    fd(l2_3)
    end_fill()

    # 第三层左边制造立体感
    pu()
    seth(180)
    fd(l1_3)
    seth(88)
    fd(l2_3 * 3 / 5)
    pd()
    for i in range(1,5):
        pensize(i/2)
        fd(l2_2 * 2 / 5/4)
    seth(6)
    for i in range(1,5):
        pensize((5-i)/2)
        fd(l1_3 * 4 / 5/4)
    pu()
    backward(l1_3 * 3 / 5)
    setheading(268)
    fd(l2_3)
    seth(0)
    fd(l1_3)



    # 返回第二层
    pu()
    seth(4)
    forward(l1_3)
    seth(354)
    fd(ll1_2/5)
    seth(270)
    fd(l4_2)

    # 返回第一层
    pu()
    seth(4)
    backward(ll1_2 / 6 + ll1)
    seth(354)
    fd(ll1 / 5)
    seth(270)
    fd(l4)


    #画第二三个方块的间隙
    up()
    seth(4)
    fd(ll1)
    ll2=l*25/40
    fd(ll2)

    #间隙修正
    backward(ll2/3)


    #画第三个方块
    pd()
    begin_fill()
    fd(ll2)
    seth(90)
    fd(l)
    seth(174)
    fd(ll2)
    seth(270)
    l4 = l + ll2 * (sin(radians(4)) + sin(radians(6)))
    fd(l4)
    end_fill()


# 花纹颜色 #F29407
# 花瓣颜色 #F8B41A
# 饼身中间颜色,比外边花瓣亮一点点 #F8B51D
speed(0)
body(18,'#F8B41A','#F29407','#F8B51D')
figure(6, 110, 90)
figure(-110, 6, 180)
figure(-6, -110, 270)
figure(110, -6, 360)
text_content = {'昆': (-100, 70), '工': (100, 70), '定': (100, -120), '限': (-98, -125)}
write_font(text_content, '#FC932B', 40)
text_content2 = {'千': (-60,-70), '里': ( -30,-70), '共': (0,-70), '婵': (30,-70), '娟': (60, -70),'但': (-60,60), '愿': ( -30,60), '人': (0,60), '长': (30,60), '久': (60, 60)}  # 圆字坐标最后向下微调了一下
write_font(text_content2, '#F29407',15)
kust(30,-40,-35)
hideturtle()#可以用ht简写
done()

四.后言

        很久以前学习时的代码,格式不太优美,哈哈。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

_小豫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值