-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (60 loc) · 2.37 KB
/
main.py
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
# -*- coding: utf-8 -*-
from random import randint
from asciimatics.screen import Screen
import math
from time import sleep
from datetime import datetime as dt
from sys import exit
def drawCircle(screen, max_circle, x_cen, y_cen):
# font_ratio = 2;
for i in range(0,60):
y =math.sin(i*math.pi/180*6)*max_circle+y_cen
x =math.cos(i*math.pi/180*6)*2*max_circle+x_cen
screen.print_at(u'◉',round(x),round(y))
def drawHand(screen, rad, x_cen, y_cen, unit, chara):
if(unit == "second"):
ang = math.radians(dt.now().second*6-90)
angOld = math.radians((dt.now().second-1)*6-90)
elif (unit == "minute"):
ang = math.radians(dt.now().minute*6-90)
angOld = math.radians((dt.now().minute-1)*6-90)
else:
ang = math.radians((dt.now().hour/24*360-90))
angOld = math.radians((dt.now().hour-1)/24*360-90)
x_pos_old = round(x_cen + rad*math.cos(angOld)*2)
y_pos_old = round(y_cen + rad*math.sin(angOld))
screen.move(x_cen,y_cen)
screen.draw(x_pos_old, y_pos_old, ' ',7, 0,True)
x_pos = round(x_cen + rad*math.cos(ang)*2)
y_pos = round(y_cen +rad*math.sin(ang))
screen.move(x_cen,y_cen)
screen.draw(x_pos, y_pos, chara,7, 0,True)
def killProgram(screen):
ev = screen.get_key()
if ev in (ord('Q'), ord('q')):
exit(0)
def defineParams(screen):
dimTup = screen.dimensions
y_cen = round(dimTup[0]/2)
x_cen = round(dimTup[1]/2)
if(x_cen/2 > y_cen):
max_radius = round(y_cen*.75)
else:
max_radius = round (x_cen*.75/2)
dimData = (dimTup[0],dimTup[1],x_cen, y_cen, max_radius)
return dimData
def analogScreen(screen):
while (screen.has_resized() == False):
dimData = defineParams(screen)
drawCircle(screen,dimData[4], dimData[2], dimData[3])
drawHand(screen, round(dimData[4])-1, dimData[2], dimData[3], "second",u'⬥')
drawHand(screen, round(dimData[4])/1.5, dimData[2], dimData[3], "minute",'m')
drawHand(screen, round(dimData[4])/2.5, dimData[2], dimData[3], "hour",'h')
screen.print_at(u'◉',dimData[2],dimData[3])
screen.print_at("24 Hour Clock",dimData[2]-4,dimData[3]-dimData[4]-1)
screen.print_at(str(dt.now().time()),dimData[2]-4,dimData[3]+dimData[4]+1)
screen.refresh()
killProgram(screen)
sleep(0.1)
while True:
Screen.wrapper(analogScreen)