raylib: cleanup experimental mode gradient color calculations (#36035)

* dfebug

* simplify

* come on man
pull/35902/merge
Shane Smiskol 1 day ago committed by GitHub
parent 63441c048c
commit 8320934d91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      selfdrive/ui/onroad/model_renderer.py

@ -211,12 +211,11 @@ class ModelRenderer(Widget):
lin_grad_point = 1 - (track_y - self._rect.y) / self._rect.height lin_grad_point = 1 - (track_y - self._rect.y) / self._rect.height
# speed up: 120, slow down: 0 # speed up: 120, slow down: 0
path_hue = max(min(60 + self._acceleration_x[i] * 35, 120), 0) path_hue = np.clip(60 + self._acceleration_x[i] * 35, 0, 120)
path_hue = int(path_hue * 100 + 0.5) / 100
saturation = min(abs(self._acceleration_x[i] * 1.5), 1) saturation = min(abs(self._acceleration_x[i] * 1.5), 1)
lightness = self._map_val(saturation, 0.0, 1.0, 0.95, 0.62) lightness = np.interp(saturation, [0.0, 1.0], [0.95, 0.62])
alpha = self._map_val(lin_grad_point, 0.75 / 2.0, 0.75, 0.4, 0.0) alpha = np.interp(lin_grad_point, [0.75 / 2.0, 0.75], [0.4, 0.0])
# Use HSL to RGB conversion # Use HSL to RGB conversion
color = self._hsla_to_color(path_hue / 360.0, saturation, lightness, alpha) color = self._hsla_to_color(path_hue / 360.0, saturation, lightness, alpha)
@ -409,13 +408,6 @@ class ModelRenderer(Widget):
return np.vstack((left_screen.T, right_screen[:, ::-1].T)).astype(np.float32) return np.vstack((left_screen.T, right_screen[:, ::-1].T)).astype(np.float32)
@staticmethod
def _map_val(x, x0, x1, y0, y1):
x = np.clip(x, x0, x1)
ra = x1 - x0
rb = y1 - y0
return (x - x0) * rb / ra + y0 if ra != 0 else y0
@staticmethod @staticmethod
def _hsla_to_color(h, s, l, a): def _hsla_to_color(h, s, l, a):
rgb = colorsys.hls_to_rgb(h, l, s) rgb = colorsys.hls_to_rgb(h, l, s)

Loading…
Cancel
Save