python海龟作图经典100例
时间: 2023-07-07 11:34:06 浏览: 150
1. 绘制一个正方形
```python
import turtle
pen = turtle.Turtle()
for i in range(4):
pen.forward(100)
pen.right(90)
turtle.done()
```
2. 绘制一个圆形
```python
import turtle
pen = turtle.Turtle()
pen.circle(50)
turtle.done()
```
3. 绘制一个五边形
```python
import turtle
pen = turtle.Turtle()
for i in range(5):
pen.forward(100)
pen.right(72)
turtle.done()
```
4. 绘制一个六边形
```python
import turtle
pen = turtle.Turtle()
for i in range(6):
pen.forward(100)
pen.right(60)
turtle.done()
```
5. 绘制一个边长逐渐增加的正方形
```python
import turtle
pen = turtle.Turtle()
for i in range(10):
pen.forward(50 + i * 10)
pen.right(90)
turtle.done()
```
6. 绘制一个颜色逐渐变化的六边形
```python
import turtle
pen = turtle.Turtle()
for i in range(6):
pen.color(1 - i / 6, i / 6, 0)
pen.forward(100)
pen.right(60)
turtle.done()
```
7. 绘制一个螺旋线
```python
import turtle
pen = turtle.Turtle()
for i in range(100):
pen.forward(i)
pen.right(30)
turtle.done()
```
8. 绘制一个彩虹
```python
import turtle
pen = turtle.Turtle()
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
for i in range(6):
pen.color(colors[i])
pen.width(10 - i)
pen.circle(100 - i * 20)
turtle.done()
```
9. 绘制一个星形
```python
import turtle
pen = turtle.Turtle()
for i in range(5):
pen.forward(100)
pen.right(144)
turtle.done()
```
10. 绘制一个爱心
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
pen.left(45)
pen.forward(100)
pen.circle(50, 180)
pen.right(90)
pen.circle(50, 180)
pen.forward(100)
pen.end_fill()
turtle.done()
```
11. 绘制一个三叶草
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("green")
pen.begin_fill()
pen.right(75)
pen.forward(100)
pen.right(165)
pen.forward(100)
pen.right(165)
pen.forward(100)
pen.end_fill()
turtle.done()
```
12. 绘制一个雪花
```python
import turtle
pen = turtle.Turtle()
def snowflake(size):
pen.forward(size)
pen.right(60)
pen.forward(size)
pen.left(120)
pen.forward(size)
pen.right(60)
pen.forward(size)
for i in range(6):
snowflake(100)
pen.right(60)
turtle.done()
```
13. 绘制一个棋盘
```python
import turtle
pen = turtle.Turtle()
def square(color, size):
pen.fillcolor(color)
pen.begin_fill()
for i in range(4):
pen.forward(size)
pen.right(90)
pen.end_fill()
size = 20
for i in range(8):
for j in range(8):
if (i + j) % 2 == 0:
square("black", size)
else:
square("white", size)
pen.forward(size)
pen.backward(size * 8)
pen.right(90)
pen.forward(size)
pen.left(90)
turtle.done()
```
14. 绘制一个立体正方体
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
for i in range(4):
pen.forward(100)
pen.right(90)
pen.end_fill()
pen.up()
pen.goto(50, 50)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
for i in range(4):
pen.forward(100)
pen.right(90)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(135)
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.right(135)
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.end_fill()
turtle.done()
```
15. 绘制一个立体圆柱
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.up()
pen.goto(0, 0)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(90)
pen.forward(100)
pen.circle(50, 180)
pen.forward(100)
pen.end_fill()
turtle.done()
```
16. 绘制一个立体球体
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
pen.right(90)
pen.circle(50)
pen.left(90)
pen.circle(-50)
pen.end_fill()
pen.up()
pen.goto(0, 0)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(45)
pen.circle(50, 90)
pen.right(90)
pen.circle(50, 90)
pen.right(90)
pen.circle(50, 90)
pen.right(90)
pen.circle(50, 90)
pen.end_fill()
turtle.done()
```
17. 绘制一个立体金字塔
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
for i in range(3):
pen.forward(100)
pen.right(120)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
for i in range(3):
pen.forward(100)
pen.left(120)
pen.end_fill()
pen.up()
pen.goto(-50, 50)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(60)
pen.forward(100)
pen.right(120)
pen.forward(100)
pen.right(120)
pen.forward(100)
pen.end_fill()
turtle.done()
```
18. 绘制一个立体长方体
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
for i in range(4):
pen.forward(100)
pen.right(90)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
for i in range(4):
pen.forward(100)
pen.right(90)
pen.end_fill()
pen.up()
pen.goto(100, 0)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
for i in range(4):
pen.forward(100)
pen.right(90)
pen.end_fill()
pen.up()
pen.goto(0, 0)
pen.down()
pen.fillcolor("yellow")
pen.begin_fill()
pen.right(45)
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.right(135)
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.right(135)
pen.forward(100)
pen.right(45)
pen.forward(100)
pen.end_fill()
turtle.done()
```
19. 绘制一个立体圆锥
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.up()
pen.goto(0, 0)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(90)
pen.forward(100)
pen.circle(-50, 180)
pen.end_fill()
turtle.done()
```
20. 绘制一个立体圆环
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
pen.circle(50)
pen.end_fill()
pen.up()
pen.goto(0, 100)
pen.down()
pen.circle(50, 180)
pen.up()
pen.goto(0, 0)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.circle(30)
pen.end_fill()
pen.up()
pen.goto(0, 70)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
turtle.done()
```
21. 绘制一个立体正十二面体
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
for i in range(5):
pen.forward(100)
pen.right(72)
pen.end_fill()
pen.up()
pen.goto(0, 200)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
pen.right(36)
for i in range(5):
pen.forward(100)
pen.right(72)
pen.end_fill()
pen.up()
pen.goto(200, 200)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(36)
for i in range(5):
pen.forward(100)
pen.right(72)
pen.end_fill()
pen.up()
pen.goto(200, 0)
pen.down()
pen.fillcolor("yellow")
pen.begin_fill()
pen.right(36)
for i in range(5):
pen.forward(100)
pen.right(72)
pen.end_fill()
pen.up()
pen.goto(0, -200)
pen.down()
pen.fillcolor("purple")
pen.begin_fill()
pen.right(36)
for i in range(5):
pen.forward(100)
pen.right(72)
pen.end_fill()
pen.up()
pen.goto(-200, -200)
pen.down()
pen.fillcolor("orange")
pen.begin_fill()
pen.right(36)
for i in range(5):
pen.forward(100)
pen.right(72)
pen.end_fill()
turtle.done()
```
22. 绘制一个立体正十四面体
```python
import turtle
pen = turtle.Turtle()
pen.fillcolor("red")
pen.begin_fill()
for i in range(8):
pen.forward(100)
pen.right(45)
pen.end_fill()
pen.up()
pen.goto(-70, 70)
pen.down()
pen.fillcolor("blue")
pen.begin_fill()
pen.right(45)
for i in range(8):
pen.forward(100)
pen.right(45)
pen.end_fill()
pen.up()
pen.goto(70, 70)
pen.down()
pen.fillcolor("green")
pen.begin_fill()
pen.right(45)
for i in range(8):
pen.forward(100)
pen.right(45)
pen.end_fill()
pen.up()
pen.goto(70, -70)
pen.down()
pen.fillcolor("yellow")
pen.begin_fill()
pen.right(45)
for i in range(8):
pen.forward(100)
pen.right(45)
pen.end_fill()
pen.up()
pen.goto(-
阅读全文