用python turtle库画一个黄色正立的月牙
时间: 2023-05-17 10:07:20 浏览: 190
以下是Python Turtle库画一个黄色正立的月牙的代码:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔颜色和填充颜色
pen.color("yellow")
pen.fillcolor("yellow")
# 开始绘制月牙
pen.begin_fill()
pen.circle(100, 180)
pen.circle(50, 180)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 等待用户关闭画布
canvas.mainloop()
```
运行以上代码,即可在画布上看到一个黄色正立的月牙。
相关问题
用python turtle库画一个立体的黄色五层书架
好的,以下是解决方案:
```python
import turtle
# 设置画笔颜色和填充颜色为黄色
turtle.color("yellow")
turtle.begin_fill()
# 画第一层
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第二层
turtle.up()
turtle.goto(0, 30)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第三层
turtle.up()
turtle.goto(0, 60)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第四层
turtle.up()
turtle.goto(0, 90)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第五层
turtle.up()
turtle.goto(0, 120)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 填充颜色
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,将会弹出一个窗口,显示一个立体的黄色五层书架。
用Python turtle库画一个熊二的卡通头像
好的,我可以为您提供如下代码:
```
import turtle
# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor("#F7D267")
pen = turtle.Turtle()
# 画熊二的耳朵
pen.penup()
pen.goto(-50,100)
pen.pendown()
pen.fillcolor("#C93930")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.penup()
pen.goto(50,100)
pen.pendown()
pen.fillcolor("#C93930")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 画熊二的脸
pen.penup()
pen.goto(0,-60)
pen.pendown()
pen.fillcolor("#F5B247")
pen.begin_fill()
pen.circle(100)
pen.end_fill()
# 画熊二的眼睛
pen.penup()
pen.goto(-40,40)
pen.pendown()
pen.fillcolor("#FFFFFF")
pen.begin_fill()
pen.circle(25)
pen.end_fill()
pen.penup()
pen.goto(40,40)
pen.pendown()
pen.fillcolor("#FFFFFF")
pen.begin_fill()
pen.circle(25)
pen.end_fill()
# 画熊二的鼻子
pen.penup()
pen.goto(0,0)
pen.pendown()
pen.fillcolor("#000000")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 画熊二的嘴巴
pen.penup()
pen.goto(-40,-40)
pen.pendown()
pen.setheading(-45)
pen.circle(30,90)
# 隐藏画笔
pen.hideturtle()
# 显示画面
canvas.mainloop()
```
您可以将代码复制到Python编辑器中并运行,即可看到熊二的卡通头像。
相关推荐
![](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)