绘制七段数码管(高级)

from turtle import*
from time import*
def drawGap(): #绘制数码管间隔
penup()
fd(5)
def drawLine(draw): #绘制单段数码管
drawGap()
pendown() if draw else penup()
fd(40)
drawGap()
right(90)
def drawDigit(d): #根据数字绘制七段数码管
drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False)
drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False)
drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False)
drawLine(True) if d in [0,2,6,8] else drawLine(False)
left(90)
drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False)
drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False)
drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False)
left(180)
penup()
fd(20)
def drawDate(date): #获得输入的数字
pencolor('blueViolet')
for i in date:
if i '-':
write("年",font=('宋体',18,'normal'))
pencolor('pink')
fd(40)
elif i
'=':
write('月',font=('楷体',18,'normal'))
pencolor('yellow')
fd(40)
elif i=='+':
write('日',font=('黑体',18,'normal'))
else:
drawDigit(eval(i))
def main():
setup(800,350,200,200)
penup()
fd(-300)
pensize(5)
drawDate(strftime("%Y-%m=%d+",gmtime()))
main()

posted @ 2024-12-05 11:32  xc3535231695  阅读(21)  评论(0)    收藏  举报