turtle打印小汽车
时间: 2023-11-13 09:46:15 浏览: 36
画小汽车的源码(turtle)
可以使用 Python 中自带的 turtle 库来绘制小汽车。以下是一个示例代码:
```python
import turtle
# 绘制车身
turtle.penup()
turtle.goto(-100, 0)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
turtle.forward(200)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(200)
turtle.left(90)
turtle.forward(50)
turtle.end_fill()
# 绘制车轮
turtle.penup()
turtle.goto(-70, -50)
turtle.pendown()
turtle.color('black')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(70, -50)
turtle.pendown()
turtle.color('black')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.done()
```
运行上述代码后,turtle 就会绘制出一个红色的小汽车,如下图所示:
![turtle小汽车](https://cdn.jsdelivr.net/gh/Yousazoe/picbed/img/20211018122450.png)
阅读全文