白又白用Python制作了一个奇奇怪怪的月饼送给大家

1,029 阅读2分钟

我正在参加中秋创意投稿大赛,详情请看:中秋创意投稿大赛

前言

马上就要中秋节了,在外漂泊的各位小伙伴也没有时间能赶回家陪陪家人,但是出门在外,月饼还是要吃的呀,给掘金的每个小伙伴送上给种口味样式的月饼,白又白已经帮你端上餐桌了,各位大大请品尝!!!!
image.png

效果展示

image.png
image.png

工具使用

开发工具:pycharm
开发环境:python3.7, Windows10
使用工具包:turtle

学习思路解析

现在脑海里有月饼的基本形状
先准备画出月饼的花边,向日葵的波浪形
可以把这个图形分解成圆弧形状的,也圆心进行偏移
image.png
找到圆心,循环画出所有的形状,绘制出一个正圆
image.png

def huabian():
    goto(0,0)
    turtle.color("orange")
    for _ in range(20):
        turtle.right(18)
        turtle.begin_fill()
        turtle.forward(220)
        turtle.circle(40,180)
        turtle.goto(0,0)
        turtle.right(180)
        turtle.end_fill()

在给每个月饼添加上装饰的圆圈画圆的话相对简单
确定起点画圆圈就行
image.png

def yuan():
    turtle.color("#8fdb75")
    goto(0,-200)
    turtle.begin_fill()
    turtle.circle(200)
    turtle.end_fill()

颜色搭配稍稍有点奇怪,大家见谅,有画向日葵的即视感
image.png
在给月饼添加上内部的装饰,添加上小花边,看起来更有食欲哈!!
image.png
图形也是单一的图像进行循环拼接

def huabian():
    goto(0,0)
    turtle.color("orange")
    for _ in range(20):
        turtle.right(18)
        turtle.begin_fill()
        turtle.forward(220)
        turtle.circle(40,180)
        turtle.goto(0,0)
        turtle.right(180)
        turtle.end_fill()

最后添加上我们喜欢的口味,蛋黄啊,喜欢草莓的你还可以加上草莓,要是不爱吃甜的你还可以加上红烧肉,红烧排骨,糖醋鲤鱼口味的,白又白就比较喜欢榴莲口味的给它加上
image.png

image.png

简易源码分享

import turtle

def goto(x,y):
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()

def yuan():
    turtle.color("#8fdb75")
    goto(0,-200)
    turtle.begin_fill()
    turtle.circle(200)
    turtle.end_fill()

def huabian():
    goto(0,0)
    turtle.color("orange")
    for _ in range(20):
        turtle.right(18)
        turtle.begin_fill()
        turtle.forward(220)
        turtle.circle(40,180)
        turtle.goto(0,0)
        turtle.right(180)
        turtle.end_fill()

def neitu():
    turtle.color("#D1C185")
    goto(0,-25)
    for _ in range(12):
        turtle.begin_fill()
        turtle.circle(150,60)
        turtle.left(90)
        turtle.circle(150,60)
        turtle.end_fill()

def wirte():
    goto(-40,-20)
    turtle.color("orange")
    turtle.write('\n\n清馨\n榴莲',font=('Time',30,'bold'))
    turtle.done()

if __name__ == '__main__':
    turtle.speed(20)
    huabian()
    yuan()
    neitu()
    wirte()
turtle.done()

我是白又白i,一名喜欢分享知识的程序媛❤️

如果没有接触过编程这块的朋友看到这篇博客,发现不会编程或者想要学习的,可以直接留言+私我呀~【非常感谢你的点赞、收藏、关注、评论,一键四连支持】