用python的turtle画一个晶体管
时间: 2023-07-04 10:31:00 浏览: 117
使用Python的turtle模块画图
好的,以下是用 Python 的 turtle 模块画晶体管的代码:
```python
import turtle
# 设置画笔颜色和宽度
turtle.pencolor("blue")
turtle.pensize(5)
# 画晶体管的外壳
turtle.penup()
turtle.goto(-150, 0)
turtle.pendown()
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(100)
# 画晶体管的管子
turtle.penup()
turtle.goto(-125, 50)
turtle.pendown()
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(50)
# 画晶体管的底座
turtle.penup()
turtle.goto(-150, -50)
turtle.pendown()
turtle.forward(100)
turtle.left(90)
turtle.forward(25)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(25)
turtle.left(90)
turtle.forward(25)
turtle.left(90)
turtle.forward(25)
turtle.right(90)
turtle.forward(50)
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
```
运行以上代码,就可以看到画出来的晶体管了。如果需要修改颜色和大小,可以根据注释的提示修改代码。
阅读全文