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
+4 -4
View File
@@ -98,11 +98,11 @@ def test_quiet_sits_then_sleeps_and_music_wakes_it():
assert r.posture == STAND
def test_pausing_sits_it_down():
def test_pausing_lets_the_quiet_clock_decide():
r = LintRenderer()
_play(r, _song(128, 2, True))
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):
@@ -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
for y in range(0, h, 2))]
assert cols
# One figure, in the middle: nothing in the outer fifths.
assert min(cols) > w * 0.2 and max(cols) < w * 0.8
# One figure, in the middle: nothing in the outer sixths.
assert min(cols) > w / 6 and max(cols) < w * 5 / 6
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"]