请用turtle绘制一个生日蛋糕
时间: 2024-06-10 20:08:47 浏览: 16
好的,这是绘制生日蛋糕的Python代码:
```python
import turtle
# 绘制蛋糕底
turtle.penup()
turtle.goto(0, -100)
turtle.pendown()
turtle.fillcolor("yellow")
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 绘制蛋糕上的糖霜
turtle.penup()
turtle.goto(-120, 0)
turtle.pendown()
turtle.fillcolor("white")
turtle.begin_fill()
turtle.setheading(0)
turtle.forward(240)
turtle.left(90)
turtle.circle(100, -180)
turtle.left(90)
turtle.forward(240)
turtle.end_fill()
# 绘制蛋糕上的蜡烛
turtle.penup()
turtle.goto(-40, 100)
turtle.pendown()
turtle.setheading(270)
turtle.fillcolor("red")
turtle.begin_fill()
turtle.forward(20)
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(20)
turtle.end_fill()
# 绘制蛋糕上的蛋糕贴纸
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.setheading(0)
turtle.fillcolor("purple")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 文字描述生日蛋糕
turtle.penup()
turtle.goto(0, 150)
turtle.pendown()
turtle.write("生日快乐!", align="center", font=("Arial", 24, "normal"))
turtle.done()
```
运行代码,就可以看到一只生日蛋糕啦!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)