diff --git a/.gitignore b/.gitignore index a348e50..8bd2c3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ /__pycache__/ + +# Effie's python environment +/bin +/include +/lib +/lib64 +pyvenv.cfg \ No newline at end of file diff --git a/NETWORKSANS-2019-REGULAR.TTF b/NETWORKSANS-2019-REGULAR.TTF new file mode 100644 index 0000000..5f8b4a3 Binary files /dev/null and b/NETWORKSANS-2019-REGULAR.TTF differ diff --git a/__main__.py b/__main__.py index 4062964..f75cdc8 100644 --- a/__main__.py +++ b/__main__.py @@ -9,64 +9,47 @@ BLACK = 0x000000 # 00 BGR WHITE = 0xffffff # 01 YELLOW = 0x00ffff # 10 RED = 0x0000ff # 11 -font18 = ImageFont.truetype('Font.ttc', 18) -font24 = ImageFont.truetype('Font.ttc', 24) -font40 = ImageFont.truetype('Font.ttc', 40) -font64 = ImageFont.truetype('Font.ttc', 64) -font100 = ImageFont.truetype('Font.ttc', 100) +fontmm = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 20) +font24 = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 24) +font42 = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 42) +font64 = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 64) +fonttime = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 92) image = Image.new('RGB', (800, 480), WHITE) draw = ImageDraw.Draw(image) -# Date/time + +# Backing image +with Image.open('ui test 2.png').convert('RGBA') as bg: + image.paste(bg, (0, 0)) + +# Time now = datetime.now() -draw.text((10, 480-10-64), f'{now:%y/%m/%d}', font=font64, fill=BLACK) -draw.text((10, 480-10-64-10-100), f'{now:%I:%M}', font=font100, fill=BLACK) +draw.text((-3, 480-3), f'{now:%H:%M}', font=fonttime, anchor="ls", fill=WHITE) -# TODO: weather -draw.text((10, 10), '?mm', font=font64, fill=BLACK) -draw.text((10, 10+64), '20°', font=font100, fill=BLACK) -draw.text((10, 10+64+100), '6° - 24°', font=font64, fill=BLACK) +# Date +dateday = f'{now:%d}' +draw.text((-3, 320), dateday, font=font64, anchor="ls", fill=WHITE) +datedaylength = draw.textlength(dateday, font=font64) +draw.text((datedaylength + 5, 320), f'{now:%b}', font=font64, anchor="lt", fill=WHITE) -# Bus -y = 0 -with Image.open('icon_bus.png') as icon: - image.paste(scale_to_height(icon), (230, y+50)) -draw.polygon((200, 0, 475, 0, 475, 50, 212.5, 50), fill=BLACK) -draw.text((215, y+5+16), 'Camberwell', font=font24, fill=WHITE) -draw.text((400, y+5), '612 S', font=font40, fill=WHITE, anchor='ma') -draw.text((400, y+55), '15', font=font64, fill=BLACK, anchor='ma') -draw.text((550, y+5), '612 N', font=font40, fill=BLACK, anchor='ma') -draw.text((550, y+55), '5', font=font64, fill=BLACK, anchor='ma') -draw.text((700, y+5), '766 N', font=font40, fill=BLACK, anchor='ma') -draw.text((700, y+55), '20', font=font64, fill=BLACK, anchor='ma') +# Temperature +temp = 6 +temphigh = 12 +draw.text((-3, 200), f'{temp}°', font=font64, anchor="ls", fill=WHITE) +draw.text((123, 237), f'{temphigh}', font=font42, anchor="ms", fill=WHITE) -# Train -y = 160 -with Image.open('icon_train.png') as icon: - image.paste(scale_to_height(icon), (280, y+50)) -draw.polygon((240, 160, 595, 160, 595, 210, 252.5, 210), fill=BLACK) -draw.text((255, y+5+16), 'City', font=font24, fill=WHITE) -draw.text((400, y+5), 'Express', font=font40, fill=WHITE, anchor='ma') -draw.text((400, y+55), '15', font=font64, fill=BLACK, anchor='ma') -draw.text((550, y+5), 'All', font=font40, fill=WHITE, anchor='ma') -draw.text((550, y+55), '5', font=font64, fill=BLACK, anchor='ma') -draw.text((700, y+5), 'Outbound', font=font40, fill=BLACK, anchor='ma') -draw.text((700, y+55), '20', font=font64, fill=BLACK, anchor='ma') - -# Tram (y=320 to 470) -y = 320 -with Image.open('icon_tram.png') as icon: - image.paste(scale_to_height(icon), (310, y+50)) -draw.polygon((280, 320, 800, 320, 800, 370, 292.5, 370), fill=BLACK) -draw.text((295, y+5+16), 'City', font=font24, fill=WHITE) -draw.text((550, y+5), '109', font=font40, fill=WHITE, anchor='ma') -draw.text((550, y+55), '7', font=font64, fill=BLACK, anchor='ma') -draw.text((700, y+5), '70', font=font40, fill=WHITE, anchor='ma') -draw.text((700, y+55), '14', font=font64, fill=BLACK, anchor='ma') - -# Line between left and right -draw.line((200, 0, 400, 800), fill=BLACK) +# Rainfall +rainfall = 3 +rainthreshold = 5 +if rainfall > rainthreshold: + rainimgpath = 'rain.png' +else: + rainimgpath = 'sun.png' +draw.text((40, 0), f'{rainfall}', font=font64, anchor="mt") +with Image.open(rainimgpath) as rainimg: + image.paste(rainimg,mask=rainimg) +draw.text((40, 55), f'mm', font=fontmm, anchor="mt") image.save('test_before_palette.png') @@ -74,8 +57,8 @@ image.save('test_before_palette.png') pal_image = Image.new('P', (1, 1)) pal_image.putpalette((0x00,0x00,0x00, 0xff,0xff,0xff, 0xff,0xff,0x00, 0xff,0x00,0x00) + (0x00,0x00,0x00)*252) # Convert the source image to the 4 colors, dithering if needed -image_4color = image.quantize(palette=pal_image) -image_4color.save('test.png') +image_4color = image.quantize(palette=pal_image, dither=Image.NONE) +image_4color.save('test_after_palette.png') show_on_screen = False if show_on_screen: diff --git a/rain.png b/rain.png new file mode 100644 index 0000000..6c530cb Binary files /dev/null and b/rain.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..73259b7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pillow==11.2.1 diff --git a/sun.png b/sun.png new file mode 100644 index 0000000..89704f2 Binary files /dev/null and b/sun.png differ diff --git a/test_after_palette.png b/test_after_palette.png new file mode 100644 index 0000000..b6e3e18 Binary files /dev/null and b/test_after_palette.png differ diff --git a/test_before_palette.png b/test_before_palette.png index 342988a..4ee664f 100644 Binary files a/test_before_palette.png and b/test_before_palette.png differ