v0.89.0: Lint Oontz in three-quarter view (or head on), nodding to the bass, ten dance moves by intensity

The moves come in three tiers picked by how full the music is now against
the last ~12 s, so a build or a drop changes the move; some use the legs.
It waits standing for 10 s before sitting and sleeps at 30 s, and skipping
songs no longer sits it down.
This commit is contained in:
2026-11-06 02:41:45 -08:00
parent 2b59ea02da
commit 0cf22773e7
9 changed files with 523 additions and 172 deletions
+21 -13
View File
@@ -412,21 +412,29 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
`tests/kaleidostrobe_golden.npz` was recorded from the emulated original `tests/kaleidostrobe_golden.npz` was recorded from the emulated original
and `test_round84` holds the port to it byte for byte. and `test_round84` holds the port to it byte for byte.
- **`gui/visualizer_lint.py`** — Lint Oontz, the fifth style (Round 122, - **`gui/visualizer_lint.py`** — Lint Oontz, the fifth style (Rounds
`lint`): one line-drawn lint ball in big headphones on the panel's gray. 122–123, `lint`): one line-drawn lint ball in big headphones on the
panel's gray, in **three-quarter view** (default: face turned to our
right, the near cup seen whole, the far one clipped to what shows past
the ball) or **head on** (`visualizer_lint_head_on`, Preferences' View
combo; in `STYLE_KEYS`). The ball is filled with the panel colour so
what's behind it (legs' tops, the far arm in 3/4) is hidden.
**Stop motion**: the renderer steps at 8 fps on its own clock and **Stop motion**: the renderer steps at 8 fps on its own clock and
`advance` is True only on a step; every step re-rolls each line's wobble `advance` is True only on a step; every step re-rolls each line's wobble
(seeded by step, so one step always draws the same) and nothing is ever (seeded by step) and nothing is ever tweened. A bass onset **nods** the
tweened. A bass onset (energy `ONSET_RATIO` over its own average) dips head (rotated about the neck in 3/4; head on, the face drops) — the legs
the head and bends the knees; the arms dance only when the onset tempo no longer crouch on the bass. Busy (onset tempo ≥ `BUSY_BPM` *and* a full
is ≥ `BUSY_BPM` *and* the spectrum is full (`BUSY_FULLNESS`, calibrated spectrum) → one of `MOVES`: ten arm+leg moves in three tiers; the tier is
on pink noise vs. sparse tones), otherwise they hang. Quiet (or paused, `now` fullness (1.5 s) against `TIER_EDGES`, ±1 when `now` is `LIFT` over
`clear()`) → it **sits** after `SIT_AFTER_S` and **sleeps** after or under `lately` (12 s) — a build or a drop. A tier change that holds 2
`SLEEP_AFTER_S`. Two renderer flags the widget reads: `idles` keeps the beats switches the move; every 16 beats it may switch within the tier.
60 Hz timer running with nothing playing (fed silence, never the old Not busy: arms hang, it only nods. Quiet/nothing playing: stands, sits
song's tail) so it can fall asleep, and `black_mode` adds `MODE_BLACK` at `SIT_AFTER_S` (10), sleeps at `SLEEP_AFTER_S` (30); `clear()` does
to the colour wheel (colour → gray → black → off) — for any other style nothing, so skipping songs never sits it down. Two renderer flags the
a saved black reads as colour. No settings yet (no `STYLE_KEYS` entry). widget reads: `idles` keeps the 60 Hz timer running with nothing playing
(fed silence, never the old song's tail), and `black_mode` adds
`MODE_BLACK` to the colour wheel (colour → gray → black → off) — for any
other style a saved black reads as colour.
- **`lintunes/dj/`** + **`gui/dj_shelf.py`** — DJ mode (Round 93; View › - **`lintunes/dj/`** + **`gui/dj_shelf.py`** — DJ mode (Round 93; View ›
DJ Mode or the turntable button under BPM). The window parts **under the DJ Mode or the turntable button under BPM). The window parts **under the
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux.""" """LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.88.1" __version__ = "0.89.0"
+13 -2
View File
@@ -873,12 +873,23 @@ class PreferencesDialog(QDialog):
lint = QWidget() lint = QWidget()
form = self._viz_form(lint) form = self._viz_form(lint)
self._preset_row(form, "lint")
self._sync_delay_slider(form, "lint") self._sync_delay_slider(form, "lint")
view = QComboBox()
view.addItems(["Three-quarter", "Head on"])
view.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)
view.setCurrentIndex(int(config["visualizer_lint_head_on"])) # before connect
view.setToolTip("Turned a little to one side, one headphone cup "
"behind its head — or facing you")
view.currentIndexChanged.connect(
lambda i: self._prefs.set("visualizer_lint_head_on", i == 1))
self._viz_setters["visualizer_lint_head_on"] = (
lambda value: view.setCurrentIndex(int(bool(value))))
form.addRow("View:", view)
about = QLabel( about = QLabel(
"A ball of lint in headphones: it bobs to the bass, dances when " "A ball of lint in headphones: it bobs to the bass, dances when "
"the music is fast and full, sits down when it goes quiet and " "the music is fast and full, sits down when it goes quiet and "
"falls asleep after a while. The colour wheel adds black for it. " "falls asleep after a while. The colour wheel adds black for it.")
"No settings yet.")
about.setWordWrap(True) about.setWordWrap(True)
about.setEnabled(False) about.setEnabled(False)
form.addRow(about) form.addRow(about)
+336 -144
View File
@@ -1,34 +1,47 @@
"""Lint Oontz: a ball of lint in headphones, dancing (Round 122). """Lint Oontz: a ball of lint in headphones, dancing (Rounds 122–123).
A very rough line drawing, animated like stop motion: the renderer steps at A very rough line drawing, animated like stop motion: the renderer steps at
``FPS`` (8) on its own clock and each step is a new pose with every line ``FPS`` (8) on its own clock and each step is a new pose with every line
re-wobbled, never an in-between — no tweening. Each step costs one repaint; re-wobbled, never an in-between — no tweening. Each step costs one repaint;
the widget's 60 Hz timer only feeds it audio (silence while nothing plays: the widget's 60 Hz timer only feeds it audio (silence while nothing plays:
``idles``, so it keeps its clock and can fall asleep). ``idles``, so it keeps its clock and can sit down and fall asleep).
What the music does to it: What the music does to it:
- **bass** → the head bob. A bass onset (energy well over its own recent - **bass** → the head **nods**: on a bass onset (energy well over its own
average) dips the ball and bends the knees; between beats it springs back. recent average) the head tips forward and comes back over two steps.
- **busy** → the arms. When the beats come fast (``BUSY_BPM`` or more, Three-quarter view rotates it; head on, the face drops (a nod towards
counted from the onsets themselves) *and* the spectrum is full you can't be a rotation).
(``BUSY_FULLNESS``), every beat throws a new arm pose and the feet step. - **busy** (the onsets come at ``BUSY_BPM`` or faster *and* the spectrum is
Otherwise the arms hang and only the head bobs. full, ``BUSY_FULLNESS``) → it **dances**: one of ``MOVES``, ten arm (and
- **quiet** (or nothing playing) → it sits down after ``SIT_AFTER_S``, and leg) moves in three intensity tiers. The tier is how full the music is
after ``SLEEP_AFTER_S`` lies down to sleep (closed eyes, rising z's), now, raised a step when it is fuller than it has been lately (a drop, a
until the music comes back. build) and lowered when it thinned out. A tier that changes and holds
for two beats switches the move — a shift in the music, a new move —
and every 16 beats it may change move within the tier anyway. Not busy,
the arms hang and it only nods.
- **quiet** (or nothing playing) → it stands waiting, sits after
``SIT_AFTER_S`` and lies down to sleep after ``SLEEP_AFTER_S``, until
the music comes back. Skipping between songs never sits it down.
Two views (``visualizer_lint_head_on``): three-quarter (the default: the
face turned to one side, one headphone cup seen whole and the other behind
the ball) or head on. Same moves in both.
The lines are the colour the wheel picks — highlight, gray or black The lines are the colour the wheel picks — highlight, gray or black
(``black_mode``: this style adds black to the wheel) — on the panel's gray. (``black_mode``: this style adds black to the wheel) — on the panel's gray.
The ball is filled with the panel's colour, so what is behind it is hidden.
""" """
import math import math
from dataclasses import dataclass
import numpy as np import numpy as np
from PyQt6.QtCore import QPointF, QRectF, Qt from PyQt6.QtCore import QPointF, QRectF, Qt
from PyQt6.QtGui import QColor, QPainterPath, QPen from PyQt6.QtGui import QColor, QPainterPath, QPen, QTransform
STYLE = "lint" STYLE = "lint"
HEAD_ON_KEY = "visualizer_lint_head_on"
FPS = 8 # stop motion: a new drawing this often FPS = 8 # stop motion: a new drawing this often
STEP_S = 1.0 / FPS STEP_S = 1.0 / FPS
INSET = 3 INSET = 3
@@ -45,39 +58,89 @@ BUSY_FULLNESS = 0.28 # mean band level (0..1) of a "full" spectrum:
# mix of a few tones 0.12-0.14 # mix of a few tones 0.12-0.14
CALM_AFTER_S = 2.0 # busy has to be gone this long to stop dancing CALM_AFTER_S = 2.0 # busy has to be gone this long to stop dancing
QUIET_DB = -48.0 # RMS under this is quiet QUIET_DB = -48.0 # RMS under this is quiet
SIT_AFTER_S = 1.5 SIT_AFTER_S = 10.0 # standing, waiting for the music, until then
SLEEP_AFTER_S = 20.0 SLEEP_AFTER_S = 30.0
WAKE_AFTER_S = 0.3 WAKE_AFTER_S = 0.3
FULLNESS_BANDS = 16 FULLNESS_BANDS = 16
# Arm poses as (left, right) shoulder angles in degrees from straight down, # Intensity: how full the music is over the last ~1.5 s, against the last
# outward positive, plus each elbow's extra bend. # ~12 s. Pink noise reads 0.31 at -20 dB RMS and 0.43 at -14.
NOW_S, LATELY_S = 1.5, 12.0
TIER_EDGES = (0.34, 0.42) # below the first: tier 0; past the second: 2
LIFT = 0.05 # fuller than lately by this much: a tier up
TIER_HOLD_BEATS = 2 # a new tier must last this long to change move
SWITCH_EVERY = 16 # beats; then maybe a new move in the same tier
NOD_DEG = 15 # three-quarter: the head tips this far
NOD_DROP = 0.2 # head on: the face drops this share of r
BLINK_EVERY = 29 # steps; one closed-eye drawing each time
STAND, SIT, SLEEP = "stand", "sit", "sleep"
# An arm is (shoulder, elbow bend) in degrees: the upper arm's angle from
# straight down, outward positive (180 = straight up, past it = across the
# head or body), and the forearm's angle relative to it.
HANG = ((18, 8), (18, 8)) HANG = ((18, 8), (18, 8))
LYING = ((4, 0), (4, 0)) # asleep: arms along the body LYING = ((4, 0), (4, 0)) # asleep: arms along the body
SITTING = ((48, -20), (48, -20)) # hands down on the floor beside it SITTING = ((48, -20), (48, -20)) # hands down on the floor beside it
BLINK_EVERY = 29 # steps; one closed-eye drawing each time
STAND, SIT, SLEEP = "stand", "sit", "sleep"
DANCE = ( @dataclass(frozen=True)
((150, -30), (30, 20)), # left up class Move:
((140, -20), (140, -20)), # both up name: str
((30, 20), (150, -30)), # right up tier: int # 0 low, 1 mid, 2 high
((90, 40), (90, 40)), # both out, bent cadence: int # stop-motion steps per frame; 0 = one per beat
frames: tuple # ((left arm, right arm, legs), ...)
def _wave_frames():
"""Arms out, a wave running from the left hand through to the right."""
frames = []
for k in range(8):
p = 2 * math.pi * k / 8
left = (90 + 25 * math.sin(p), 45 * math.sin(p - 1.3))
right = (90 + 25 * math.sin(p - math.pi),
45 * math.sin(p - math.pi - 1.3))
frames.append((left, right, "wide"))
return tuple(frames)
def _windmill_frames():
frames = []
for k in range(8):
a = k * 45
frames.append((((a + 180) % 360, 0), (a, 0),
"wide" if k % 2 else "stand"))
return tuple(frames)
MOVES = (
# ---- tier 0: a bit going on ----
Move("sway", 0, 0, (((-10, 5), (40, 10), "step_r"),
((40, 10), (-10, 5), "step_l"))),
Move("snap", 0, 0, (((25, 115), (20, 30), "knee_l"),
((20, 30), (25, 115), "knee_r"))),
Move("shimmy", 0, 2, (((75, 55), (50, 55), "stand"),
((50, 55), (75, 55), "stand"))),
# ---- tier 1: going ----
Move("point", 1, 0, (((45, -110), (150, 0), "step_r"),
((45, -110), (-25, 0), "stand"),
((150, 0), (45, -110), "step_l"),
((-25, 0), (45, -110), "stand"))),
Move("wave", 1, 1, _wave_frames()),
Move("pump", 1, 0, (((40, -110), (165, 0), "kick_l"),
((40, -110), (100, 80), "stand"))),
Move("robot", 1, 0, (((90, 90), (90, -90), "knee_l"),
((90, -90), (90, 90), "knee_r"))),
# ---- tier 2: the drop ----
Move("hands up", 2, 0, (((165, 25), (165, 25), "jump"),
((150, -15), (150, -15), "stand"))),
Move("raise the roof", 2, 0, (((135, 45), (135, 45), "wide"),
((105, 75), (105, 75), "wide"))),
Move("windmill", 2, 1, _windmill_frames()),
) )
class _Figure:
"""One lint ball: its fixed fuzz profile and its own pose."""
def __init__(self, index: int):
rng = np.random.default_rng(7919 * (index + 1))
self.index = index
self.radii = 1.0 + rng.uniform(-0.09, 0.09, 26)
self.hairs = rng.uniform(0, 2 * math.pi, 9)
self.hair_len = rng.uniform(0.12, 0.3, 9)
self.pose = 0
class LintRenderer: class LintRenderer:
name = STYLE name = STYLE
black_mode = True # the wheel offers black for this style black_mode = True # the wheel offers black for this style
@@ -86,7 +149,12 @@ class LintRenderer:
panel = QColor(200, 200, 200) # set by the widget: the background panel = QColor(200, 200, 200) # set by the widget: the background
def __init__(self, config=None): def __init__(self, config=None):
self._fig = _Figure(0) rng = np.random.default_rng(7919)
self._radii = 1.0 + rng.uniform(-0.09, 0.09, 26)
self._hairs = rng.uniform(0, 2 * math.pi, 9)
self._hair_len = rng.uniform(0.12, 0.3, 9)
self._rng = np.random.default_rng(104729)
self.head_on = False
self._behind = 0.0 self._behind = 0.0
self._clock = 0.0 self._clock = 0.0
self.step = 1 # 0 would be a blink self.step = 1 # 0 would be a blink
@@ -94,34 +162,33 @@ class LintRenderer:
self._last_beat = -1.0 self._last_beat = -1.0
self._beats = [] self._beats = []
self._beat_pending = False self._beat_pending = False
self.bob = 0.0 self.nod = 0.0
self.fullness = 0.0 self.fullness = 0.0
self.now = 0.0 # fullness over NOW_S
self.lately = 0.0 # … and over LATELY_S
self.busy = False self.busy = False
self._calm_for = 0.0 self._calm_for = 0.0
self._quiet_for = SIT_AFTER_S # nothing has played yet: sitting self._quiet_for = SIT_AFTER_S # nothing has played yet: sitting
self._loud_for = 0.0 self._loud_for = 0.0
self.posture = SIT self.posture = SIT
self.feet = 0 self.move = None # a Move while dancing
self._frame = 0 # which of its frames
self._move_beats = 0 # beats since the move began
self._new_tier = None # (tier, beats it has held)
self.configure(config or {})
# ---- the renderer contract ---- # ---- the renderer contract ----
def configure(self, config): def configure(self, config):
pass # no settings yet self.head_on = bool(config.get(HEAD_ON_KEY, False))
@property @property
def asleep(self) -> bool: def asleep(self) -> bool:
return self.posture == SLEEP return self.posture == SLEEP
def clear(self): def clear(self):
"""Stopped or paused: it sits down (and sleeps, given time).""" """Paused or stopped. Nothing changes here: the quiet clock (fed
self._quiet_for = max(self._quiet_for, SIT_AFTER_S) silence) sits it down in its own time, so skipping songs doesn't."""
self._loud_for = 0.0
if self.posture == STAND:
self.posture = SIT
self.busy = False
self.bob = 0.0
self._beats.clear()
self.step += 1
@property @property
def tempo(self) -> float: def tempo(self) -> float:
@@ -131,6 +198,15 @@ class LintRenderer:
return 0.0 return 0.0
return 60.0 * (len(recent) - 1) / max(1e-6, recent[-1] - recent[0]) return 60.0 * (len(recent) - 1) / max(1e-6, recent[-1] - recent[0])
@property
def tier(self) -> int:
base = 0 if self.now < TIER_EDGES[0] else 1 if self.now < TIER_EDGES[1] else 2
if self.now - self.lately > LIFT:
base += 1
elif self.lately - self.now > LIFT:
base -= 1
return max(0, min(2, base))
def advance(self, frame) -> bool: def advance(self, frame) -> bool:
dt = max(0.0, frame.dt) dt = max(0.0, frame.dt)
self._clock += dt self._clock += dt
@@ -166,7 +242,10 @@ class LintRenderer:
spectrum, freqs = spectrum_of(frame.samples, FFT, frame.rate) spectrum, freqs = spectrum_of(frame.samples, FFT, frame.rate)
lo, hi = np.searchsorted(freqs, BASS_HZ) lo, hi = np.searchsorted(freqs, BASS_HZ)
bass = float(np.sum(np.square(spectrum[lo:hi]))) bass = float(np.sum(np.square(spectrum[lo:hi])))
keep = math.exp(-dt / AVERAGE_S) if dt > 0 else 1.0
def keep(seconds):
return math.exp(-dt / seconds) if dt > 0 else 1.0
if (db >= QUIET_DB and bass > ONSET_RATIO * self._bass_avg if (db >= QUIET_DB and bass > ONSET_RATIO * self._bass_avg
and bass > 1e-5 and bass > 1e-5
and self._clock - self._last_beat >= ONSET_GAP_S): and self._clock - self._last_beat >= ONSET_GAP_S):
@@ -175,10 +254,18 @@ class LintRenderer:
self._beat_pending = True self._beat_pending = True
self._beats = [t for t in self._beats self._beats = [t for t in self._beats
if self._clock - t <= TEMPO_WINDOW_S] if self._clock - t <= TEMPO_WINDOW_S]
self._bass_avg = keep * self._bass_avg + (1 - keep) * bass k = keep(AVERAGE_S)
levels = band_levels(spectrum, freqs, self._bass_avg = k * self._bass_avg + (1 - k) * bass
band_edges(FULLNESS_BANDS, frame.rate)) if db >= QUIET_DB: # silence between songs isn't "thinner music"
self.fullness = keep * self.fullness + (1 - keep) * float(levels.mean()) full = float(band_levels(
spectrum, freqs, band_edges(FULLNESS_BANDS, frame.rate)).mean())
if not self.lately: # the first music heard: nothing to lift from
self.now = self.lately = full
self.fullness = k * self.fullness + (1 - k) * full
k = keep(NOW_S)
self.now = k * self.now + (1 - k) * full
k = keep(LATELY_S)
self.lately = k * self.lately + (1 - k) * full
wants = self.tempo >= BUSY_BPM and self.fullness >= BUSY_FULLNESS wants = self.tempo >= BUSY_BPM and self.fullness >= BUSY_FULLNESS
if wants: if wants:
@@ -191,20 +278,60 @@ class LintRenderer:
# ---- posing (every stop-motion step) ---- # ---- posing (every stop-motion step) ----
def _pick(self, tier: int):
choices = [m for m in MOVES if m.tier == tier and m is not self.move]
self.move = choices[int(self._rng.integers(len(choices)))]
self._frame = 0
self._move_beats = 0
self._new_tier = None
def _pose(self): def _pose(self):
self.step += 1 self.step += 1
beat = self._beat_pending
self._beat_pending = False
if self.posture != STAND: if self.posture != STAND:
self.bob = 0.0 self.nod = 0.0
self._beat_pending = False return
self.nod = 1.0 if beat else (0.45 if self.nod >= 1.0 else 0.0)
if not self.busy:
self.move = None
return
tier = self.tier
if self.move is None:
self._pick(tier)
elif beat:
self._move_beats += 1
if tier != self.move.tier:
held = (self._new_tier[1] + 1 if self._new_tier
and self._new_tier[0] == tier else 1)
self._new_tier = (tier, held)
if held >= TIER_HOLD_BEATS:
self._pick(tier)
return return
if self._beat_pending:
self._beat_pending = False
self.bob = 1.0
if self.busy:
self.feet ^= 1
self._fig.pose = (self._fig.pose + 1) % len(DANCE)
else: else:
self.bob = 0.35 if self.bob >= 1.0 else 0.0 self._new_tier = None
if self._move_beats >= SWITCH_EVERY:
self._move_beats = 0
if self._rng.random() < 0.5:
self._pick(tier)
return
if self.move.cadence == 0:
if beat:
self._frame = (self._frame + 1) % len(self.move.frames)
elif self.step % self.move.cadence == 0:
self._frame = (self._frame + 1) % len(self.move.frames)
def _limbs(self):
"""(left arm, right arm, legs) for this step."""
if self.posture == SLEEP:
return LYING[0], LYING[1], "stand"
if self.posture == SIT:
return SITTING[0], SITTING[1], "sit"
if self.move is not None:
return self.move.frames[self._frame % len(self.move.frames)]
swing = 6 * self.nod # a hanging arm swings with the nod
return ((HANG[0][0] + swing, HANG[0][1]),
(HANG[1][0] + swing, HANG[1][1]), "stand")
# ---- drawing ---- # ---- drawing ----
@@ -214,16 +341,16 @@ class LintRenderer:
return return
painter.save() painter.save()
painter.setRenderHint(painter.RenderHint.Antialiasing) painter.setRenderHint(painter.RenderHint.Antialiasing)
self._paint_figure(painter, area, self._fig, QColor(color)) self._paint_figure(painter, area, QColor(color))
painter.restore() painter.restore()
def _paint_figure(self, painter, cell, fig, ink): def _paint_figure(self, painter, cell, ink):
# The ball's radius: room for headphones either side and legs below, # The ball's radius: room for arms either side, the band above and
# or (asleep) lying full length. # legs below — or, asleep, lying full length.
r = min(cell.width() / 3.9, cell.height() / 4.2) r = min(cell.width() / 4.4, cell.height() / 4.6)
if self.posture == SLEEP: if self.posture == SLEEP:
r = min(r, cell.width() / 4.6, cell.height() / 2.8) r = min(r, cell.width() / 4.6, cell.height() / 2.8)
rng = np.random.default_rng(self.step * 31 + fig.index) rng = np.random.default_rng(self.step * 31)
wob = max(0.4, r * 0.06) wob = max(0.4, r * 0.06)
def j(x, y): def j(x, y):
@@ -244,122 +371,187 @@ class LintRenderer:
head = cx - r * 0.75 head = cx - r * 0.75
painter.translate(head, ground - r * 1.4) painter.translate(head, ground - r * 1.4)
painter.rotate(-90) painter.rotate(-90)
self._body(painter, fig, r, 0.0, j, SLEEP) self._body(painter, r, j, 0.0)
painter.restore() painter.restore()
self._zzz(painter, head + r * 0.5, ground - r * 3.0, r, fig, j) self._zzz(painter, head + r * 0.5, ground - r * 3.0, r, j)
return return
if self.posture == SIT: if self.posture == SIT:
painter.translate(cx, ground - r * 1.1) # the ball on the floor painter.translate(cx, ground - r * 1.1) # the ball on the floor
self._body(painter, fig, r, 0.0, j, SIT) else:
painter.restore() lift = r * 0.35 if self._limbs()[2] == "jump" else 0.0
return painter.translate(cx, ground - r * 2.25 - lift)
legs = r * 1.25 self._body(painter, r, j, self.nod)
dip = self.bob * r * 0.22
painter.translate(cx, ground - legs - r + dip)
self._body(painter, fig, r, dip, j, STAND)
painter.restore() painter.restore()
def _body(self, painter, fig, r, dip, j, posture): def _body(self, painter, r, j, nod):
"""The figure drawn around its ball's centre (0, 0), feet at +y.""" """The figure around its ball's centre (0, 0), feet at +y."""
asleep = posture == SLEEP posture = self.posture
blink = posture == SIT and self.step % BLINK_EVERY == 0 three_q = not self.head_on
# The fuzzy ball: a wobbly ring plus a few loose hairs. left_arm, right_arm, legs = self._limbs()
n = len(fig.radii) # The head (ball, face, headphones) nods about the neck: tipped in
# three-quarter view, the face dropped head on.
pivot = QPointF(0, r * 0.85)
tilt = QTransform()
if three_q and nod:
tilt.translate(pivot.x(), pivot.y())
tilt.rotate(NOD_DEG * nod)
tilt.translate(-pivot.x(), -pivot.y())
drop = 0.0 if three_q else NOD_DROP * r * nod
if three_q:
shoulders = {-1: (-r * 0.92, r * 0.3), 1: (r * 0.82, r * 0.38)}
hips = {-1: -r * 0.3, 1: r * 0.42}
else:
shoulders = {-1: (-r * 0.92, r * 0.3), 1: (r * 0.92, r * 0.3)}
hips = {-1: -r * 0.35, 1: r * 0.35}
shoulders = {s: tilt.map(QPointF(*p)) for s, p in shoulders.items()}
# Behind the ball: the legs (their tops hidden), and in
# three-quarter view the far arm and the far headphone cup.
self._legs(painter, r, j, legs, hips)
if three_q:
self._arm(painter, r, j, 1, shoulders[1], right_arm)
painter.save()
painter.setTransform(tilt, True)
if three_q:
outside = QPainterPath()
outside.addRect(QRectF(-3 * r, -3 * r, 6 * r, 6 * r))
ball = QPainterPath()
ball.addEllipse(QPointF(0, 0), r * 1.02, r * 1.02)
painter.save()
painter.setClipPath(outside.subtracted(ball),
Qt.ClipOperation.IntersectClip)
painter.drawEllipse(j(r * 0.98, -r * 0.05), r * 0.2, r * 0.4)
painter.restore()
# The fuzzy ball, filled with the panel so what's behind is hidden.
n = len(self._radii)
ring = QPainterPath() ring = QPainterPath()
for i in range(n + 1): for i in range(n + 1):
a = 2 * math.pi * (i % n) / n a = 2 * math.pi * (i % n) / n
p = j(math.cos(a) * r * fig.radii[i % n], p = j(math.cos(a) * r * self._radii[i % n],
math.sin(a) * r * fig.radii[i % n]) math.sin(a) * r * self._radii[i % n])
ring.moveTo(p) if i == 0 else ring.lineTo(p) ring.moveTo(p) if i == 0 else ring.lineTo(p)
painter.setBrush(QColor(self.panel))
painter.drawPath(ring) painter.drawPath(ring)
for a, length in zip(fig.hairs, fig.hair_len): painter.setBrush(Qt.BrushStyle.NoBrush)
for a, length in zip(self._hairs, self._hair_len):
if abs(math.cos(a)) > 0.8 or math.sin(a) > 0.5: if abs(math.cos(a)) > 0.8 or math.sin(a) > 0.5:
continue # where the headphone cups and the legs are continue # where the headphone cups and the legs are
painter.drawLine(j(math.cos(a) * r, math.sin(a) * r), painter.drawLine(j(math.cos(a) * r, math.sin(a) * r),
j(math.cos(a) * r * (1 + length), j(math.cos(a) * r * (1 + length),
math.sin(a) * r * (1 + length))) math.sin(a) * r * (1 + length)))
# Face. self._face(painter, r, j, posture, three_q, drop)
eye_y, eye_x = -r * 0.18, r * 0.32 self._headphones(painter, r, j, three_q, drop)
painter.restore()
if three_q:
self._arm(painter, r, j, -1, shoulders[-1], left_arm)
else:
for s, arm in ((-1, left_arm), (1, right_arm)):
self._arm(painter, r, j, s, shoulders[s], arm)
def _face(self, painter, r, j, posture, three_q, drop):
asleep = posture == SLEEP
blink = posture == SIT and self.step % BLINK_EVERY == 0
eye_y = -r * 0.18 + drop
mouth_y = r * 0.22 + drop
if three_q: # turned to its left (our right)
eyes = ((r * 0.18, 1.0), (r * 0.6, 0.8)) # (x, size): far is smaller
mouth = (r * 0.12, r * 0.62)
else:
eyes = ((-r * 0.32, 1.0), (r * 0.32, 1.0))
mouth = (-r * 0.3, r * 0.3)
mid = (mouth[0] + mouth[1]) / 2
if asleep or blink: if asleep or blink:
for s in (-1, 1): for x, size in eyes:
painter.drawLine(j(s * eye_x - r * 0.13, eye_y), painter.drawLine(j(x - r * 0.13 * size, eye_y),
j(s * eye_x + r * 0.13, eye_y)) j(x + r * 0.13 * size, eye_y))
if asleep:
painter.drawLine(j(-r * 0.12, r * 0.32), j(r * 0.12, r * 0.32))
elif posture == SIT:
if not blink:
dot = max(0.8, r * 0.07)
for s in (-1, 1):
painter.drawEllipse(j(s * eye_x, eye_y), dot, dot)
painter.drawLine(j(-r * 0.18, r * 0.32), j(r * 0.18, r * 0.3))
else: else:
dot = max(0.8, r * 0.07) dot = max(0.8, r * 0.07)
for s in (-1, 1): for x, size in eyes:
c = j(s * eye_x, eye_y) painter.drawEllipse(j(x, eye_y), dot * size, dot)
painter.drawEllipse(c, dot, dot) if asleep:
smile = QPainterPath(j(-r * 0.3, r * 0.22)) painter.drawLine(j(mid - r * 0.12, mouth_y + r * 0.1),
j(mid + r * 0.12, mouth_y + r * 0.1))
elif posture == SIT:
painter.drawLine(j(mid - r * 0.18, mouth_y + r * 0.1),
j(mid + r * 0.18, mouth_y + r * 0.08))
else:
smile = QPainterPath(j(mouth[0], mouth_y))
depth = r * (0.5 if self.busy else 0.32) depth = r * (0.5 if self.busy else 0.32)
smile.quadTo(j(0, r * 0.22 + depth), j(r * 0.3, r * 0.22)) smile.quadTo(j(mid, mouth_y + depth), j(mouth[1], mouth_y))
painter.drawPath(smile) painter.drawPath(smile)
# Big headphones: a band over the top, a cup over each side. def _headphones(self, painter, r, j, three_q, drop):
band = QPainterPath(j(-r * 1.12, -r * 0.1)) d = drop * 0.3
band.cubicTo(j(-r * 1.25, -r * 1.75), j(r * 1.25, -r * 1.75), if three_q:
j(r * 1.12, -r * 0.1)) # The near cup seen whole on the side of the head, the band
# over the top to the far cup (drawn behind the ball).
near = j(-r * 0.55, -r * 0.02 + d)
painter.drawEllipse(near, r * 0.3, r * 0.44)
painter.drawEllipse(near, r * 0.14, r * 0.24)
band = QPainterPath(j(-r * 0.6, -r * 0.45 + d))
band.cubicTo(j(-r * 0.75, -r * 1.65 + d), j(r * 0.95, -r * 1.55 + d),
j(r * 0.98, -r * 0.42 + d))
painter.drawPath(band)
return
band = QPainterPath(j(-r * 1.12, -r * 0.1 + d))
band.cubicTo(j(-r * 1.25, -r * 1.75 + d), j(r * 1.25, -r * 1.75 + d),
j(r * 1.12, -r * 0.1 + d))
painter.drawPath(band) painter.drawPath(band)
for s in (-1, 1): for s in (-1, 1):
c = j(s * r * 1.08, 0) painter.drawEllipse(j(s * r * 1.08, d), r * 0.24, r * 0.42)
painter.drawEllipse(c, r * 0.24, r * 0.42)
# Arms from the shoulders, two sticks each. def _arm(self, painter, r, j, s, start, arm):
if asleep: shoulder, bend = arm
pose = LYING upper, lower = r * 0.8, r * 0.65
elif posture == SIT:
pose = SITTING
elif self.busy:
pose = DANCE[fig.pose]
else:
pose = HANG
upper, lower = r * 0.75, r * 0.6
for s, (shoulder, bend) in zip((-1, 1), pose):
if posture == STAND and not self.busy:
shoulder += 6 * self.bob # a hanging arm swings with the bob
start = (s * r * 0.92, r * 0.3)
a = math.radians(shoulder) a = math.radians(shoulder)
elbow = (start[0] + s * math.sin(a) * upper, elbow = (start.x() + s * math.sin(a) * upper,
start[1] + math.cos(a) * upper) start.y() + math.cos(a) * upper)
b = math.radians(shoulder + bend) b = math.radians(shoulder + bend)
hand = (elbow[0] + s * math.sin(b) * lower, hand = (elbow[0] + s * math.sin(b) * lower,
elbow[1] + math.cos(b) * lower) elbow[1] + math.cos(b) * lower)
painter.drawPolyline([j(*start), j(*elbow), j(*hand)]) painter.drawPolyline([j(start.x(), start.y()), j(*elbow), j(*hand)])
if posture == SIT: def _legs(self, painter, r, j, legs, hips):
if legs == "sit":
# Splayed out along the floor, feet turned up. # Splayed out along the floor, feet turned up.
for s in (-1, 1): for s in (-1, 1):
hip = (s * r * 0.45, r * 0.85) hip = (hips[s] * 1.2, r * 0.85)
knee = (s * r * 1.0, r * 1.08) knee = (s * r * 1.0 + hips[s] * 0.2, r * 1.08)
foot = (s * r * 1.6, r * 1.08) foot = (s * r * 1.6 + hips[s] * 0.2, r * 1.08)
painter.drawPolyline([j(*hip), j(*knee), j(*foot), painter.drawPolyline([j(*hip), j(*knee), j(*foot),
j(foot[0] + s * r * 0.05, r * 0.78)]) j(foot[0] + s * r * 0.05, r * 0.78)])
return return
foot_y = r * 2.25
# Legs: straight, or bent at the knee by the bob; the feet step
# apart when dancing.
legs = r * 1.25
knee_out = dip * 0.9
spread = r * (0.5 if (self.busy and self.feet) else 0.35)
for s in (-1, 1): for s in (-1, 1):
hip = (s * r * 0.35, r * 0.93) side = "l" if s < 0 else "r"
foot_y = r + legs - dip hip = (hips[s], r * 0.6)
out = spread + (r * 0.15 if self.busy and self.feet == (s > 0) else 0) foot = [hips[s] + s * r * 0.02, foot_y]
foot = (s * out, foot_y) knee_out = 0.0
toe = s * r * 0.25
if legs == "wide":
foot[0] = hips[s] + s * r * 0.45
knee_out = r * 0.15
elif legs == "step_" + side:
foot[0] = hips[s] + s * r * 0.35
elif legs == "kick_" + side:
foot = [hips[s] + s * r * 1.0, foot_y - r * 0.6]
knee_out = r * 0.15
elif legs == "knee_" + side:
foot[1] = foot_y - r * 0.35
knee_out = r * 0.4
elif legs == "jump":
foot = [hips[s] + s * r * 0.05, foot_y - r * 0.3]
knee_out = r * 0.35
knee = ((hip[0] + foot[0]) / 2 + s * knee_out, knee = ((hip[0] + foot[0]) / 2 + s * knee_out,
(hip[1] + foot_y) / 2) (hip[1] + foot[1]) / 2)
painter.drawPolyline([j(*hip), j(*knee), j(*foot), painter.drawPolyline([j(*hip), j(*knee), j(*foot),
j(foot[0] + s * r * 0.25, foot_y)]) j(foot[0] + toe, foot[1])])
def _zzz(self, painter, x, y, r, fig, j): def _zzz(self, painter, x, y, r, j):
"""Little z's rising, a new one every few frames.""" """Little z's rising, a new one every few frames."""
phase = self.step % 12 phase = self.step % 12
for k in range(3): for k in range(3):
+1
View File
@@ -33,6 +33,7 @@ STYLE_KEYS = {
"visualizer_laser_glow", "visualizer_laser_grid", "visualizer_laser_glow", "visualizer_laser_grid",
"visualizer_laser_head", "visualizer_laser_dot", "visualizer_laser_head", "visualizer_laser_dot",
"visualizer_laser_grid_dot"), "visualizer_laser_grid_dot"),
"lint": ("visualizer_lint_head_on",),
} }
+2 -1
View File
@@ -77,7 +77,8 @@ LIMITS = {
"visualizer_radial_dot": (0.2, 2.5), # × the automatic size "visualizer_radial_dot": (0.2, 2.5), # × the automatic size
} }
_FLAGS = ("visualizer_radial_normalize", "visualizer_laser_head", _FLAGS = ("visualizer_radial_normalize", "visualizer_laser_head",
"visualizer_laser_glow", "visualizer_laser_grid") "visualizer_laser_glow", "visualizer_laser_grid",
"visualizer_lint_head_on")
_INTEGER = ("visualizer_radial_spokes", "visualizer_radial_levels", _INTEGER = ("visualizer_radial_spokes", "visualizer_radial_levels",
"visualizer_bars_count", "visualizer_bars_count",
"visualizer_laser_low_hz", "visualizer_laser_high_hz") "visualizer_laser_low_hz", "visualizer_laser_high_hz")
+1
View File
@@ -35,6 +35,7 @@ DEFAULTS = {
"visualizer_radial_levels": 20, # volume steps along each spoke "visualizer_radial_levels": 20, # volume steps along each spoke
"visualizer_radial_dot": 1.0, # dot size, × the automatic size "visualizer_radial_dot": 1.0, # dot size, × the automatic size
"visualizer_radial_normalize": True, # even out bass vs treble "visualizer_radial_normalize": True, # even out bass vs treble
"visualizer_lint_head_on": False, # Lint Oontz: head on, not 3/4 view
# Per-area grayscale overrides (0=black .. 255=white). None = inherit the # Per-area grayscale overrides (0=black .. 255=white). None = inherit the
# current/default look for that surface, so nothing changes until the user # current/default look for that surface, so nothing changes until the user
# drags a slider in Preferences. # drags a slider in Preferences.
+4 -4
View File
@@ -98,11 +98,11 @@ def test_quiet_sits_then_sleeps_and_music_wakes_it():
assert r.posture == STAND assert r.posture == STAND
def test_pausing_sits_it_down(): def test_pausing_lets_the_quiet_clock_decide():
r = LintRenderer() r = LintRenderer()
_play(r, _song(128, 2, True)) _play(r, _song(128, 2, True))
r.clear() r.clear()
assert r.posture == SIT assert r.posture == STAND # Round 123: it waits before sitting
def test_one_ball_in_the_given_colour(qapp): def test_one_ball_in_the_given_colour(qapp):
@@ -115,8 +115,8 @@ def test_one_ball_in_the_given_colour(qapp):
if any(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80 if any(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80
for y in range(0, h, 2))] for y in range(0, h, 2))]
assert cols assert cols
# One figure, in the middle: nothing in the outer fifths. # One figure, in the middle: nothing in the outer sixths.
assert min(cols) > w * 0.2 and max(cols) < w * 0.8 assert min(cols) > w / 6 and max(cols) < w * 5 / 6
def test_every_frame_wobbles(qapp): def test_every_frame_wobbles(qapp):
+137
View File
@@ -0,0 +1,137 @@
"""Round 123: Lint Oontz in three-quarter view (or head on, a setting),
nodding its head, ten dance moves by intensity, and slower to sit/sleep."""
import numpy as np
from PyQt6.QtCore import QRectF
from PyQt6.QtGui import QColor, QImage, QPainter
from lintunes.gui import visualizer_lint as vl
from lintunes.gui import visualizer_presets as presets
from lintunes.gui import visualizer_styles as vs
from lintunes.preferences import Preferences
RATE = 44100
def _pink(n, db, rng):
w = rng.normal(size=n)
f = np.fft.rfft(w)
k = np.arange(len(f))
k[0] = 1
x = np.fft.irfft(f / np.sqrt(k), n)
return x / np.sqrt(np.mean(x ** 2)) * 10 ** (db / 20)
def _section(seconds, db, rng, bpm=128):
n = int(RATE * seconds)
t = np.arange(n) / RATE
kick = np.sin(2 * np.pi * 55 * t) * np.exp(-(t % (60 / bpm)) * 18) * 0.7
return (_pink(n, db, rng) + kick).astype(np.float32)
def _feed(r, audio, on_step=None):
hist = np.zeros(vs.HISTORY, np.float32)
n = RATE // 60
for i in range(0, len(audio) - n, n):
chunk = audio[i:i + n]
hist = np.concatenate([hist, chunk])[-vs.HISTORY:]
if r.advance(vs.Frame(hist, RATE, chunk, 1 / 60)) and on_step:
on_step()
def _quiet(r, seconds):
for _ in range(int(seconds * 60)):
r.advance(vs.Frame(np.zeros(vs.HISTORY, np.float32), RATE,
np.zeros(0, np.float32), 1 / 60))
def _draw(r, w=240, h=240):
img = QImage(w, h, QImage.Format.Format_ARGB32)
img.fill(QColor(205, 205, 205))
p = QPainter(img)
r.paint(p, QRectF(0, 0, w, h), QColor(40, 110, 220))
p.end()
return img
def test_ten_moves_in_three_tiers_using_arms_and_legs():
assert len(vl.MOVES) == 10
assert len({m.name for m in vl.MOVES}) == 10
assert {m.tier for m in vl.MOVES} == {0, 1, 2}
legs = {frame[2] for m in vl.MOVES for frame in m.frames}
assert legs - {"stand"} # some moves use the legs
def test_waits_standing_then_sits_then_sleeps():
r = vl.LintRenderer()
_feed(r, _section(3, -16, np.random.default_rng(1)))
assert r.posture == vl.STAND
_quiet(r, 2) # skipping to the next song
assert r.posture == vl.STAND
_quiet(r, vl.SIT_AFTER_S - 2 + 0.5)
assert r.posture == vl.SIT
_quiet(r, vl.SLEEP_AFTER_S - vl.SIT_AFTER_S)
assert r.posture == vl.SLEEP
assert vl.SIT_AFTER_S >= 8 and vl.SLEEP_AFTER_S >= 25
def test_the_moves_follow_the_music_shifting():
rng = np.random.default_rng(2)
r = vl.LintRenderer()
tiers = {}
for name, seconds, db in (("verse", 20, -21), ("drop", 20, -13),
("break", 15, -21)):
seen = set()
_feed(r, _section(seconds, db, rng),
lambda: r.move and seen.add(r.move.tier))
tiers[name] = (r.move.tier, seen)
assert tiers["verse"][0] == 0
assert tiers["drop"][0] == 2
assert tiers["break"][0] == 0
def test_a_beat_nods_the_head():
r = vl.LintRenderer()
r.posture = vl.STAND
r._beat_pending = True
r._pose()
assert r.nod == 1.0
r._pose()
assert 0 < r.nod < 1
r._pose()
assert r.nod == 0.0
for head_on in (False, True): # and it shows, in both views
r.configure({vl.HEAD_ON_KEY: head_on})
r.nod = 0.0
still = _draw(r)
r.nod = 1.0
assert _draw(r) != still
def test_both_views_draw_every_move(qapp):
for head_on in (False, True):
r = vl.LintRenderer({vl.HEAD_ON_KEY: head_on})
r.posture, r.busy = vl.STAND, True
for move in vl.MOVES:
r.move = move
for f in range(len(move.frames)):
r._frame = f
img = _draw(r, 134, 38)
assert any(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80
for x in range(134) for y in range(38))
def test_three_quarter_and_head_on_differ(qapp):
a = vl.LintRenderer({vl.HEAD_ON_KEY: False})
b = vl.LintRenderer({vl.HEAD_ON_KEY: True})
for r in (a, b):
r.posture = vl.STAND
assert _draw(a) != _draw(b)
def test_the_view_is_a_setting(qapp, tmp_path):
prefs = Preferences(tmp_path)
assert vs.settings(prefs)[vl.HEAD_ON_KEY] is False # 3/4 by default
prefs.set(vl.HEAD_ON_KEY, True)
r = vs.make_renderer(vs.STYLE_LINT, vs.settings(prefs))
assert r.head_on
assert vl.HEAD_ON_KEY in presets.STYLE_KEYS["lint"]