用Python画一个生日蛋糕并写上生日祝福对象及生日祝福语。画一个双层蛋糕并点上蜡烛。代码运行时间较长,请静待惊喜出现,代码运行截图:
完整程序代码:
干货主要有:
① 多本 Python 电子书(和经典的书籍)应该有
② Python标准库资料(最全中文版)
③ 项目源码(四五十个有趣且可靠的练手项目及源码)
④ Python基础入门、爬虫、网络开发、大数据分析方面的视频(适合小白学习)
⑤ Python学习路线图(告别不入流的学习)
私信小编即可获取大量Python学习资源
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=, height=, startx=0, starty=0)
t.title("好友,祝你生日快乐!")
t.speed(2)
t.penup()
t.goto, 0)
t.pendown()
# 1
t.pencolor("white")
t.begin_fill()
for i in range):
x = drawX, i)
y = drawY(, i)
t.goto(x, y)
t.fillcolor("#fef5f7")
t.end_fill()
# 2
t.begin_fill()
for i in range):
x = drawX, -i)
y = drawY(, -i)
t.goto(x, y)
for i in range, ):
x = drawX, i)
y = drawY(, i)
t.goto(x, y)
t.fillcolor("#f2d7dd")
t.end_fill()
# 3
t.pu()
t.goto, 0)
t.pd()
t.begin_fill()
for i in range):
x = drawX, i)
y = drawY(, i)
t.goto(x, y)
t.fillcolor("#cbd9f9")
t.end_fill()
# 4
t.begin_fill()
t.pencolor("#fee48c")
for i in range):
x = drawX, i)
y = drawY(, i) +
t.goto(x, y)
t.goto(-, 0)
t.fillcolor("#cbd9f9")
t.end_fill()
# 5
t.pu()
t.goto, )
t.pd()
t.pencolor("#fff0f3")
t.begin_fill()
for i in range):
x = drawX, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#fff0f3")
t.end_fill()
# 6
t.pu()
t.goto, )
t.pd()
t.pencolor("#fff9fb")
t.begin_fill()
for i in range):
x = drawX, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#fff9fb")
t.end_fill()
# 7
t.pu()
t.goto, 0)
t.pd()
t.begin_fill()
t.pencolor("#ffa79d")
for i in range):
x = drawX, -i)
y = drawY(, -i) +
t.goto(x, y)
t.goto(-, 0)
for i in range, ):
x = drawX, i)
y = drawY(, i)
t.goto(x, y)
t.fillcolor("#ffa79d")
t.end_fill()
# 8
t.pu()
t.goto, )
t.pd()
t.begin_fill()
t.pensize(4)
t.pencolor("#fff0f3")
for i in range):
x = drawX, * i)
y = drawY(-, i) +
t.goto(x, y)
t.goto(-, )
t.pensize(1)
for i in range, ):
x = drawX, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#fff0f3")
t.end_fill()
# 9
t.pu()
t.goto(, )
t.pd()
t.begin_fill()
t.pencolor("#6f3732")
t.goto(, )
for i in range):
x = drawX(, i)
y = drawY(, i) +
t.goto(x, y)
t.goto(-, )
for i in range, ):
x = drawX(, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#6f3732")
t.end_fill()
#
t.pu()
t.goto(, )
t.pd()
t.pencolor("#ffaaa0")
t.begin_fill()
for i in range):
x = drawX(, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#ffaaa0")
t.end_fill()
#
t.pu()
t.goto(, )
t.pd()
t.pencolor("#ffc3be")
t.begin_fill()
for i in range):
x = drawX(, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#ffc3be")
t.end_fill()
#
t.pu()
t.goto(, )
t.pd()
t.begin_fill()
t.pensize(3)
t.pencolor("#ffaaa0")
for i in range):
x = drawX(, * i)
y = drawY(-, i) +
t.goto(x, y)
t.goto(-, )
t.pensize(1)
for i in range, ):
x = drawX(, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#ffaaa0")
t.end_fill()
#
t.pu()
t.goto(, )
t.pd()
t.pencolor("#b1c9e9")
t.begin_fill()
for i in range):
x = drawX(4, i) +
y = drawY(1, i) +
t.goto(x, y)
t.goto(, )
for i in range):
x = drawX(4, i) +
y = drawY(1, i) +
t.goto(x, y)
t.goto(, )
t.fillcolor("#b1c9e9")
t.end_fill()
t.pencolor("white")
t.pensize(2)
for i in range(1, 6):
t.goto(, + * i)
t.pu()
t.goto(, + * i)
t.pd()
t.pu()
t.goto(, )
t.pd()
t.goto(, )
t.pensize(1)
#
t.pu()
t.goto(, )
t.pd()
t.pencolor("#f1add1")
t.begin_fill()
for i in range):
x = drawX(4, i) +
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#f1add1")
t.end_fill()
#
t.pu()
t.goto(-, )
t.pd()
t.pencolor("#b1c9e9")
t.begin_fill()
for i in range):
x = drawX(4, i) -
y = drawY(1, i) +
t.goto(x, y)
t.goto(-, )
for i in range):
x = drawX(4, i) -
y = drawY(1, i) +
t.goto(x, y)
t.goto(-, )
t.fillcolor("#b1c9e9")
t.end_fill()
t.pencolor("white")
t.pensize(2)
for i in range(1, 6):
t.goto(-, + * i)
t.pu()
t.goto(-, + * i)
t.pd()
t.pu()
t.goto(-, )
t.pd()
t.goto(-, )
t.pensize(1)
#
t.pu()
t.goto(-, )
t.pd()
t.pencolor("#f1add1")
t.begin_fill()
for i in range):
x = drawX(4, i) -
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#f1add1")
t.end_fill()
#
t.pu()
t.goto(0, )
t.pd()
t.pencolor("#b1c9e9")
t.begin_fill()
for i in range):
x = drawX(4, i)
y = drawY(1, i) +
t.goto(x, y)
t.goto(4, )
for i in range):
x = drawX(4, i)
y = drawY(1, i) +
t.goto(x, y)
t.goto(-4, )
t.fillcolor("#b1c9e9")
t.end_fill()
t.pencolor("white")
t.pensize(2)
for i in range(1, 6):
t.goto(4, + * i)
t.pu()
t.goto(-4, + * i)
t.pd()
t.pu()
t.goto(0, )
t.pd()
t.goto(0, )
t.pensize(1)
#
t.pu()
t.goto(4, )
t.pd()
t.pencolor("#f1add1")
t.begin_fill()
for i in range):
x = drawX(4, i)
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#f1add1")
t.end_fill()
#
t.pu()
t.goto(, )
t.pd()
t.pencolor("#b1c9e9")
t.begin_fill()
for i in range):
x = drawX(4, i) +
y = drawY(1, i) +
t.goto(x, y)
t.goto(, )
for i in range):
x = drawX(4, i) +
y = drawY(1, i) +
t.goto(x, y)
t.goto(, )
t.fillcolor("#b1c9e9")
t.end_fill()
t.pencolor("white")
t.pensize(2)
for i in range(1, 6):
t.goto(, + * i)
t.pu()
t.goto(, + * i)
t.pd()
t.pu()
t.goto(, )
t.pd()
t.goto(, )
t.pensize(1)
#
t.pu()
t.goto(, )
t.pd()
t.pencolor("#f1add1")
t.begin_fill()
for i in range):
x = drawX(4, i) +
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#f1add1")
t.end_fill()
#
t.pu()
t.goto(-, )
t.pd()
t.pencolor("#b1c9e9")
t.begin_fill()
for i in range):
x = drawX(4, i) -
y = drawY(1, i) +
t.goto(x, y)
t.goto(-, )
for i in range):
x = drawX(4, i) -
y = drawY(1, i) +
t.goto(x, y)
t.goto(-, )
t.fillcolor("#b1c9e9")
t.end_fill()
t.pencolor("white")
t.pensize(2)
for i in range(1, 6):
t.goto(-, + * i)
t.pu()
t.goto(-, + * i)
t.pd()
t.pu()
t.goto(-, )
t.pd()
t.goto(-, )
t.pensize(1)
#
t.pu()
t.goto(-, )
t.pd()
t.pencolor("#f1add1")
t.begin_fill()
for i in range):
x = drawX(4, i) -
y = drawY(, i) +
t.goto(x, y)
t.fillcolor("#f1add1")
t.end_fill()
###随机
color = ["#e28cb9", "#805a8c", "#eaa989", "#6e90b7", "#b8b68f", "#e174b5", "#cf737c", "#7c8782"]
for i in range():
t.pu()
x = r.randint(-, )
y = r.randint(-, )
t.goto(x, y)
t.pd()
t.dot(r.randint(2, 5), color[r.randint(0, 7)])
for i in range():
t.pu()
x = r.randint(-, )
y = r.randint(-, )
t.goto(x, y)
t.pd()
t.dot(r.randint(2, 5), color[r.randint(0, 7)])
for i in range():
t.pu()
x = r.randint(-, )
y = r.randint(, )
t.goto(x, y)
t.pd()
t.dot(r.randint(2, 5), color[r.randint(0, 7)])
for i in range():
t.pu()
x = r.randint(-, )
y = r.randint(, )
t.goto(x, y)
t.pd()
t.dot(r.randint(2, 5), color[r.randint(0, 7)])
for i in range():
t.pu()
x = r.randint(-, )
y = r.randint, )
t.goto(x, y)
t.pd()
t.dot(r.randint(3, 5), color[r.randint(0, 7)])
t.seth()
t.pu()
t.goto(0, 0)
t.fd)
t.left()
t.fd)
t.pd()
t.write("Happy Birthday", font=("Curlz MT", ))
t.color('blue')
t.penup()
t.goto(-, )
t.pendown()
t.write('致:好友友 ', font=('楷体', , 'bold'))
t.color('red')
t.penup()
t.goto(-, )
t.pendown()
t.write('祝 你 生 日 快 乐!前 程 似 锦!', font=('楷体', , 'bold'))
t.color('blue')
t.penup()
t.goto, -)
t.pendown()
t.write('————Python代码大全', font=('楷体', , 'bold'))
t.done()