Last active
May 24, 2021 10:48
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.factory import Factory | |
from kivy.properties import NumericProperty | |
from kivy.clock import Clock | |
KV = ''' | |
#:import rgba kivy.utils.rgba | |
#:import cos math.cos | |
#:import sin math.sin | |
#:import pi math.pi | |
#:import chain itertools.chain | |
#:import time time.time | |
<Hand@Widget>: | |
length: 300 | |
hand_width: 20 | |
color: '#FFFFFF' | |
angle: 0 | |
canvas: | |
Color: | |
rgba: rgba(self.color) | |
PushMatrix | |
Rotate: | |
origin: self.center | |
angle: 90 + self.angle | |
SmoothLine: | |
width: self.hand_width or 1 | |
cap: 'square' | |
points: | |
( | |
self.center_x - self.length * .1, | |
self.center_y, | |
self.center_x + self.length * .9, | |
self.center_y | |
) | |
PopMatrix | |
FloatLayout: | |
clock_size: min(*self.size) / 2.5 | |
canvas.before: | |
Color: | |
rgba: rgba('#FFFFFF') | |
Ellipse: | |
size: 2 * (self.clock_size or 0), 2 * (self.clock_size or 0) | |
pos: self.center_x - (self.clock_size or 0), self.center_y - (self.clock_size or 0) | |
Color: | |
rgba: rgba('#108AC7') | |
Point: | |
pointsize: 2 | |
points: | |
list(chain(*[( | |
self.center_x + cos(2 * pi * angle / 60) * .95 * (self.clock_size or 0), | |
self.center_y + sin(2 * pi * angle / 60) * .95 * (self.clock_size or 0) | |
) | |
for angle in range(60) | |
])) | |
Color: | |
rgba: rgba('#177BAD') | |
Point: | |
pointsize: 5 | |
points: | |
list(chain(*[( | |
self.center_x + cos(2 * pi * angle / 12) * .9 * (self.clock_size or 0), | |
self.center_y + sin(2 * pi * angle / 12) * .9 * (self.clock_size or 0) | |
) | |
for angle in range(12) | |
])) | |
Hand: | |
angle: app.hours | |
hand_width: 10 | |
length: (root.clock_size or 0) / 2 | |
color: '#FA2E41' | |
Hand: | |
angle: app.minutes | |
hand_width: 8 | |
length: (root.clock_size or 0) / 3 | |
color: '#AD0E1E' | |
Hand: | |
seconds: app.seconds | |
div_mod: divmod(self.seconds or 0, 1) | |
angle: - (360/60) * (1 * (self.div_mod[0]) + 1 - (((1 - self.div_mod[1] / 1) ** 16) * 1)) if self.div_mod else 0 | |
hand_width: 5 | |
length: (root.clock_size or 0) | |
color: '#FBF546' | |
''' | |
class Application(App): | |
hours = NumericProperty() | |
minutes = NumericProperty() | |
seconds = NumericProperty() | |
def build(self): | |
Clock.schedule_interval(self.update_time, 0) | |
return Builder.load_string(KV) | |
def update_time(self, dt): | |
now = datetime.now() | |
self.hours = now.hour | |
self.minutes = now.minute | |
self.seconds = now.second + now.microsecond / 1000_000 | |
if __name__ == "__main__": | |
Application().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment