七段数码管的绘制1
# 七段数码管的绘制(LED显示)# SevenDigitsDraw
import turtle as t
def drawLine(draw):
t.pendown() if draw else t.penup()
t.fd(40)
t.right(90)
def drawDigit(digit):
# 数字2,3,4,5,6,8,9需要画第一笔
drawLine(True) if digit in else drawLine(False)
# 数字0,1,3,4,5,6,7,8,9需要画第一笔
drawLine(True) if digit in else drawLine(False)
drawLine(True) if digit in else drawLine(False)
drawLine(True) if digit in else drawLine(False)
t.left(90)
drawLine(True) if digit in else drawLine(False)
drawLine(True) if digit in else drawLine(False)
drawLine(True) if digit in else drawLine(False)
t.left(180)
t.penup()# 为绘制后续数字确定位置
t.fd(20)# 为绘制后续数字确定位置
defdrawDate(date):
for i in date:
drawDigit(eval(i))
def main():
t.setup(800, 350, 200, 200)
t.penup()
t.fd(-300)
t.pensize(5)
drawDate('20181016')
t.hideturtle()
t.done()
main()
页:
[1]