用Python制作生日蛋糕、生日快乐,生日祝福代码

您所在的位置:网站首页 python生日快乐代码 用Python制作生日蛋糕、生日快乐,生日祝福代码

用Python制作生日蛋糕、生日快乐,生日祝福代码

2023-08-29 02:29| 来源: 网络整理| 查看: 265

用Python画一个生日蛋糕并写上生日祝福对象及生日祝福语。画一个双层蛋糕并点上蜡烛。代码运行时间较长,请静待惊喜出现,代码运行截图:

在这里插入图片描述

点击免费领取《CSDN大礼包》:

最新全套【Python入门到进阶资料 & 实战源码 & 安装工具】https://mp.weixin.qq.com/s/9IuSexhanYZ1TMAF1MZIhw

完整程序代码:

import turtle as t import math as m import random as r def drawX(a, i): angle = m.radians(i) return a * m.cos(angle) def drawY(b, i): angle = m.radians(i) return b * m.sin(angle) # 设置背景颜色,窗口位置以及大小 t.bgcolor("#d3dae8") t.setup(width=900, height=600, startx=0, starty=0) t.title("好友,祝你生日快乐!") t.speed(2) t.penup() t.goto(150, 0) t.pendown() # 1 t.pencolor("white") t.begin_fill() for i in range(360): x = drawX(150, i) y = drawY(60, i) t.goto(x, y) t.fillcolor("#fef5f7") t.end_fill() # 2 t.begin_fill() for i in range(180): x = drawX(150, -i) y = drawY(70, -i) t.goto(x, y) for i in range(180, 360): x = drawX(150, i) y = drawY(60, i) t.goto(x, y) t.fillcolor("#f2d7dd") t.end_fill() # 3 t.pu() t.goto(120, 0) t.pd() t.begin_fill() for i in range(360): x = drawX(120, i) y = drawY(48, i) t.goto(x, y) t.fillcolor("#cbd9f9") t.end_fill() # 4 t.begin_fill() t.pencolor("#fee48c") for i in range(540): x = drawX(120, i) y = drawY(48, i) + 70 t.goto(x, y) t.goto(-120, 0) t.fillcolor("#cbd9f9") t.end_fill() # 5 t.pu() t.goto(120, 70) t.pd() t.pencolor("#fff0f3") t.begin_fill() for i in range(360): x = drawX(120, i) y = drawY(48, i) + 70 t.goto(x, y) t.fillcolor("#fff0f3") t.end_fill() # 6 t.pu() t.goto(110, 70) t.pd() t.pencolor("#fff9fb") t.begin_fill() for i in range(360): x = drawX(110, i) y = drawY(44, i) + 70 t.goto(x, y) t.fillcolor("#fff9fb") t.end_fill() # 7 t.pu() t.goto(120, 0) t.pd() t.begin_fill() t.pencolor("#ffa79d") for i in range(180): x = drawX(120, -i) y = drawY(48, -i) + 10 t.goto(x, y) t.goto(-120, 0) for i in range(180, 360): x = drawX(120, i) y = drawY(48, i) t.goto(x, y) t.fillcolor("#ffa79d") t.end_fill() # 8 t.pu() t.goto(120, 70) t.pd() t.begin_fill() t.pensize(4) t.pencolor("#fff0f3") for i in range(1800): x = drawX(120, 0.1 * i) y = drawY(-18, i) + 10 t.goto(x, y) t.goto(-120, 70) t.pensize(1) for i in range(180, 360): x = drawX(120, i) y = drawY(48, i) + 70 t.goto(x, y) t.fillcolor("#fff0f3") t.end_fill() # 9 t.pu() t.goto(80, 70) t.pd() t.begin_fill() t.pencolor("#6f3732") t.goto(80, 120) for i in range(180): x = drawX(80, i) y = drawY(32, i) + 120 t.goto(x, y) t.goto(-80, 70) for i in range(180, 360): x = drawX(80, i) y = drawY(32, i) + 70 t.goto(x, y) t.fillcolor("#6f3732") t.end_fill() # 10 t.pu() t.goto(80, 120) t.pd() t.pencolor("#ffaaa0") t.begin_fill() for i in range(360): x = drawX(80, i) y = drawY(32, i) + 120 t.goto(x, y) t.fillcolor("#ffaaa0") t.end_fill() # 11 t.pu() t.goto(70, 120) t.pd() t.pencolor("#ffc3be") t.begin_fill() for i in range(360): x = drawX(70, i) y = drawY(28, i) + 120 t.goto(x, y) t.fillcolor("#ffc3be") t.end_fill() # 12 t.pu() t.goto(80, 120) t.pd() t.begin_fill() t.pensize(3) t.pencolor("#ffaaa0") for i in range(1800): x = drawX(80, 0.1 * i) y = drawY(-12, i) + 80 t.goto(x, y) t.goto(-80, 120) t.pensize(1) for i in range(180, 360): x = drawX(80, i) y = drawY(32, i) + 120 t.goto(x, y) t.fillcolor("#ffaaa0") t.end_fill() # 13 t.pu() t.goto(64, 120) t.pd() t.pencolor("#b1c9e9") t.begin_fill() for i in range(360): x = drawX(4, i) + 60 y = drawY(1, i) + 120 t.goto(x, y) t.goto(64, 170) for i in range(540): x = drawX(4, i) + 60 y = drawY(1, i) + 170 t.goto(x, y) t.goto(56, 120) t.fillcolor("#b1c9e9") t.end_fill() t.pencolor("white") t.pensize(2) for i in range(1, 6): t.goto(64, 120 + 10 * i) t.pu() t.goto(56, 120 + 10 * i) t.pd() t.pu() t.goto(60, 170) t.pd() t.goto(60, 180) t.pensize(1) # t.pu() t.goto(64, 190) t.pd() t.pencolor("#f1add1") t.begin_fill() for i in range(360): x = drawX(4, i) + 60 y = drawY(10, i) + 190 t.goto(x, y) t.fillcolor("#f1add1") t.end_fill() # 14 t.pu() t.goto(-56, 120) t.pd() t.pencolor("#b1c9e9") t.begin_fill() for i in range(360): x = drawX(4, i) - 60 y = drawY(1, i) + 120 t.goto(x, y) t.goto(-56, 170) for i in range(540): x = drawX(4, i) - 60 y = drawY(1, i) + 170 t.goto(x, y) t.goto(-64, 120) t.fillcolor("#b1c9e9") t.end_fill() t.pencolor("white") t.pensize(2) for i in range(1, 6): t.goto(-56, 120 + 10 * i) t.pu() t.goto(-64, 120 + 10 * i) t.pd() t.pu() t.goto(-60, 170) t.pd() t.goto(-60, 180) t.pensize(1) # t.pu() t.goto(-56, 190) t.pd() t.pencolor("#f1add1") t.begin_fill() for i in range(360): x = drawX(4, i) - 60 y = drawY(10, i) + 190 t.goto(x, y) t.fillcolor("#f1add1") t.end_fill() # 15 t.pu() t.goto(0, 130) t.pd() t.pencolor("#b1c9e9") t.begin_fill() for i in range(360): x = drawX(4, i) y = drawY(1, i) + 130 t.goto(x, y) t.goto(4, 180) for i in range(540): x = drawX(4, i) y = drawY(1, i) + 180 t.goto(x, y) t.goto(-4, 130) t.fillcolor("#b1c9e9") t.end_fill() t.pencolor("white") t.pensize(2) for i in range(1, 6): t.goto(4, 130 + 10 * i) t.pu() t.goto(-4, 130 + 10 * i) t.pd() t.pu() t.goto(0, 180) t.pd() t.goto(0, 190) t.pensize(1) # t.pu() t.goto(4, 200) t.pd() t.pencolor("#f1add1") t.begin_fill() for i in range(360): x = drawX(4, i) y = drawY(10, i) + 200 t.goto(x, y) t.fillcolor("#f1add1") t.end_fill() # 16 t.pu() t.goto(30, 110) t.pd() t.pencolor("#b1c9e9") t.begin_fill() for i in range(360): x = drawX(4, i) + 30 y = drawY(1, i) + 110 t.goto(x, y) t.goto(34, 160) for i in range(540): x = drawX(4, i) + 30 y = drawY(1, i) + 160 t.goto(x, y) t.goto(26, 110) t.fillcolor("#b1c9e9") t.end_fill() t.pencolor("white") t.pensize(2) for i in range(1, 6): t.goto(34, 110 + 10 * i) t.pu() t.goto(26, 110 + 10 * i) t.pd() t.pu() t.goto(30, 160) t.pd() t.goto(30, 170) t.pensize(1) # t.pu() t.goto(34, 180) t.pd() t.pencolor("#f1add1") t.begin_fill() for i in range(360): x = drawX(4, i) + 30 y = drawY(10, i) + 180 t.goto(x, y) t.fillcolor("#f1add1") t.end_fill() # 17 t.pu() t.goto(-30, 110) t.pd() t.pencolor("#b1c9e9") t.begin_fill() for i in range(360): x = drawX(4, i) - 30 y = drawY(1, i) + 110 t.goto(x, y) t.goto(-26, 160) for i in range(540): x = drawX(4, i) - 30 y = drawY(1, i) + 160 t.goto(x, y) t.goto(-34, 110) t.fillcolor("#b1c9e9") t.end_fill() t.pencolor("white") t.pensize(2) for i in range(1, 6): t.goto(-26, 110 + 10 * i) t.pu() t.goto(-34, 110 + 10 * i) t.pd() t.pu() t.goto(-30, 160) t.pd() t.goto(-30, 170) t.pensize(1) # t.pu() t.goto(-26, 180) t.pd() t.pencolor("#f1add1") t.begin_fill() for i in range(360): x = drawX(4, i) - 30 y = drawY(10, i) + 180 t.goto(x, y) t.fillcolor("#f1add1") t.end_fill() ###随机 color = ["#e28cb9", "#805a8c", "#eaa989", "#6e90b7", "#b8b68f", "#e174b5", "#cf737c", "#7c8782"] for i in range(80): t.pu() x = r.randint(-120, 120) y = r.randint(-25, 30) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(40): t.pu() x = r.randint(-90, 90) y = r.randint(-35, 10) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(40): t.pu() x = r.randint(-80, 80) y = r.randint(60, 90) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(30): t.pu() x = r.randint(-50, 50) y = r.randint(45, 70) t.goto(x, y) t.pd() t.dot(r.randint(2, 5), color[r.randint(0, 7)]) for i in range(50): t.pu() x = r.randint(-500, 500) y = r.randint(120, 300) t.goto(x, y) t.pd() t.dot(r.randint(3, 5), color[r.randint(0, 7)]) t.seth(90) t.pu() t.goto(0, 0) t.fd(210) t.left(90) t.fd(170) t.pd() t.write("Happy Birthday", font=("Curlz MT", 50)) t.color('blue') t.penup() t.goto(-400, 210) t.pendown() t.write('致:好友友 ', font=('楷体', 32, 'bold')) t.color('red') t.penup() t.goto(-300, 50) t.pendown() t.write('祝 你 生 日 快 乐!前 程 似 锦!', font=('楷体', 30, 'bold')) t.color('blue') t.penup() t.goto(100, -220) t.pendown() t.write('————Python代码大全', font=('楷体', 20, 'bold')) t.done() 最后,为大家准备一份python入门学习资料

如果你也喜欢编程,想通过学习Python转行、做副业或者提升工作效率,我也为大家整理了一份【最新全套Python学习资料】一定对你有用!

对于0基础小白入门:

如果你是零基础小白,想快速入门Python是可以考虑的!

1、学习时间相对较短,学习内容更全面更集中

2、可以找到适合自己的学习方案

这份资料包含:Python安装包+激活码、Python web开发,Python爬虫,Python数据分析,人工智能、机器学习等教程,带你从零开始系统性的学好Python!

点击免费领取《CSDN大礼包》:

最新全套【Python入门到进阶资料 & 实战源码 & 安装工具】https://mp.weixin.qq.com/s/9IuSexhanYZ1TMAF1MZIhw

一、Python所有方向的学习路线

Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。

二、Python课程视频

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。

img

三、全套PDF电子书

书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。

img

四、清华编程大佬出品《漫画看学Python》

用通俗易懂的漫画,来教你学习Python,让你更容易记住,并且不会枯燥乏味。

img

五、Python实战案例

光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

img

六、互联网企业面试真题

我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

img

这份完整版的Python全套学习资料已经上传至CSDN官方,朋友们如果需要可以点击下方链接费获取【保证100%免费】

点击免费领取《CSDN大礼包》:

最新全套【Python入门到进阶资料 & 实战源码 & 安装工具】https://mp.weixin.qq.com/s/9IuSexhanYZ1TMAF1MZIhw

以上全套资料已经为大家打包准备好了,希望对正在学习Python的你有所帮助!

如果你觉得这篇文章有帮助,可以点个赞呀~

我会坚持每天更新Python相关干货,分享自己的学习经验帮助想学习Python的朋友们少走弯路!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3