python 七段管模块

def drawGap(): #绘制数码管间隔
turtle.penup()
turtle.fd(5)
def drawLine(draw): #绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
drawGap()
turtle.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)
turtle.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)
turtle.left(180)
turtle.penup()
turtle.fd(20)

实例

import turtle, time
t=turtle.Pen() <粘贴模板代码> def drawchinese(word):
t.sety(-55)
if word == '-':
t.write('年',font=("Arial", 70, "normal"))
t.fd(110)
elif word == '=':
t.write('月',font=("Arial", 70, "normal"))
t.fd(110)
elif word == '+':
t.write('日',font=("Arial", 70, "normal"))
t.sety(0) def drawDate(date):
for i in date:
if i=='-'or i=='='or i=='+':
drawchinese(i)
else:
drawDigit(eval(i))
def main():
turtle.setup(1000, 350, 200, 200)
t.penup()
t.forward(-450)
t.pensize(5)
drawDate(time.strftime('%Y-%m=%d+',time.gmtime()))
turtle.exitonclick()
main()

python 七段管模块-LMLPHP

05-04 11:00