代码拉取完成,页面将自动刷新
"""
绘制时间(2020-09-13 09:43:43),日月为不同函数
1, 读取时间转换为年月日形式
2,绘制年月日
调用函数绘制一个数字
每次绘制七段中的一笔
绘制整个数字
检测到年绘制
....
"""
import time
import turtle
def hu_time():
"""
获取系统时间转换为既定形式
2020-09-13 09:43:43
"""
t = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
return t.split()
def sug_jg(n):
"""
控制数码管每个线段的间隔
"""
turtle.penup()
turtle.fd(n)
turtle.pendown()
def huiz_x(boor, j, x):
"""
bool 值为真时向右45度绘制线
x 为线一次绘制长度, j 为线间隔宽度
否则只转向
"""
sug_jg(j)
turtle.pendown() if boor else turtle.penup()
turtle.fd(x)
sug_jg(j)
turtle.right(90)
def huiz_s(sr, j=5, x=50):
"""
在窗口内绘制输入的数字(0_9)
绘制完后画笔位置为最后一笔抹点,角度向右相对0度
"""
try:
sr = int(sr)
except:
print("huiz_s() 传入参数非数字")
huiz_x(True, j, x) if sr in [2, 3, 4, 5, 6, 8, 9] else huiz_x(False, j, x)
huiz_x(True, j, x) if sr in [0, 1, 3, 4, 5, 6, 7, 8, 9] else huiz_x(
False, j, x)
huiz_x(True, j, x) if sr in [0, 2, 3, 5, 6, 8, 9] else huiz_x(False, j, x)
huiz_x(True, j, x) if sr in [0, 2, 6, 8] else huiz_x(False, j, x)
turtle.left(90)
huiz_x(True, j, x) if sr in [0, 4, 5, 6, 8, 9] else huiz_x(False, j, x)
huiz_x(True, j, x) if sr in [0, 2, 3, 5, 6, 7, 8, 9] else huiz_x(
False, j, x)
huiz_x(True, j, x) if sr in [0, 1, 2, 3, 4, 7, 8, 9] else huiz_x(
False, j, x)
turtle.left(180)
def huiz_nf(sr):
"""
绘制传入年份格式为 xxxx-xx-xx
不检查传入格式
"""
for i in sr:
if i == '-':
turtle.pendown()
turtle.fd(15)
sug_jg(20)
else:
huiz_s(int(i))
sug_jg(20)
turtle.setup(1080, 250)
turtle.speed(10)
while True:
turtle.colormode(255)
turtle.bgcolor(176, 196, 222)
turtle.color(238, 99, 99)
turtle.width(5)
sug_jg(-520)
turtle.begin_fill()
nf = hu_time()
huiz_nf(nf[0])
# 输出小号时间
turtle.pencolor(147, 112, 219)
turtle.width(3)
sug_jg(20)
turtle.up()
turtle.left(-90)
turtle.fd(30)
turtle.left(90)
for i in nf[1]:
if i == ':':
zb = turtle.position()
turtle.penup()
turtle.goto(zb[0], zb[1] - 30) # 斜线下
turtle.pendown()
turtle.goto(zb[0] + 7, zb[1] + 30) # 斜线 角度 上
turtle.penup()
turtle.goto(zb[0] + 25, zb[1])
turtle.pendown()
else:
huiz_s(i, j=2, x=25)
sug_jg(13)
time.sleep(50)
turtle.end_fill()
time.sleep(3)
turtle.reset()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。