-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisney_countdown.py
65 lines (45 loc) · 1.65 KB
/
disney_countdown.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
#!/usr/bin/env python
import colorsys
import signal
import time
import datetime
from sys import exit
from PIL import Image, ImageDraw, ImageFont
import unicornhathd
day_of_trip = 27
month_of_trip = 10
year_of_trip = 2017
time_until = datetime.datetime(year_of_trip, month_of_trip, day_of_trip) - datetime.datetime.now()
TEXT = str((time_until.days+1)) + " DAYS TO GO"
FONT = ("/usr/share/fonts/truetype/freefont/FreeSansBold.ttf", 12)
unicornhathd.rotation(90)
unicornhathd.brightness(1)
width, height = unicornhathd.get_shape()
img = Image.open('mickey.png')
text_x = width
text_y = 2
font_file, font_size = FONT
font = ImageFont.truetype(font_file, font_size)
text_width, text_height = font.getsize(TEXT)
text_width += width + text_x + 32
image = Image.new("RGB", ((text_width),max(16, text_height)), (0,0,0))
draw = ImageDraw.Draw(image)
draw.bitmap((text_x, 0), img)
draw.text(((text_x*2), text_y), TEXT, fill=(255, 255, 255), font=font)
draw.bitmap(((text_width-(text_x*2)), 0), img)
try:
while True:
for scroll in range(text_width - width):
for x in range(width):
for y in range(height):
pixel = image.getpixel((x+scroll, y))
br, bg, bb = [int(n * 255) for n in colorsys.hsv_to_rgb((x + scroll) / float(text_width), 1.0, 1.0)]
r, g, b = [float(n / 255.0) for n in pixel]
r = int(br * r)
g = int(bg * g)
b = int(bb * b)
unicornhathd.set_pixel(width-1-x, y, r, g, b)
unicornhathd.show()
time.sleep(0.01)
except KeyboardInterrupt:
unicornhathd.off()