Python画数码晶体管日期(年月日时分秒)

源码:

 1 drawLine(draw) 画一条线
 2 drawDight(dight) 画一个数字
 3 drawDate(date) 画一组数字
 4 import turtle, time
 5 
 6 
 7 def drawLine(draw):
 8     turtle.pendown() if draw else turtle.penup()
 9     turtle.fd(40)
10     turtle.right(90)
11 
12 
13 def drawDight(dight):
14     drawLine(True) if dight in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
15     drawLine(True) if dight in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
16     drawLine(True) if dight in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
17     drawLine(True) if dight in [0, 2, 6, 8] else drawLine(False)
18     turtle.left(90)
19     drawLine(True) if dight in [0, 4, 5, 6, 8, 9] else drawLine(False)
20     drawLine(True) if dight in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
21     drawLine(True) if dight in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
22     turtle.right(180)
23     turtle.penup()
24     turtle.fd(20)
25 
26 
27 def drawDate(date):
28     turtle.pencolor("red")
29     for i in date:
30         if i == '-':
31             turtle.write('', font=("微软雅黑", 32, "normal"))
32             turtle.pencolor("green")
33             turtle.fd(80)
34         elif i == '=':
35             turtle.write('', font=("微软雅黑", 32, "normal"))
36             turtle.pencolor("blue")
37             turtle.fd(80)
38         elif i == '+':
39             turtle.write('', font=("微软雅黑", 32, "normal"))
40             turtle.pencolor("red")
41             turtle.fd(80)
42         elif i == '/':
43             turtle.write('', font=("微软雅黑", 32, "normal"))
44             turtle.pencolor("green")
45             turtle.fd(80)
46         elif i == '*':
47             turtle.write('', font=("微软雅黑", 32, "normal"))
48             turtle.pencolor("blue")
49             turtle.fd(80)
50         elif i == '.':
51             turtle.write('', font=("微软雅黑", 32, "normal"))
52             turtle.fd(80)
53         else:
54             drawDight(eval(i))
55 
56 
57 if __name__ == '__main__':
58     # turtle.setup()  我用的是pycharm,所以没有设置画布,idle下需要设置
59     turtle.penup()
60     turtle.fd(-350)
61     turtle.pensize(5)
62     turtle.speed(1000)  # 速度再大也没感觉了
63     drawDate(time.strftime('%Y-%m=%d+', time.localtime()))
64     # 这里千万不要用time.gmtime()),获取的是UTC时区(0时区)的struct_time
65     # 踩了半天坑
66 
67     turtle.right(90)
68     turtle.fd(120)
69     turtle.right(90)
70     turtle.fd(660)
71     turtle.right(180)
72     drawDate(time.strftime('%H/%M*%S.', time.localtime()))
73     turtle.hideturtle()
74     turtle.done()

 


效果图:

在这里插入图片描述
在这里插入图片描述

 

posted @ 2021-02-17 18:33  BugMiaowu2021  阅读(353)  评论(0编辑  收藏  举报