七段数码管绘制python代码
时间: 2023-10-14 11:24:33 浏览: 70
七段数码管绘制
以下是一个简单的七段数码管绘制的 Python 代码,使用了 Turtle 库:
```python
import turtle
# 绘制数字 0
def draw_zero():
turtle.penup()
turtle.goto(-50, 50)
turtle.pendown()
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.penup()
# 绘制数字 1
def draw_one():
turtle.penup()
turtle.goto(50, 50)
turtle.pendown()
turtle.right(135)
turtle.forward(140)
turtle.right(225)
turtle.forward(100)
turtle.penup()
# 绘制数字 2
def draw_two():
turtle.penup()
turtle.goto(-50, -50)
turtle.pendown()
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(45)
turtle.forward(70.71)
turtle.right(135)
turtle.forward(50)
turtle.penup()
# 绘制数字 3
def draw_three():
turtle.penup()
turtle.goto(50, -50)
turtle.pendown()
turtle.right(90)
turtle.forward(100)
turtle.right(225)
turtle.forward(70.71)
turtle.right(135)
turtle.forward(100)
turtle.penup()
# 绘制数字 4
def draw_four():
turtle.penup()
turtle.goto(-50, -150)
turtle.pendown()
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(180)
turtle.forward(100)
turtle.penup()
# 绘制数字 5
def draw_five():
turtle.penup()
turtle.goto(0, -150)
turtle.pendown()
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.penup()
# 绘制数字 6
def draw_six():
turtle.penup()
turtle.goto(-50, -250)
turtle.pendown()
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.penup()
# 绘制数字 7
def draw_seven():
turtle.penup()
turtle.goto(50, -250)
turtle.pendown()
turtle.right(135)
turtle.forward(70.71)
turtle.right(45)
turtle.forward(100)
turtle.penup()
# 绘制数字 8
def draw_eight():
turtle.penup()
turtle.goto(-50, -350)
turtle.pendown()
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.penup()
# 绘制数字 9
def draw_nine():
turtle.penup()
turtle.goto(50, -350)
turtle.pendown()
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(50)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(50)
turtle.penup()
# 初始化
turtle.speed(0)
turtle.hideturtle()
# 绘制数字 0 到 9
draw_zero()
draw_one()
draw_two()
draw_three()
draw_four()
draw_five()
draw_six()
draw_seven()
draw_eight()
draw_nine()
# 显示绘制结果
turtle.done()
```
这个代码通过调用不同的函数,每个函数绘制了一个数字。调用时,只需要修改数字对应的函数即可。
阅读全文