七段数码管可以有固定的顺序
不同的数字显示不同的线条
代码:
import turtle,time
def drawGap():
turtle.penup()
turtle.fd(5)
def drawLine(draw): 绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup() 要是down是真值,那么海龟画笔落下
turtle.fd(40)
drawGap()
turtle.right(90)
def drawDigit (digit): 根据数字绘制七段数码管
drawLine(Ture) if digit in [2,3,4,5,6,9]else drawLine(False)
drawLine(Ture) if digit in [0,1,3,4,5,6,7,8,9]else drawLine(False)
drawLine(Ture) if digit in [0,2,3,5,6,8,9]else drawLine(False)
drawLine(Ture) if digit in [0,2,6,8]else drawLine(False) 现在一直右转,绘制完1,2,3,4的管,让他左转开始绘制其他的
turtle.left(90)
drawLine(Ture) if digit in [0,4,5,6,8,9]else drawLine(False)
drawLine(Ture) if digit in [0,2,3,5,6,7,8,9]else drawLine(False)
drawLine(Ture) if digit in [0,1,2,3,4,7,8,9]else drawLine(False)
turtle.left(180)
turtle.penup()
turtle.fd(20)
def drawDate(date):
turtle.pencolor("red")
for i in date:
if i =='-':
turtle.write("年",font=("Arial",18,"normai"))
turtle.pencolor("green")
turtle.fd(40)
elif i =='=':
turtle.write("月",font=("Arial",18,"normai"))
elif i =='+':
turtle.write("日",font=("Arial",18,"normai"))
else:
drawDigit(eval(i))
def main():
tyrtle.setup(800,350,200,200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
drawDate(time.strftime("%Y-%m=%d+",time,gmtime()))
drawDate('20210205')
turtle.hideturtle()
turtle.done()
main()
七段数码管的举一反三
模块化思维:确定模块接口,封装功能
规则化思维:抽象过程为规则,计算机自动执行
应用问题的扩展
绘制地小数点的七段数码管
带刷新的时间倒计时效果