1 Star 0 Fork 0

chuan / py程序语言设计

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
time.py 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
"""
绘制时间(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()
Python
1
https://gitee.com/chuancode/py-programming-language-design.git
git@gitee.com:chuancode/py-programming-language-design.git
chuancode
py-programming-language-design
py程序语言设计
master

搜索帮助