Python生日祝福-美丽蛋糕+祝福语

呈现效果如下:

如果有用,给个点个小赞,谢谢b( ̄▽ ̄)d

import turtle as t
import time
import math as m
import random as r

# 设置画布
t.bgcolor('white')  # 设置背景色

# 开始绘制生日蛋糕
t.speed(2)
t.delay(0)


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.speed(10)
t.pensize(1)
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))  # todo 此处可以修改画完蛋糕以后显示的文字
t.pu()
t.goto(-220, -200)  # Adjust the Y coordinate to position the text below the cake
t.pencolor("#ffaaa0")  # Set the same color as "Happy Birthday"
t.pendown()
t.write("muamua 生日快乐!", font=("Curlz MT", 50))  # Use the same font and color
t.pu()
t.goto(-160, -300)  # Adjust the Y coordinate to position the text below the cake
t.pencolor("#ffaaa0")  # Set the same color as "Happy Birthday"
t.pendown()
t.write("I LOVE YOU!", font=("Curlz MT", 50))  # Use the same font and color
t.done()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值