added SpeedMapDisplay
This commit is contained in:
parent
c0063a5d75
commit
68a9d853c5
41
speed_map_display.py
Normal file
41
speed_map_display.py
Normal file
@ -0,0 +1,41 @@
|
||||
import pygame
|
||||
|
||||
from map_display import MapDisplay
|
||||
from path import Path
|
||||
|
||||
|
||||
class SpeedMapDisplay(MapDisplay):
|
||||
def __init__(self,
|
||||
surf: pygame.Surface,
|
||||
min_lat: float,
|
||||
max_lat: float,
|
||||
min_lon: float,
|
||||
max_lon: float,
|
||||
min_speed_col: tuple[int, int, int],
|
||||
max_speed_col: tuple[int, int, int],
|
||||
segment_threshold: float):
|
||||
super().__init__(surf, min_lat, max_lat, min_lon, max_lon)
|
||||
self.min_speed_col: tuple[int, int, int] = min_speed_col
|
||||
self.max_speed_col: tuple[int, int, int] = max_speed_col
|
||||
self.segment_threshold: float = segment_threshold
|
||||
|
||||
def draw_path(self, path: Path) -> None:
|
||||
colors = []
|
||||
min_speed = min(path.extra_data)
|
||||
max_speed = max(path.extra_data)
|
||||
|
||||
colors = list(map(lambda s: self.interpolate_color(s, min_speed, max_speed), path.extra_data))
|
||||
|
||||
self.draw_colored_path(path, colors)
|
||||
|
||||
def interpolate_color(self, speed: float, min_speed: float, max_speed: float) -> tuple[int, int, int]:
|
||||
r_span = self.max_speed_col[0] - self.min_speed_col[0]
|
||||
g_span = self.max_speed_col[1] - self.min_speed_col[1]
|
||||
b_span = self.max_speed_col[2] - self.min_speed_col[2]
|
||||
|
||||
f = (speed - min_speed) / (max_speed - min_speed)
|
||||
r = int(r_span * f + self.min_speed_col[0])
|
||||
g = int(g_span * f + self.min_speed_col[1])
|
||||
b = int(b_span * f + self.min_speed_col[2])
|
||||
|
||||
return r, g, b
|
Loading…
Reference in New Issue
Block a user