python使用海龟库绘图绘制倒三角形 菱形 五边形 六边形 圆
时间: 2023-10-24 15:22:24 浏览: 587
poligonos_turtle:使用Turtle库创建多边形
好的,下面是使用海龟库绘制不同形状图形的 Python 代码:
1. 绘制倒三角形:
```python
import turtle
t = turtle.Turtle()
# 绘制倒三角形
for i in range(3):
t.forward(100)
t.right(120)
turtle.done()
```
2. 绘制菱形:
```python
import turtle
t = turtle.Turtle()
# 绘制菱形
for i in range(4):
t.forward(100)
t.right(45)
turtle.done()
```
3. 绘制五边形:
```python
import turtle
t = turtle.Turtle()
# 绘制五边形
for i in range(5):
t.forward(100)
t.right(72)
turtle.done()
```
4. 绘制六边形:
```python
import turtle
t = turtle.Turtle()
# 绘制六边形
for i in range(6):
t.forward(100)
t.right(60)
turtle.done()
```
5. 绘制圆:
```python
import turtle
t = turtle.Turtle()
# 绘制圆
t.circle(100)
turtle.done()
```
阅读全文