-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinClock.py
More file actions
77 lines (65 loc) · 1.51 KB
/
binClock.py
File metadata and controls
77 lines (65 loc) · 1.51 KB
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
72
73
74
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# binClock.py
#
# Copyright 2013 ryan <ryan@porta-penguin>
#
# This one's going out to my chums Ben, Michael, and The Girl!
# Last revision: 07/06/10
import os
import platform
import time
from datetime import datetime
binGrid = [[0]*4 for i in range(6)]
grid = [[0]*4 for i in range(6)]
def main():
while True:
tick()
return 0
def tick():
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
for i in range(0,6):
timeArray = []
hour = datetime.now().hour
hourTens = getBin(hour / 10)
hourOnes = getBin(hour % 10)
mint = datetime.now().minute
mintTens = getBin(mint / 10)
mintOnes = getBin(mint % 10)
sec = datetime.now().second
secTens = getBin(sec / 10)
secOnes = getBin(sec % 10)
timeArray.extend((hourTens, hourOnes, mintTens, mintOnes, secTens, secOnes))
for j in range(0,4):
binGrid[i][j] = timeArray[i][j]
buildDisplay()
printGrid()
time.sleep(1)
def printGrid():
grid[0][0] = ' '
grid[0][1] = ' '
grid[2][0] = ' '
grid[4][0] = ' '
for i in range(0,4):
print str(2**(3-i)) + ' >',
for j in range(0,6):
print grid[j][i],
print '\n'
#print '---------------------------'
print ' ^ ^ ^ ^ ^ ^'
print ' H h M m S s'
def getBin(x):
return (bin(x)[2:]).zfill(4)
def buildDisplay():
for i in range(0,6):
for j in range(0,4):
if binGrid[i][j] == '1':
grid[i][j] = '[X]'
else:
grid[i][j] = '[ ]'
if __name__ == '__main__':
main()