turtle画图代码大全
时间: 2023-07-22 22:07:26 浏览: 169
python turtle 绘图动画源码
以下是一些turtle画图的示例代码:
1. 画一个正方形:
```python
import turtle
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
```
2. 画一个三角形:
```python
import turtle
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
```
3. 画一个五角星:
```python
import turtle
for i in range(5):
turtle.forward(100)
turtle.right(144)
```
4. 画一个圆形:
```python
import turtle
turtle.circle(100)
```
5. 画一个螺旋线:
```python
import turtle
for i in range(100):
turtle.forward(i)
turtle.right(10)
```
6. 画一个心形:
```python
import turtle
turtle.left(45)
turtle.forward(100)
turtle.circle(50, 180)
turtle.right(90)
turtle.circle(50, 180)
turtle.forward(100)
```
以上代码只是一些简单的示例,你可以根据需要调整参数和循环次数来创建更复杂的图形。
阅读全文