python有趣的画图代码大全
时间: 2023-11-01 19:58:47 浏览: 96
如果你对使用Python的turtle模块进行有趣的画图代码感兴趣,可以尝试以下代码示例:
1. 绘制彩虹
```python
import turtle
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
turtle.bgcolor('black')
turtle.speed(10)
turtle.width(3)
for x in range(360):
turtle.pencolor(colors[x % 6])
turtle.forward(x)
turtle.left(59)
```
2. 绘制螺旋线
```python
import turtle
turtle.bgcolor('black')
turtle.speed(0)
turtle.width(3)
for x in range(200):
turtle.pencolor('white')
turtle.forward(x)
turtle.left(91)
```
3. 绘制星星
```python
import turtle
turtle.bgcolor('black')
turtle.speed(0)
for x in range(5):
turtle.pencolor('white')
turtle.forward(200)
turtle.right(144)
```
4. 绘制花朵
```python
import turtle
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']
turtle.bgcolor('black')
turtle.speed(0)
turtle.width(3)
for x in range(120):
turtle.pencolor(colors[x % 6])
turtle.circle(x)
turtle.left(59)
```
阅读全文