diff --git a/CLAUDE.md b/CLAUDE.md index 5cea484..f0d69d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -417,7 +417,9 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal 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 + combo; in `STYLE_KEYS`). `visualizer_lint_face_left` (Round 124, the + Looking combo, 3/4 only) mirrors the whole drawing about its centre; the + z's are only moved, so they still read as z's. 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 `advance` is True only on a step; every step re-rolls each line's wobble diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 564e017..38526d9 100644 --- a/lintunes/__init__.py +++ b/lintunes/__init__.py @@ -1,3 +1,3 @@ """LinTunes — iTunes-style music library manager and player for Linux.""" -__version__ = "0.89.0" +__version__ = "0.90.0" diff --git a/lintunes/gui/preferences_dialog.py b/lintunes/gui/preferences_dialog.py index 91d9b6f..b80522f 100644 --- a/lintunes/gui/preferences_dialog.py +++ b/lintunes/gui/preferences_dialog.py @@ -881,11 +881,27 @@ class PreferencesDialog(QDialog): 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)) + facing = QComboBox() + facing.addItems(["Right", "Left"]) + facing.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents) + facing.setCurrentIndex(int(config["visualizer_lint_face_left"])) + facing.setToolTip("Which way it looks in three-quarter view") + facing.setEnabled(view.currentIndex() == 0) + + def view_chosen(i): + facing.setEnabled(i == 0) + self._prefs.set("visualizer_lint_head_on", i == 1) + + view.currentIndexChanged.connect(view_chosen) + facing.currentIndexChanged.connect( + lambda i: self._prefs.set("visualizer_lint_face_left", i == 1)) self._viz_setters["visualizer_lint_head_on"] = ( lambda value: view.setCurrentIndex(int(bool(value)))) + self._viz_setters["visualizer_lint_face_left"] = ( + lambda value: facing.setCurrentIndex(int(bool(value)))) + self._lint_view, self._lint_facing = view, facing form.addRow("View:", view) + form.addRow("Looking:", facing) about = QLabel( "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 " diff --git a/lintunes/gui/visualizer_lint.py b/lintunes/gui/visualizer_lint.py index fe0186f..ae31169 100644 --- a/lintunes/gui/visualizer_lint.py +++ b/lintunes/gui/visualizer_lint.py @@ -26,7 +26,9 @@ What the music does to it: 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 ball) or head on. Same moves in both. Three-quarter looks to our right +unless ``visualizer_lint_face_left``: then the whole drawing is mirrored +(the z's only moved, so they still read as z's). 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. @@ -42,6 +44,7 @@ from PyQt6.QtGui import QColor, QPainterPath, QPen, QTransform STYLE = "lint" HEAD_ON_KEY = "visualizer_lint_head_on" +FACE_LEFT_KEY = "visualizer_lint_face_left" # 3/4 view: looking to our left FPS = 8 # stop motion: a new drawing this often STEP_S = 1.0 / FPS INSET = 3 @@ -155,6 +158,7 @@ class LintRenderer: self._hair_len = rng.uniform(0.12, 0.3, 9) self._rng = np.random.default_rng(104729) self.head_on = False + self.face_left = False self._behind = 0.0 self._clock = 0.0 self.step = 1 # 0 would be a blink @@ -181,6 +185,7 @@ class LintRenderer: def configure(self, config): self.head_on = bool(config.get(HEAD_ON_KEY, False)) + self.face_left = bool(config.get(FACE_LEFT_KEY, False)) @property def asleep(self) -> bool: @@ -364,7 +369,12 @@ class LintRenderer: ground = cell.bottom() - pen.widthF() cx = cell.center().x() + mirror = self.face_left and not self.head_on painter.save() + if mirror: + painter.translate(cx, 0) + painter.scale(-1, 1) + painter.translate(-cx, 0) if self.posture == SLEEP: # Lying on its back, feet to the right: the standing drawing # turned a quarter (rotate(-90) sends "down" to "right"). @@ -373,7 +383,9 @@ class LintRenderer: painter.rotate(-90) self._body(painter, r, j, 0.0) painter.restore() - self._zzz(painter, head + r * 0.5, ground - r * 3.0, r, j) + x = head + r * 0.5 + self._zzz(painter, 2 * cx - x if mirror else x, ground - r * 3.0, + r, j, -1 if mirror else 1) return if self.posture == SIT: painter.translate(cx, ground - r * 1.1) # the ball on the floor @@ -551,13 +563,14 @@ class LintRenderer: painter.drawPolyline([j(*hip), j(*knee), j(*foot), j(foot[0] + toe, foot[1])]) - def _zzz(self, painter, x, y, r, j): - """Little z's rising, a new one every few frames.""" + def _zzz(self, painter, x, y, r, j, way=1): + """Little z's rising (drifting ``way``: 1 right, -1 left), a new one + every few frames.""" phase = self.step % 12 for k in range(3): age = (phase / 4 + k) % 3 # 0..3, how far it has risen size = r * (0.18 + 0.08 * age) - zx = x + age * r * 0.3 + zx = x + way * age * r * 0.3 - (size if way < 0 else 0) zy = y - age * r * 0.4 painter.drawPolyline([j(zx, zy), j(zx + size, zy), j(zx, zy + size), j(zx + size, zy + size)]) diff --git a/lintunes/gui/visualizer_presets.py b/lintunes/gui/visualizer_presets.py index 36d784b..19dc30d 100644 --- a/lintunes/gui/visualizer_presets.py +++ b/lintunes/gui/visualizer_presets.py @@ -33,7 +33,7 @@ STYLE_KEYS = { "visualizer_laser_glow", "visualizer_laser_grid", "visualizer_laser_head", "visualizer_laser_dot", "visualizer_laser_grid_dot"), - "lint": ("visualizer_lint_head_on",), + "lint": ("visualizer_lint_head_on", "visualizer_lint_face_left"), } diff --git a/lintunes/gui/visualizer_styles.py b/lintunes/gui/visualizer_styles.py index 47da55e..baa0b02 100644 --- a/lintunes/gui/visualizer_styles.py +++ b/lintunes/gui/visualizer_styles.py @@ -78,7 +78,7 @@ LIMITS = { } _FLAGS = ("visualizer_radial_normalize", "visualizer_laser_head", "visualizer_laser_glow", "visualizer_laser_grid", - "visualizer_lint_head_on") + "visualizer_lint_head_on", "visualizer_lint_face_left") _INTEGER = ("visualizer_radial_spokes", "visualizer_radial_levels", "visualizer_bars_count", "visualizer_laser_low_hz", "visualizer_laser_high_hz") diff --git a/lintunes/preferences.py b/lintunes/preferences.py index a7f2c67..56fb98e 100644 --- a/lintunes/preferences.py +++ b/lintunes/preferences.py @@ -36,6 +36,7 @@ DEFAULTS = { "visualizer_radial_dot": 1.0, # dot size, × the automatic size "visualizer_radial_normalize": True, # even out bass vs treble "visualizer_lint_head_on": False, # Lint Oontz: head on, not 3/4 view + "visualizer_lint_face_left": False, # … and in 3/4, looking to the left # Per-area grayscale overrides (0=black .. 255=white). None = inherit the # current/default look for that surface, so nothing changes until the user # drags a slider in Preferences. diff --git a/tests/test_round123.py b/tests/test_round123.py index 6ff5822..1ff9264 100644 --- a/tests/test_round123.py +++ b/tests/test_round123.py @@ -135,3 +135,47 @@ def test_the_view_is_a_setting(qapp, tmp_path): r = vs.make_renderer(vs.STYLE_LINT, vs.settings(prefs)) assert r.head_on assert vl.HEAD_ON_KEY in presets.STYLE_KEYS["lint"] + + +# ---- Round 124: which way the three-quarter view looks ---- + +def _differ(a, b): + return sum(abs(a.pixelColor(x, y).red() - b.pixelColor(x, y).red()) > 60 + for x in range(a.width()) for y in range(a.height())) + + +def test_facing_left_is_the_mirror_image(qapp): + for posture in (vl.STAND, vl.SIT): + right = vl.LintRenderer({vl.FACE_LEFT_KEY: False}) + left = vl.LintRenderer({vl.FACE_LEFT_KEY: True}) + for r in (right, left): + r.posture = posture + # Same step, same wobble: one is the other flipped (bar a few + # antialiased edge pixels), and nothing like it unflipped. + a, b = _draw(left), _draw(right) + flipped = _differ(a, b.mirrored(True, False)) + assert flipped < _differ(a, b) / 10 + + +def test_head_on_ignores_facing(qapp): + a = vl.LintRenderer({vl.HEAD_ON_KEY: True, vl.FACE_LEFT_KEY: False}) + b = vl.LintRenderer({vl.HEAD_ON_KEY: True, vl.FACE_LEFT_KEY: True}) + for r in (a, b): + r.posture = vl.STAND + assert _draw(a) == _draw(b) + + +def test_asleep_facing_left_still_draws(qapp): + r = vl.LintRenderer({vl.FACE_LEFT_KEY: True}) + r.posture = vl.SLEEP + img = _draw(r) + assert any(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80 + for x in range(240) for y in range(240)) + + +def test_facing_is_a_setting(qapp, tmp_path): + prefs = Preferences(tmp_path) + assert vs.settings(prefs)[vl.FACE_LEFT_KEY] is False # right by default + prefs.set(vl.FACE_LEFT_KEY, True) + assert vs.make_renderer(vs.STYLE_LINT, vs.settings(prefs)).face_left + assert vl.FACE_LEFT_KEY in presets.STYLE_KEYS["lint"]