Skip to content
This repository was archived by the owner on Oct 28, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .site/pyscript/thumbnails/car_cluster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/car_cluster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions lib/examples/car_cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def __init__(self, vehicle, scr=None):
bg=BG,
unit="mph",
caption="0.0 mi",
minor=5,
major=20,
)
self.speed.set_pos(W * 27 // 100 - size // 2, cy - size // 2)
self.power = Ring(
Expand All @@ -240,6 +242,8 @@ def __init__(self, vehicle, scr=None):
bg=BG,
unit="kW",
caption="3.7 mi/kWh",
minor=10,
major=50,
)
self.power.set_pos(W * 73 // 100 - size // 2, cy - size // 2)

Expand Down
24 changes: 16 additions & 8 deletions lib/examples/car_cluster/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def __init__(
sweep=270,
unit="",
caption="",
ticks=54,
major_every=6,
minor=None,
major=None,
):
self.size = size
self.stops = stops
Expand Down Expand Up @@ -141,7 +141,13 @@ def __init__(
self._buf = lv.draw_buf_create(size, size, lv.COLOR_FORMAT.ARGB8888, 0)
self.canvas.set_draw_buf(self._buf)
self.canvas.fill_bg(_color(0x000000), lv.OPA.TRANSP)
self._paint(track, ticks, major_every)
# Ticks sit at round values: one every ``minor`` units, a longer one
# every ``major``. Left unset, the dial gets ten major divisions.
if minor is None:
minor = self.vmax / 50.0
if major is None:
major = self.vmax / 10.0
self._paint(track, minor, major)

# The cover: the empty part of the track, painted over the sweep.
self.cover = lv.arc(self.obj)
Expand Down Expand Up @@ -216,7 +222,7 @@ def __init__(

# -- art ----------------------------------------------------------------

def _paint(self, track, ticks, major_every):
def _paint(self, track, minor, major):
layer = lv.layer_t()
self.canvas.init_layer(layer)
cx, cy, r = self.cx, self.cy, self.radius
Expand Down Expand Up @@ -263,14 +269,16 @@ def _paint(self, track, ticks, major_every):
line.round_start = True
line.round_end = True
r_out = self.size // 2 - 2
ticks = int(round(self.vmax / minor))
per_major = max(1, int(round(major / minor)))
for i in range(ticks + 1):
t = i / ticks
a = math.radians(self.start + self.sweep * t)
major = i % major_every == 0
length = max(8, self.size // 24) if major else max(4, self.size // 48)
line.width = 3 if major else 2
is_major = i % per_major == 0
length = max(8, self.size // 24) if is_major else max(4, self.size // 48)
line.width = 3 if is_major else 2
line.color = _color(gradient_at(self.stops, t))
line.opa = 230 if major else 110
line.opa = 230 if is_major else 110
line.p1 = lv.point_precise_t({"x": cx + math.cos(a) * r_out, "y": cy + math.sin(a) * r_out})
line.p2 = lv.point_precise_t(
{"x": cx + math.cos(a) * (r_out - length), "y": cy + math.sin(a) * (r_out - length)}
Expand Down
Loading