用python画出鸡和篮球
时间: 2024-01-26 17:27:07 浏览: 55
当然可以!下面是使用Python的turtle库画出鸡和篮球的示例代码:
```python
import turtle
# 画鸡
def draw_chicken():
turtle.penup()
turtle.goto(-50, -50)
turtle.pendown()
# 画鸡身体
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, -30)
turtle.pendown()
# 画鸡头
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画鸡嘴巴
turtle.penup()
turtle.goto(-45, -10)
turtle.pendown()
turtle.pencolor('orange')
turtle.setheading(-60)
turtle.circle(20, 120)
# 画眼睛
turtle.penup()
turtle.goto(-20, -20)
turtle.pendown()
turtle.fillcolor('black')
turtle.setheading(0)
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 画篮球
def draw_basketball():
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
# 画篮球外圈
turtle.fillcolor('orange')
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画篮球纹理
for _ in range(8):
turtle.penup()
turtle.goto(50, 0)
turtle.pendown()
turtle.setheading(-90)
turtle.circle(50, 45)
turtle.hideturtle()
# 主函数
def main():
turtle.setup(500, 500)
turtle.speed(3)
draw_chicken()
draw_basketball()
turtle.done()
# 调用主函数
main()
```
运行上述代码后,将会通过turtle库画出一个鸡和一个篮球。希望这对你有所帮助!如果你还有其他问题,请随时提问。
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)