脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python绘制数码晶体管日期

Python绘制数码晶体管日期

2021-09-06 00:13一个超会写Bug的安太狼 Python

这篇文章主要为大家详细介绍了Python绘制数码晶体管日期,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Python绘制数码晶体管日期的具体代码,供大家参考,具体内容如下

源码:

drawLine(draw) 画一条线
drawDight(dight) 画一个数字
drawDate(date) 画一组数字

代码:

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

效果图:

Python绘制数码晶体管日期

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/m0_46278037/article/details/113836545

延伸 · 阅读

精彩推荐