首页 > 其他分享 >数码管绘制时间

数码管绘制时间

时间:2022-12-08 17:22:40浏览次数:38  
标签:turtle False drawLine 40 else 数码管 时间 fd 绘制

 1 import turtle
 2 import datetime
 3 
 4 def drawGap():  # 绘制数码管间隔
 5     turtle.penup()
 6     turtle.fd(1)
 7 
 8 def drawLine(draw):  # 绘制单段数码管
 9     drawGap()
10     turtle.pendown() if draw else turtle.penup()
11     turtle.fd(40)
12     drawGap()
13     turtle.right(90)
14 
15 def drawDigit(d):  # 根据数字绘制七段数码管
16     drawLine(True) if d in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
17     drawLine(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
18     drawLine(True) if d in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
19     drawLine(True) if d in [0, 2, 6, 8] else drawLine(False)
20     turtle.left(90)
21     drawLine(True) if d in [0, 4, 5, 6, 8, 9] else drawLine(False)
22     drawLine(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
23     drawLine(True) if d in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
24     turtle.left(180)
25     turtle.penup()
26     turtle.fd(20)
27 
28 def drawDate(date):
29     turtle.pencolor("red")
30     for i in date:
31         if i == '/':
32             turtle.write('年', font=("Arial", 18, "normal"))
33             turtle.pencolor('green')
34             turtle.fd(40)
35         elif i == '!':
36             turtle.write('月', font=("Arial", 18, "normal"))
37             turtle.pencolor('orange')
38             turtle.fd(40)
39         elif i == '@':
40             turtle.write('日', font=("Arial", 18, "normal"))
41             turtle.pencolor('yellow')
42             turtle.fd(40)
43         elif i == '+':
44             turtle.write('时', font=("Arial ", 18, "normal"))
45             turtle.pencolor("pink")
46             turtle.fd(40)
47         elif i == '-':
48             turtle.write('分', font=("Arial", 18, "normal"))
49             turtle.pencolor("blue")
50             turtle.fd(40)
51         elif i == '*':
52             turtle.write('秒', font=("Arial", 18, "normal"))
53             turtle.pencolor('red')
54             turtle.fd(40)
55         else:
56             drawDigit(eval(i))
57     turtle.exitonclick()
58 
59 def main():
60     turtle.setup(800, 350, 0, 200)
61     turtle.penup()
62     turtle.fd(-350)
63     turtle.pensize(5)
64     drawDate(datetime.datetime.now().strftime('%Y/%m!%d@%H+%M-%S*'))
65     turtle.hideturtle()
66 
67 main()

 

 学号尾号5,画出年月日小时分秒

标签:turtle,False,drawLine,40,else,数码管,时间,fd,绘制
From: https://www.cnblogs.com/1234567yuanlv/p/16966662.html

相关文章