v0.88.1: Lint Oontz is one ball — it sits when nothing plays and falls asleep later; the wheel's modes for it are colour, gray, black
The visualizer keeps its clock with nothing playing for a style that idles (fed silence), so the ball can sit, blink and fall asleep while paused.
This commit is contained in:
+93
-43
@@ -1,10 +1,17 @@
|
||||
"""Round 122: Lint Oontz, the stop-motion lint-ball visualizer."""
|
||||
"""Round 122: Lint Oontz, the stop-motion lint-ball visualizer: one ball in
|
||||
headphones that dances, sits when nothing plays and falls asleep; its
|
||||
colour modes are highlight, gray and black."""
|
||||
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_styles as vs
|
||||
from lintunes.gui.visualizer_lint import FPS, LintRenderer
|
||||
from lintunes.gui.visualizer import (
|
||||
MODE_BLACK, MODE_DIM, MODE_OFF, MODE_ON)
|
||||
from lintunes.gui.visualizer_lint import FPS, LintRenderer, SIT, SLEEP, STAND
|
||||
|
||||
from test_round86 import _tile
|
||||
|
||||
RATE = 44100
|
||||
|
||||
@@ -31,6 +38,19 @@ def _play(r, audio):
|
||||
return steps
|
||||
|
||||
|
||||
def _silence(seconds):
|
||||
return np.zeros(int(RATE * seconds), np.float32)
|
||||
|
||||
|
||||
def _draw(r, w, h, color=QColor(40, 110, 220)):
|
||||
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), color)
|
||||
p.end()
|
||||
return img
|
||||
|
||||
|
||||
def test_registered():
|
||||
assert vs.STYLE_LINT in vs.STYLES
|
||||
assert vs.STYLE_NAMES[vs.STYLE_LINT] == "Lint Oontz"
|
||||
@@ -46,69 +66,99 @@ def test_stop_motion_frame_rate():
|
||||
def test_fast_full_music_dances():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(128, 6, True))
|
||||
assert not r.asleep and r.busy
|
||||
assert r.posture == STAND and r.busy
|
||||
assert 120 <= r.tempo <= 136
|
||||
|
||||
|
||||
def test_slow_sparse_music_only_bobs():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(80, 6, False))
|
||||
assert not r.asleep and not r.busy
|
||||
assert r.posture == STAND and not r.busy
|
||||
assert 74 <= r.tempo <= 86
|
||||
|
||||
|
||||
def test_quiet_puts_them_to_sleep_and_music_wakes_them():
|
||||
def test_it_starts_sitting_then_falls_asleep():
|
||||
r = LintRenderer()
|
||||
assert r.posture == SIT
|
||||
_play(r, _silence(vl.SLEEP_AFTER_S - vl.SIT_AFTER_S - 1))
|
||||
assert r.posture == SIT
|
||||
_play(r, _silence(2))
|
||||
assert r.posture == SLEEP
|
||||
|
||||
|
||||
def test_quiet_sits_then_sleeps_and_music_wakes_it():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(128, 3, True))
|
||||
assert not r.asleep
|
||||
_play(r, np.zeros(RATE * 2, np.float32))
|
||||
assert not r.asleep # a short break isn't sleep
|
||||
_play(r, np.zeros(RATE * 3, np.float32))
|
||||
assert r.asleep
|
||||
assert r.posture == STAND
|
||||
_play(r, _silence(vl.SIT_AFTER_S + 0.5))
|
||||
assert r.posture == SIT
|
||||
_play(r, _silence(vl.SLEEP_AFTER_S))
|
||||
assert r.posture == SLEEP
|
||||
_play(r, _song(128, 1, True))
|
||||
assert not r.asleep
|
||||
assert r.posture == STAND
|
||||
|
||||
|
||||
def test_cleared_is_asleep():
|
||||
def test_pausing_sits_it_down():
|
||||
r = LintRenderer()
|
||||
_play(r, _song(128, 2, True))
|
||||
r.clear()
|
||||
assert r.asleep
|
||||
assert r.posture == SIT
|
||||
|
||||
|
||||
def test_three_balls_gray_highlight_black(qapp):
|
||||
def test_one_ball_in_the_given_colour(qapp):
|
||||
r = LintRenderer()
|
||||
r.panel = QColor(205, 205, 205)
|
||||
gray, highlight, black = r.colors(QColor(40, 110, 220))
|
||||
assert highlight == QColor(40, 110, 220)
|
||||
assert black == QColor(0, 0, 0)
|
||||
assert gray.red() == gray.green() == gray.blue() < 205
|
||||
for asleep in (False, True):
|
||||
r.asleep = asleep
|
||||
for w, h in ((110, 44), (900, 450)):
|
||||
img = QImage(w, h, QImage.Format.Format_ARGB32)
|
||||
img.fill(r.panel)
|
||||
p = QPainter(img)
|
||||
r.paint(p, QRectF(0, 0, w, h), highlight)
|
||||
p.end()
|
||||
blue = sum(img.pixelColor(x, y).blue() - img.pixelColor(x, y).red() > 80
|
||||
for x in range(w) for y in range(0, h, 2))
|
||||
assert blue > 0
|
||||
for posture in (STAND, SIT, SLEEP):
|
||||
r.posture = posture
|
||||
for w, h in ((134, 38), (900, 450)):
|
||||
img = _draw(r, w, h)
|
||||
cols = [x for x in range(w)
|
||||
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
|
||||
|
||||
|
||||
def test_every_frame_wobbles(qapp):
|
||||
r = LintRenderer()
|
||||
r.asleep = False
|
||||
|
||||
def draw():
|
||||
img = QImage(200, 100, QImage.Format.Format_ARGB32)
|
||||
img.fill(QColor(205, 205, 205))
|
||||
p = QPainter(img)
|
||||
r.paint(p, QRectF(0, 0, 200, 100), QColor(40, 110, 220))
|
||||
p.end()
|
||||
return img
|
||||
|
||||
first = draw()
|
||||
assert draw() == first # the same step draws the same
|
||||
r.posture = STAND
|
||||
first = _draw(r, 200, 100)
|
||||
assert _draw(r, 200, 100) == first # the same step draws the same
|
||||
r.step += 1
|
||||
assert draw() != first # the next one is re-wobbled
|
||||
assert _draw(r, 200, 100) != first # the next one is re-wobbled
|
||||
|
||||
|
||||
def test_the_wheel_adds_black_for_lint_only(qapp, tmp_path):
|
||||
prefs, vis = _tile(tmp_path, "lint")
|
||||
seen = []
|
||||
for _ in range(4):
|
||||
vis.cycle_mode()
|
||||
seen.append(vis._mode)
|
||||
assert seen == [MODE_DIM, MODE_BLACK, MODE_OFF, MODE_ON]
|
||||
vis.cycle_mode()
|
||||
vis.cycle_mode()
|
||||
assert vis._mode == MODE_BLACK
|
||||
assert vis.paint_color() == QColor(0, 0, 0)
|
||||
prefs.set("visualizer_style", "bars") # black means nothing there
|
||||
assert vis.paint_color() == vis.palette().highlight().color()
|
||||
vis.cycle_mode()
|
||||
assert vis._mode == MODE_OFF
|
||||
prefs2, bars = _tile(tmp_path / "b", "bars")
|
||||
seen = []
|
||||
for _ in range(3):
|
||||
bars.cycle_mode()
|
||||
seen.append(bars._mode)
|
||||
assert seen == [MODE_DIM, MODE_OFF, MODE_ON]
|
||||
|
||||
|
||||
def test_it_keeps_its_clock_with_nothing_playing(qapp, tmp_path):
|
||||
_, vis = _tile(tmp_path, "lint")
|
||||
assert vis._timer.isActive() # sits, and will fall asleep
|
||||
_, bars = _tile(tmp_path / "b", "bars")
|
||||
assert not bars._timer.isActive()
|
||||
vis._renderer.posture = STAND
|
||||
for _ in range(int(vl.SIT_AFTER_S * 60) + 30):
|
||||
vis._advance_frame() # fed silence, not the old song
|
||||
assert vis._renderer.posture == SIT
|
||||
vis.cycle_mode(); vis.cycle_mode(); vis.cycle_mode()
|
||||
assert vis._mode == MODE_OFF and not vis._timer.isActive()
|
||||
|
||||
Reference in New Issue
Block a user