1 Star 0 Fork 0

张佳琛/201911921张佳琛_从代码到实物期末选题_2022-1-15_1-12进制时钟

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
二进制时钟.py 9.56 KB
一键复制 编辑 原始数据 按行查看 历史
张佳琛 提交于 2022-06-06 16:55 . 代码文件
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pygame
import sys
import time
class Clock:
screen=pygame.display.set_mode((640, 480))
def __init__(self):
pygame.init()
pygame.display.set_caption('Binary Clock')
self.display()
def display(self):
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT:
exit(0)
elif e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
exit(0)
self.capture()
self.logic()
pygame.display.flip()
time.sleep(0.5)
def capture(self):
#Hour
#Row1
pygame.draw.circle(self.screen, (255, 255, 255), (70, 400), 30 ) # 颜色(白色) 位置 直径
pygame.draw.circle(self.screen, (255, 255, 255), (70, 300), 30 )
#Row2
pygame.draw.circle(self.screen, (255, 255, 255), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (170, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (170, 200), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (170, 100), 30 )
#Min
#Row1
pygame.draw.circle(self.screen, (255, 255, 255), (270, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (270, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (270, 200), 30 )
#Row2
pygame.draw.circle(self.screen, (255, 255, 255), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (370, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (370, 200), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (370, 100), 30 )
#Sec
#Row1
pygame.draw.circle(self.screen, (255, 255, 255), (470, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (470, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (470, 200), 30 )
#Row2
pygame.draw.circle(self.screen, (255, 255, 255), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (570, 300), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (570, 200), 30 )
pygame.draw.circle(self.screen, (255, 255, 255), (570, 100), 30 )
def logic(self):
#Hour
if int(time.asctime( time.localtime(time.time()) )[11])==1:# 表示小时的第一位 0,1,2三种
pygame.draw.circle(self.screen, (255, 0, 0), (70, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[11])==2:
pygame.draw.circle(self.screen, (255, 0, 0), (70, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==1:# 表示小时的第二位 0-9共10种
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==2:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==5:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==6:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==7:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==8:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 100), 30 )
if int(time.asctime( time.localtime(time.time()) )[12])==9:
pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (170, 100), 30 )
#Min
if int(time.asctime( time.localtime(time.time()) )[14])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==2:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[14])==5:
pygame.draw.circle(self.screen, (255, 0, 0), (270, 200), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==2:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==5:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==6:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==7:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==8:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 100), 30 )
if int(time.asctime( time.localtime(time.time()) )[15])==9:
pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (370, 100), 30 )
#Sec
if int(time.asctime( time.localtime(time.time()) )[17])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==2:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[17])==5:
pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (470, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==1:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==2:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==3:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==4:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==5:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==6:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==7:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==8:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 100), 30 )
if int(time.asctime( time.localtime(time.time()) )[18])==9:
pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
pygame.draw.circle(self.screen, (255, 0, 0), (570, 100), 30 )
if __name__ == "__main__":Clock()
# In[ ]:
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/izhang-jiachen/Binary_Clock.git
git@gitee.com:izhang-jiachen/Binary_Clock.git
izhang-jiachen
Binary_Clock
201911921张佳琛_从代码到实物期末选题_2022-1-15_1-12进制时钟
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385