生日蛋糕代码编程python
时间: 2023-11-21 13:55:51 浏览: 301
以下是一个用Python绘制生日蛋糕的例子,其中包括生日祝福对象和祝福语,并且有两层蛋糕和蜡烛。请注意,代码运行时间可能较长,请耐心等待。
```python
import turtle
# 设置画布大小和背景颜色
canvas = turtle.Screen()
canvas.bgcolor("#FFDAB9")
canvas.setup(width=800, height=600)
# 绘制底层蛋糕
cake1 = turtle.Turtle()
cake1.speed(10)
cake1.penup()
cake1.goto(0, -200)
cake1.pendown()
cake1.begin_fill()
cake1.color("#FF69B4")
cake1.circle(200)
cake1.end_fill()
# 绘制上层蛋糕
cake2 = turtle.Turtle()
cake2.speed(10)
cake2.penup()
cake2.goto(0, 0)
cake2.pendown()
cake2.begin_fill()
cake2.color("#FFC0CB")
cake2.circle(100)
cake2.end_fill()
# 绘制蜡烛
candle = turtle.Turtle()
candle.speed(10)
candle.penup()
candle.goto(0, 100)
candle.pendown()
candle.color("#FFD700")
candle.begin_fill()
candle.circle(20)
candle.end_fill()
# 绘制蜡烛火焰
flame = turtle.Turtle()
flame.speed(10)
flame.penup()
flame.goto(0, 120)
flame.pendown()
flame.color("#FFA500")
flame.begin_fill()
flame.circle(10)
flame.end_fill()
# 编写生日祝福语
text = turtle.Turtle()
text.speed(10)
text.penup()
text.goto(0, 250)
text.pendown()
text.color("#8B0000")
text.write("Happy Birthday!", align="center", font=("Arial", 36, "bold"))
# 编写生日祝福对象
name = turtle.Turtle()
name.speed(10)
name.penup()
name.goto(0, -250)
name.pendown()
name.color("#8B0000")
name.write("To [生日祝福对象],", align="center", font=("Arial", 24, "normal"))
name.penup()
name.goto(0, -300)
name.pendown()
name.write("Best wishes!", align="center", font=("Arial", 24, "normal"))
turtle.done()
```
阅读全文