用Python画一个蛋糕
时间: 2023-05-11 22:03:22 浏览: 129
好的,以下是用Python画一个蛋糕的代码:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("pink")
# 画蛋糕底部
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.begin_fill()
turtle.color("brown")
turtle.circle(200)
turtle.end_fill()
# 画蛋糕上面的奶油
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color("white")
turtle.circle(150)
turtle.end_fill()
# 画蛋糕上的草莓
turtle.penup()
turtle.goto(-100, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(100, 100)
turtle.pendown()
turtle.begin_fill()
turtle.color("red")
turtle.circle(50)
turtle.end_fill()
# 画蛋糕上的蜡烛
turtle.penup()
turtle.goto(0, 200)
turtle.pendown()
turtle.color("yellow")
turtle.pensize(5)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
turtle.done()
```
希望这个代码对你有帮助!
阅读全文