Python海龟画潜水艇代码
时间: 2024-05-16 22:10:41 浏览: 132
python实现海龟绘图程序
Python海龟画潜水艇代码是一种基于Python中turtle库的绘图程序,通过turtle库提供的函数和方法来绘制出一个潜水艇的图形。以下是Python海龟画潜水艇代码的实现步骤:
1. 导入turtle库
```
import turtle
```
2. 创建画布和画笔
```
window = turtle.Screen()
pen = turtle.Turtle()
```
3. 绘制潜水艇的外形
```
# 潜水艇的船体
pen.pensize(4)
pen.penup()
pen.goto(-150,0)
pen.pendown()
pen.color('gray')
pen.circle(50,180)
pen.forward(300)
pen.circle(50,180)
# 潜水艇的舷窗
pen.penup()
pen.goto(-60,0)
pen.pendown()
pen.color('black')
pen.circle(20)
pen.penup()
pen.goto(60,0)
pen.pendown()
pen.color('black')
pen.circle(20)
# 潜水艇的螺旋桨
pen.penup()
pen.goto(-120,-50)
pen.pendown()
pen.color('black')
pen.begin_fill()
for i in range(3):
pen.forward(240)
pen.left(120)
pen.end_fill()
# 潜水艇的尾部
pen.penup()
pen.goto(-150,0)
pen.pendown()
pen.color('gray')
pen.begin_fill()
for i in range(2):
pen.forward(30)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.end_fill()
```
4. 完成绘图并显示结果
```
window.exitonclick()
```
阅读全文