import turtle
import math
def drawGap():#绘制数码管间隔
turtle.penup()
turtle.fd(5)
def drawLine(draw):#绘制单段数码管
drawGap()#画之前先画个间隔
turtle.pendown()if draw else turtle.penup()#draw为1落笔,draw为0提笔
turtle.fd(80)
drawGap()
turtle.right(90)
def drawLine1(draw):#一半线
turtle.pendown()if draw else turtle.penup()
turtle.fd(40)
def drawLine2(draw):#整线
drawGap()#间隔
turtle.pendown()if draw else turtle.penup()
turtle.fd(80)
def drawLine3(draw):#斜线
drawGap()#间隔
turtle.pendown()if draw else turtle.penup()
turtle.fd(40*math.sqrt(5))
def drawDigit(digit):
drawGap()
drawGap() # 间隔
drawLine1(True) if digit in ['a','b','e','f','h','j','p','q','r','s']else drawLine1(False)#第一条短线
drawGap()
drawLine1(True) if digit in ['a', 'b', 'e', 'f', 'h', 'g', 'p', 'q', 'r', 's'] else drawLine1(False)#第二条短线
drawGap()
turtle.right(90)
drawLine2(True) if digit in ['a', 'b', 'd', 'g', 'h', 'n', 'q', 's', 'u', 'w','o'] else drawLine2(False)#右下角长线
drawGap()
turtle.right(90)
drawLine2(True) if digit in ['c', 'b', 'd', 'g', 'e', 'i', 'l', 's','u','z','o'] else drawLine2(False) # 底下长线
drawGap()
turtle.right(90)
drawLine2(True) if digit in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'l', 'p', 'n', 'r','u','w','o'] else drawLine2(False)#左下角长线
drawGap()
drawLine2(True) if digit in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'l', 'm', 'n', 'o', 'p','q','r','s','u'] else drawLine2(False) # 左上侧长线
drawGap()
turtle.right(90)
drawLine2(True) if digit in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'j', 'o', 'p', 'q', 'r', 's', 't'] else drawLine2(False)#顶部长线
drawGap()
turtle.right(90)
drawLine2(True) if digit in ['a', 'b', 'd', 'h', 'm', 'n', 'o', 'p', 'q', 'r', 'u'] else drawLine2(False) # 右侧长线
drawGap()
drawLine2(True) if digit in ['a', 'b', 'd', 'g', 'h', 'n', 'q', 's', 'u', 'w'] else drawLine2(False) # 右下角长线
drawGap()
turtle.right(153)
drawLine3(True) if digit in ['k', 'n', 'r', 'w', 'x'] else drawLine2(False) # 右下角斜线
drawGap()
drawLine3(True) if digit in ['m', 'n', 'v', 'y', 'x'] else drawLine2(False) # 左上角斜线
drawGap()
turtle.right(117)
turtle.penup()
turtle.fd(80)
drawGap()
turtle.right(117)
drawLine3(True) if digit in ['m', 'k', 'v', 'y', 'x'] else drawLine2(False) # 右上角斜线
drawGap()
drawLine3(True) if digit in ['w', 'x'] else drawLine2(False) # 左下角斜线
drawGap()
turtle.left(117)
drawLine1(True) if digit in ['c', 'b', 'd', 'g', 'e', 'i', 'l', 's','u','z']else drawLine1(False) # 左下角横短线
drawGap()
turtle.left(90)
drawLine2(True) if digit in ['y', 'k', 't', 'i'] else drawLine2(False)#中心下整线
drawGap()
drawLine2(True) if digit in ['j', 'k', 't', 'i'] else drawLine2(False)#中心上整线
turtle.penup() # 抬