• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

白又白i

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

白又白用Python制作了一个奇奇怪怪的月饼送给大家,祝中秋节快乐

前言

马上就要中秋节了,在外漂泊的各位小伙伴也没有时间能赶回家陪陪家人,但是出门在外,月饼还是要吃的呀,给掘金的每个小伙伴送上给种口味样式的月饼,白又白已经帮你端上餐桌了,各位大大请品尝!!!!
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,一名喜欢分享知识的程序媛❤️

在这里我给大家整理了些学习资料以及学习路线,可以让你避免踩雷和少走弯路,喜欢吗,喜欢的就关注我的公众号:白又白学Python

posted on 2021-09-05 14:57  白又白i  阅读(332)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3