Compare commits

...

4 Commits

Author SHA1 Message Date
Florin Tobler
9f46b10916 fix seconds 2022-07-29 13:24:27 +02:00
Florin Tobler
37baca6fef updated gitignore 2022-07-28 17:03:40 +02:00
Florin Tobler
a0baee69f8 add mirroring 2022-07-28 17:03:21 +02:00
Florin Tobler
64e6d7242c adjust clock face 2022-07-28 17:01:44 +02:00
3 changed files with 10 additions and 4 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*.png *.png
*.pyc

View File

@@ -5,6 +5,8 @@ from PIL import Image
from PIL import ImageDraw from PIL import ImageDraw
from PIL import ImageFont from PIL import ImageFont
mirror = False
def rgb(r=0, g=None, b=None): def rgb(r=0, g=None, b=None):
if g == None: if g == None:
@@ -19,10 +21,12 @@ def rrc(tuple, center, angle):
cos = math.cos(angle) cos = math.cos(angle)
tpl = (tuple[0] - center[0], tuple[1] - center[1]) tpl = (tuple[0] - center[0], tuple[1] - center[1])
tpl = tuple tpl = tuple
if mirror:
cos = -cos
return (int(tpl[0] * sin + tpl[1] * cos + center[0]), int(-tpl[0] * cos + tpl[1] * sin + center[1])) return (int(tpl[0] * sin + tpl[1] * cos + center[0]), int(-tpl[0] * cos + tpl[1] * sin + center[1]))
def draw_clock(size=(800, 480), pixelformat="RGBA", r=210, aliasing=None): def draw_clock(size=(800, 480), pixelformat="RGBA", r=230, aliasing=None):
if aliasing != None: if aliasing != None:
size = (size[0] * aliasing, size[1] * aliasing) size = (size[0] * aliasing, size[1] * aliasing)
r *= aliasing r *= aliasing
@@ -37,7 +41,7 @@ def draw_clock(size=(800, 480), pixelformat="RGBA", r=210, aliasing=None):
for i12 in range(12): for i12 in range(12):
for i5 in range(5): for i5 in range(5):
angle = (i12 * 5 + i5) / 60 * 2 * math.pi angle = (i12 * 5 + i5) / 60 * 2 * math.pi
len = r * 0.93 if i5 == 0 else r * 0.97 len = r * 0.85 if i5 == 0 else r * 0.95
thick = int((5 if i5 == 0 else 2) * r/180) thick = int((5 if i5 == 0 else 2) * r/180)
sin = math.sin(angle) sin = math.sin(angle)
cos = math.cos(angle) cos = math.cos(angle)
@@ -56,7 +60,7 @@ def draw_clock(size=(800, 480), pixelformat="RGBA", r=210, aliasing=None):
draw.line([rrc((+base, r * 0.2), center, angle), rrc((0, -r * 0.95), center, angle), rrc((-base, r * 0.2), center, angle)], fill=rgb(1), width=int(thick)) draw.line([rrc((+base, r * 0.2), center, angle), rrc((0, -r * 0.95), center, angle), rrc((-base, r * 0.2), center, angle)], fill=rgb(1), width=int(thick))
#draw second pointer #draw second pointer
angle = (now.second + now.microsecond / 1000000) / 60 * 2 * math.pi / 2 + math.pi / 2 angle = (now.second + now.microsecond / 1000000) / 60 * 2 * math.pi + math.pi / 2
thick = 4*r/180 thick = 4*r/180
draw.line([rrc((0, r * 0.3), center, angle), rrc((0, -r * 0.8), center, angle)], fill=rgb(1, 0, 0), width=int(thick)) draw.line([rrc((0, r * 0.3), center, angle), rrc((0, -r * 0.8), center, angle)], fill=rgb(1, 0, 0), width=int(thick))
e_center = rrc((0, -r * 0.8), center, angle) e_center = rrc((0, -r * 0.8), center, angle)

View File

@@ -4,6 +4,7 @@ import time
def main(): def main():
clock_pillow.mirror = True
fb = Framebuffer(device_no=0) fb = Framebuffer(device_no=0)
while True: while True:
img = clock_pillow.draw_clock(pixelformat="RGBA", aliasing=None) img = clock_pillow.draw_clock(pixelformat="RGBA", aliasing=None)