@@ 1,4 1,3 @@
-import os
import requests
import simdjson
from PIL import Image, ImageDraw
@@ 23,10 22,10 @@ LON_RANGE = MAX_LON - MIN_LON
LAT_RANGE = MAX_LAT - MIN_LAT
WIDTH = 648
-HEIGHT = int(1.5 * WIDTH * LAT_RANGE / LON_RANGE)
+HEIGHT = 480
+MAP_HEIGHT = int(1.5 * WIDTH * LAT_RANGE / LON_RANGE)
-# L = grayscale 8-bit
-SCREEN = Image.new("L", (WIDTH, HEIGHT), color=255)
+SCREEN = Image.new("1", (WIDTH, HEIGHT), color=1)
DRAW = ImageDraw.Draw(SCREEN)
MOVING = Image.open("moving.png")
STOPPED = Image.open("stopped.png")
@@ 45,7 44,7 @@ out geom qt;
def latlon_to_xy(lat: float, lon: float) -> (float, float):
x = WIDTH * (lon - MIN_LON) / LON_RANGE
- y = HEIGHT - (HEIGHT * (lat - MIN_LAT) / LAT_RANGE)
+ y = min(MAP_HEIGHT, MAP_HEIGHT - (MAP_HEIGHT * (lat - MIN_LAT) / LAT_RANGE))
return x, y
@@ 55,7 54,7 @@ def draw_coastlines(coastlines):
coords = item["coordinates"]
for lon, lat in coords:
screen_coords.append(latlon_to_xy(lat, lon))
- DRAW.line(screen_coords, fill=200, width=1, joint="curve")
+ DRAW.line(screen_coords, width=1, joint="curve")
for sequence in coastlines["elements"]:
item = sequence["geometry"]
@@ 68,9 67,10 @@ def draw_coastlines(coastlines):
else:
raise
+ DRAW.line([(0, MAP_HEIGHT), (WIDTH, MAP_HEIGHT)])
+
def paste(src: Image, dest_x, dest_y):
- grayscale_version = src.convert("L")
center_x = src.width / 2
center_y = src.height / 2
@@ 80,10 80,7 @@ def paste(src: Image, dest_x, dest_y):
# PIL alpha compositing cannot be used directly since the images aren't both RGBA.
# this copies a pixel value to the screen only if the alpha channel in the original is nontransparent.
if alpha > 0:
- DRAW.point(
- (dest_x + x - center_x, dest_y + y - center_y),
- fill=grayscale_version.getpixel((x, y)),
- )
+ DRAW.point((dest_x + x - center_x, dest_y + y - center_y))
def main():
@@ 116,11 113,11 @@ def main():
else:
label += f" {boat['lastdock'][0]}->{boat['aterm'][0]} ETA {boat['eta']}"
paste(MOVING.rotate(-boat["head"]), x, y)
- DRAW.point((x, y), fill=0)
+ DRAW.point((x, y))
DRAW.text((x, y), label, anchor="mm")
- SCREEN.save("map.png", "PNG")
+ SCREEN.save("map.bmp", "BMP")
if __name__ == "__main__":
- main()>
\ No newline at end of file
+ main()