python画蛋糕_python+turtle制作一个生日蛋糕

话不多说,直接上代码

import turtle as t

import time

t.fillcolor("#FFFFCC")

t.begin_fill()

t.penup()

t.goto(-200,100) #初始位置在-150,100,

t.right(90)

t.pendown()

t.fd(150)

t.circle(50,90)

t.fd(300)

t.circle(50,90)

t.fd(150)

t.left(66)

t.circle(493,48)

t.left(66)

t.end_fill()

#=============================蛋糕的外框

t.penup()

t.goto(-200,50)

t.pendown()

t.left(60)

t.fd(20)

t.circle(10,70)

t.fd(50)

t.circle(-10,70)

t.fd(60)

t.circle(10,70)

t.fd(50)

t.circle(-10,70)

t.fd(60)

t.circle(10,70)

t.fd(50)

t.circle(-10,70)

t.fd(60)

t.circle(10,70)

t.fd(42)

#=============================绘制奶酪

t.penup()

t.goto(-200,100)

t.pendown()

#=============================移到最初的起点

t.fillcolor("#5cb85c")

t.begin_fill() #第一个圈

t.left(90)

t.circle(-20,220)

t.end_fill()

t.fillcolor("#cca4e3")

t.begin_fill() #第二个圈

t.left(200)

t.circle(-23,185)

t.end_fill()

t.fillcolor("#5cb85c")

t.begin_fill() #第三个圈

t.left(180)

t.circle(-22,185)

t.end_fill()

t.fillcolor("#5AA9F3")

t.begin_fill() #第四个圈

t.left(180)

t.circle(-20,186)

t.end_fill()

t.fillcolor("blue")

t.begin_fill() #第五个圈

t.left(180)

t.circle(-20,183)

t.end_fill()

t.fillcolor("yellow")

t.begin_fill() #第六个圈

t.left(180)

t.circle(-20,190)

t.end_fill()

t.fillcolor("orange")

t.begin_fill()

t.left(180)

t.circle(-21,177)

t.end_fill()

t.fillcolor("brown")

t.begin_fill()

t.left(180)

t.circle(-20,190)

t.end_fill()

t.fillcolor("purple")

t.begin_fill()

t.left(190)

t.circle(-20,200)

t.end_fill()

t.fillcolor("pink")

t.begin_fill()

t.left(195)

t.circle(-22,204)

t.end_fill()

#===================================绘制蛋糕上的花瓣

t.penup()

t.goto(-130,140)

t.left(215)

t.pendown()

t.fd(90)

t.right(90)

t.fd(10)

t.left(185)

t.fillcolor("#ff2d51")

t.begin_fill()

t.circle(-10,180)

t.circle(10,180)

t.left(180)

t.circle(-20,180)

t.end_fill()

t.fillcolor("yellow")

t.begin_fill()

t.left(175)

t.fd(10)

t.right(90)

t.fd(79)

t.end_fill()

#========================第一个蜡烛,接下来是第二个蜡烛

t.penup()

t.goto(120,140)

t.left(180)

t.pendown()

t.fd(90)

t.right(90)

t.fd(10)

t.left(185)

t.fillcolor("#ff2d51")

t.begin_fill()

t.circle(-10,180)

t.circle(10,180)

t.left(180)

t.circle(-20,180)

t.end_fill()

t.fillcolor("yellow")

t.begin_fill()

t.left(175)

t.fd(10)

t.right(90)

t.fd(85)

t.end_fill()

#=========================第二支蜡烛

t.penup()

t.goto(0,-30)

t.pendown()

t.fillcolor("red")

t.begin_fill()

t.right(90)

t.fd(15)

t.goto(0,-50)

t.goto(15,-30)

t.goto(0,-30)

t.end_fill()

t.penup()

t.goto(-70,30)

t.pendown()

t.fillcolor("black")

t.begin_fill()

t.circle(10,360)

t.end_fill()

t.penup()

t.goto(70,30)

t.pendown()

t.fillcolor("black")

t.begin_fill()

t.circle(10,360)

t.end_fill()

#============两只眼睛一张嘴

time.sleep(3)

# t.right(90)

# t.fd(100) #向前方画100像素

# t.left(90) #向右旋转90度

# t.fd(150)

# t.left(90)

# t.pendown()

# t.fd(150)

# t.left(90)

# t.circle(100,45)

#==============================设置初始位置

# t.circle(200, 45)

# t.left(90)

# t.circle(200, 90)

# t.left(90)

# t.circle(200, 45)

# #===============================绘制顶部半圆

#

#

# t.penup()

# t.goto(-140,160)

# t.right(90)

# t.pendown()

# t.goto(-140,20)

ff91b8a14e6c4da8bff0ad2631a5be1b.png

祝天下所有二十岁生日的少年生日快乐!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个使用 Pythonturtle 模块生日蛋糕的例子: ```python import turtle # 设置turtle.penup() turtle.goto(-200, 0) turtle.pendown() turtle.pensize(5) turtle.pencolor('red') turtle.speed(4) # 蜡烛 for i in range(5): turtle.fillcolor('yellow') turtle.begin_fill() turtle.forward(40) turtle.left(90) turtle.forward(40) turtle.left(90) turtle.forward(40) turtle.left(90) turtle.forward(40) turtle.left(90) turtle.end_fill() turtle.penup() turtle.forward(10) turtle.pendown() # 火苗 turtle.fillcolor('orange') turtle.begin_fill() turtle.forward(10) turtle.right(135) turtle.forward(20) turtle.right(90) turtle.forward(20) turtle.right(135) turtle.forward(30) turtle.right(135) turtle.forward(20) turtle.right(90) turtle.forward(20) turtle.right(135) turtle.forward(10) turtle.end_fill() turtle.penup() turtle.right(90) turtle.forward(50) turtle.right(90) turtle.forward(60) turtle.right(180) # 蛋糕 turtle.penup() turtle.goto(-100, -100) turtle.pendown() turtle.fillcolor('pink') turtle.begin_fill() turtle.forward(200) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.forward(200) turtle.left(90) turtle.forward(100) turtle.left(90) turtle.end_fill() # turtle.penup() turtle.goto(-50, -50) turtle.pendown() turtle.pencolor('white') turtle.write('Happy Birthday!', font=('Arial', 18, 'normal')) # 隐藏turtle.hideturtle() # 等待点击关闭窗口 turtle.exitonclick() ``` 这段代码使用 turtle 模块了一个生日蛋糕,包括蜡烛、火苗、蛋糕生日快乐的字样。你可以在终端中运行这段代码,看看效果如何。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值