2132 lines
89 KiB
Python
2132 lines
89 KiB
Python
#!/usr/bin/env python3
|
||
"""Generate shared/animations.json (+ shared/ANIMATIONS.md): one-second, 12-frame stop-motion animations.
|
||
|
||
Each animation is drawn frame by frame (no tweening between keyframes) and every frame gets
|
||
its own random wobble, the "boil" of hand-cut stop motion. One primary colour each. They
|
||
start at the checkbox: the origin (0, 0) is the box's centre, one unit is the box's size,
|
||
y points down, so "up out of the box" is negative y.
|
||
|
||
Output, compact on purpose (both apps parse it):
|
||
{"fps": 12, "colors": {"red": "#..", ...}, "perSet": 5, "sets": [40, 20, 10],
|
||
"animations": [{"name", "color", "sound", "frames": [[shape, ...], ...]}],
|
||
"calm": [...], "star": {...}, "streak": {...}}
|
||
shapes: see tools/anim_kit.py ("p" polygon, "l" polyline, "c" circle, "k" colour switch,
|
||
"n" the streak number, drawn by the painter: routine/gui/anim_paint.py).
|
||
"star": the special 2 s animation, same shape format, 24 frames.
|
||
"calm": the calm set, 2 s (24 frames) each, for tasks marked "calm": true in the schedule.
|
||
"streak": {"levels": [7, 21, 42, 66, 100, 150, 254, 365], "every": 100,
|
||
"sets": [[anim, ...] per level, 8 each; [] = none yet], "calm": [anim × 4]}
|
||
24 frames each; every one has "n" shapes for the streak number. Made from
|
||
tools/streak_anims/levelK.py + calm.py (see that package's docstring).
|
||
|
||
Run: python3 tools/gen_animations.py everything into shared/ (deterministic)
|
||
python3 tools/gen_animations.py --level 3 --out DIR only streak level 3 (or calm), into DIR
|
||
"""
|
||
|
||
import json
|
||
import math
|
||
import os
|
||
import random
|
||
|
||
from anim_kit import (CALM_FRAMES, CB, COLORS, FPS, N, R, ROOT, STREAK_FRAMES, C, L, P, cc, cl, cp, ease_out, # noqa: F401
|
||
frames_of, inout, j, oval, ring, rotate, star, steam, wavy)
|
||
|
||
|
||
# ── the twenty ────────────────────────────────────────────────────────────────
|
||
|
||
def bloom(i, t):
|
||
"""A stem shoots up and a five-petal flower pops open, then sheds a petal."""
|
||
s = []
|
||
h = min(1.0, t * 2.2) * 3.2
|
||
s.append(L([(0, 0), (0.25, -h * 0.4), (-0.15, -h * 0.75), (0.1, -h)], 0.2))
|
||
if i >= 3:
|
||
s.append(P([(0.1, -h * 0.5), (0.9, -h * 0.65), (0.25, -h * 0.4)])) # a leaf
|
||
if i >= 5:
|
||
open_ = min(1.0, (i - 4) / 3)
|
||
cx, cy = 0.1, -h
|
||
for k in range(5):
|
||
if i >= 10 and k == 1:
|
||
continue
|
||
a = -math.pi / 2 + k * 2 * math.pi / 5 + i * 0.05
|
||
d = 0.55 * open_
|
||
s.append(C(cx + d * math.cos(a), cy + d * math.sin(a), 0.38 * open_ + 0.05))
|
||
s.append(C(cx, cy, 0.22, 0.12))
|
||
if i >= 10: # the shed petal
|
||
s.append(C(0.9 + (i - 10) * 0.5, -h + (i - 10) * 0.6, 0.3))
|
||
return s
|
||
|
||
|
||
def rocket(i, t):
|
||
"""Wobbles in the box, then blasts off upward with a flickering flame and puffs."""
|
||
s = []
|
||
y = 0.0 if i < 2 else -((i - 1) ** 1.7) * 0.32
|
||
shake = 0.12 if i < 2 else 0
|
||
x = R.uniform(-shake, shake)
|
||
body = [(x, y - 1.4), (x + 0.45, y - 0.6), (x + 0.45, y + 0.5), (x - 0.45, y + 0.5), (x - 0.45, y - 0.6)]
|
||
s.append(P(body))
|
||
s.append(P([(x + 0.45, y + 0.1), (x + 0.85, y + 0.7), (x + 0.45, y + 0.5)]))
|
||
s.append(P([(x - 0.45, y + 0.1), (x - 0.85, y + 0.7), (x - 0.45, y + 0.5)]))
|
||
fl = 0.5 + R.uniform(0, 0.7) + (0.6 if i >= 2 else 0)
|
||
s.append(P([(x - 0.3, y + 0.6), (x, y + 0.6 + fl), (x + 0.3, y + 0.6)], 0.12))
|
||
for k in range(max(0, i - 2)): # smoke left behind
|
||
py = -((k + 1) ** 1.7) * 0.32 + 1.0
|
||
s.append(C(R.uniform(-0.3, 0.3), py, 0.2 + (i - k) * 0.06, 0.1))
|
||
return s
|
||
|
||
|
||
def starburst(i, t):
|
||
"""Rays shoot out of the box, grow, then fly off as dashes."""
|
||
s = []
|
||
for k in range(10):
|
||
a = k * 2 * math.pi / 10 + 0.15
|
||
if i < 6:
|
||
r0, r1 = 0.6, 0.6 + (i + 1) * 0.42
|
||
else:
|
||
r0, r1 = 0.6 + (i - 5) * 0.7, 0.6 + (i - 5) * 0.7 + max(0.2, 2.5 - (i - 5) * 0.35)
|
||
s.append(L([(r0 * math.cos(a), r0 * math.sin(a)), (r1 * math.cos(a), r1 * math.sin(a))], 0.2))
|
||
if i in (2, 3, 4):
|
||
s.append(P(star(0, 0, 0.9, 0.4, 8, i * 0.3)))
|
||
return s
|
||
|
||
|
||
def bounce(i, t):
|
||
"""A ball pops out and bounces off to the right, squashing on every landing."""
|
||
hops = [(0, 0), (2.0, 0), (3.6, 0), (4.8, 0)]
|
||
seg = min(2, int(t * 3 * 0.999))
|
||
u = (t * 3) - seg
|
||
(x0, _), (x1, _) = hops[seg], hops[seg + 1]
|
||
hgt = [3.4, 2.0, 1.1][seg]
|
||
x = x0 + (x1 - x0) * u
|
||
y = -4 * hgt * u * (1 - u)
|
||
squash = u < 0.12 or u > 0.88
|
||
rx, ry = (0.75, 0.4) if squash else (0.55, 0.6)
|
||
pts = [(x + rx * math.cos(a), y - ry + ry * math.sin(a)) for a in [k * math.pi / 6 for k in range(12)]]
|
||
s = [P(pts)]
|
||
if squash and i > 0:
|
||
s.append(L([(x - 0.8, 0.05), (x - 0.5, -0.25)], 0.1))
|
||
s.append(L([(x + 0.8, 0.05), (x + 0.5, -0.25)], 0.1))
|
||
return s
|
||
|
||
|
||
def jack(i, t):
|
||
"""A jack-in-the-box spring boings up and wobbles side to side."""
|
||
ext = [0.4, 1.4, 2.8, 3.6, 3.1, 3.5, 3.2, 3.4, 3.3, 3.35, 3.3, 3.3][i]
|
||
sway = math.sin(i * 1.3) * 0.5 * (1 - t)
|
||
pts = []
|
||
coils = 7
|
||
for k in range(coils * 2 + 1):
|
||
f = k / (coils * 2)
|
||
pts.append(((0.35 if k % 2 else -0.35) + sway * f, -ext * f))
|
||
s = [L(pts, 0.14)]
|
||
hx, hy = sway, -ext - 0.55
|
||
s.append(P(ring(hx, hy, 0.55, 12, i * 0.2, 0.04)))
|
||
s.append(P([(hx - 0.55, hy - 0.4), (hx - 0.2, hy - 1.2), (hx, hy - 0.5), (hx + 0.2, hy - 1.2), (hx + 0.55, hy - 0.4)]))
|
||
return s
|
||
|
||
|
||
def balloon(i, t):
|
||
"""A balloon floats up out of the box, swaying, then pops."""
|
||
if i < 8:
|
||
y = -0.8 - i * 0.45
|
||
x = math.sin(i * 0.9) * 0.3
|
||
s = [P(ring(x, y - 0.55, 0.6, 14, 0, 0.04) + [(x, y + 0.1)])]
|
||
s.append(P([(x - 0.12, y + 0.15), (x + 0.12, y + 0.15), (x, y - 0.02)]))
|
||
s.append(L([(x, y + 0.15), (x + 0.2, y + 0.6), (x - 0.15, y + 1.0), (x + 0.1, y + 1.4)], 0.07))
|
||
return s
|
||
y = -0.8 - 7 * 0.45 - 0.55
|
||
x = math.sin(7 * 0.9) * 0.3
|
||
k = i - 7
|
||
s = []
|
||
for m in range(7):
|
||
a = m * 2 * math.pi / 7 + 0.3
|
||
d = 0.3 + k * 0.45
|
||
cx, cy = x + d * math.cos(a), y + d * math.sin(a) + k * k * 0.05
|
||
s.append(P(rotate([(cx - 0.15, cy - 0.1), (cx + 0.18, cy), (cx - 0.05, cy + 0.15)], m + k, cx, cy)))
|
||
if k == 1:
|
||
s.append(P(star(x, y, 1.1, 0.5, 9), 0.1))
|
||
return s
|
||
|
||
|
||
def firework(i, t):
|
||
"""A rocket trail climbs, then bursts into a dandelion of sparks that droop."""
|
||
top = -4.2
|
||
if i < 5:
|
||
y = top * (i + 1) / 5
|
||
return [L([(0, 0.0 if i < 2 else y + 1.4), (0, y)], 0.12), C(0, y, 0.12)]
|
||
k = i - 4
|
||
s = []
|
||
for m in range(12):
|
||
a = m * 2 * math.pi / 12
|
||
r = 0.5 + k * 0.38
|
||
x, y = r * math.cos(a), top + r * math.sin(a) + k * k * 0.04
|
||
if k < 5:
|
||
s.append(L([(0.6 * x, top + 0.6 * (y - top)), (x, y)], 0.1))
|
||
if k >= 3:
|
||
s.append(C(x, y + 0.2, 0.09))
|
||
if k == 1:
|
||
s.append(C(0, top, 0.45))
|
||
return s
|
||
|
||
|
||
def bird(i, t):
|
||
"""A little bird flaps out of the box and away up to the right."""
|
||
x, y = t * 5.0, -0.3 - t * 4.2 + math.sin(i * 1.7) * 0.15
|
||
up = i % 2 == 0
|
||
wy = -0.7 if up else 0.45
|
||
s = [P([(x - 0.4, y), (x + 0.5, y - 0.1), (x + 0.75, y - 0.35), (x + 0.6, y + 0.1), (x - 0.1, y + 0.25)])]
|
||
s.append(P([(x - 0.1, y - 0.05), (x - 0.7, y + wy), (x + 0.3, y - 0.05)]))
|
||
s.append(P([(x + 0.75, y - 0.3), (x + 1.0, y - 0.2), (x + 0.75, y - 0.15)])) # beak
|
||
s.append(P([(x - 0.4, y), (x - 0.85, y - 0.25), (x - 0.75, y + 0.2)])) # tail
|
||
return s
|
||
|
||
|
||
def sprout(i, t):
|
||
"""A vine climbs out of the box in fits and starts, sprouting leaves left and right."""
|
||
steps = [0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6][i]
|
||
pts = [(0, 0)]
|
||
for k in range(steps):
|
||
pts.append(((0.35 if k % 2 else -0.35), -(k + 1) * 0.6))
|
||
s = [L(pts, 0.16)]
|
||
for k in range(1, steps):
|
||
x, y = pts[k]
|
||
d = 1 if k % 2 else -1
|
||
g = min(1.0, (steps - k) / 2 + 0.4)
|
||
s.append(P([(x, y), (x + d * 0.5 * g, y - 0.45 * g), (x + d * 1.0 * g, y - 0.1 * g), (x + d * 0.5 * g, y + 0.1)]))
|
||
if i >= 10:
|
||
x, y = pts[-1]
|
||
s.append(P(star(x, y - 0.2, 0.45, 0.2, 5, i * 0.4)))
|
||
return s
|
||
|
||
|
||
def confetti(i, t):
|
||
"""A cannon of tumbling paper squares that arcs out and flutters down."""
|
||
s = []
|
||
rng = random.Random(77)
|
||
for m in range(14):
|
||
vx, vy = rng.uniform(-2.4, 3.2), rng.uniform(-6.5, -3.5)
|
||
tt = t * 1.1
|
||
x, y = vx * tt, vy * tt + 7.0 * tt * tt
|
||
if i == 0:
|
||
x, y = x * 0.3, y * 0.3
|
||
spin = i * rng.uniform(0.6, 1.4) + m
|
||
sz = 0.22
|
||
sq = rotate([(x - sz, y - sz * abs(math.cos(spin))), (x + sz, y - sz * abs(math.cos(spin))),
|
||
(x + sz, y + sz * abs(math.cos(spin))), (x - sz, y + sz * abs(math.cos(spin)))], spin * 0.7, x, y)
|
||
s.append(P(sq, 0, 0.03))
|
||
return s
|
||
|
||
|
||
def worm(i, t):
|
||
"""A worm wriggles out of the box and inches off to the right."""
|
||
head = min(1.0, t * 1.5)
|
||
s = []
|
||
pts = []
|
||
n = 14
|
||
for k in range(n + 1):
|
||
f = k / n
|
||
x = f * 3.0 * head + t * 1.4
|
||
y = -0.6 * math.sin(f * 2 * math.pi * 1.2 + i * 1.1) * head - 0.4 * head
|
||
pts.append((x, y))
|
||
s.append(L(pts, 0.32, 0.03))
|
||
hx, hy = pts[-1]
|
||
s.append(C(hx, hy, 0.24))
|
||
s.append(L([(hx, hy - 0.2), (hx + 0.15, hy - 0.6)], 0.07))
|
||
s.append(L([(hx + 0.1, hy - 0.15), (hx + 0.45, hy - 0.5)], 0.07))
|
||
return s
|
||
|
||
|
||
def lightning(i, t):
|
||
"""A bolt cracks up out of the box, flashes twice, and leaves sparks."""
|
||
s = []
|
||
if i in (0, 1, 2, 5, 6, 9):
|
||
reach = min(1.0, (i + 1) / 3)
|
||
zz = [(0, 0), (0.6, -1.0), (-0.1, -1.4), (0.8, -2.6), (0.1, -2.9), (1.0, -4.3)]
|
||
cut = max(2, int(len(zz) * reach))
|
||
pts = zz[:cut]
|
||
left = [(x - 0.2, y) for x, y in pts]
|
||
right = [(x + 0.2, y) for x, y in reversed(pts)]
|
||
s.append(P(left + right, 0, 0.08))
|
||
if i in (5, 9):
|
||
s.append(P(star(0.4, -2.2, 2.0, 0.7, 6, i), 0.1))
|
||
if i >= 7:
|
||
for m in range(5):
|
||
a = m * 1.3 + i
|
||
r = (i - 6) * 0.55
|
||
s.append(L([(1.0 + r * math.cos(a), -4.3 + r * math.sin(a)),
|
||
(1.0 + (r + 0.3) * math.cos(a), -4.3 + (r + 0.3) * math.sin(a))], 0.1))
|
||
return s
|
||
|
||
|
||
def spiral(i, t):
|
||
"""A spiral unwinds out of the box, turning a notch each frame, then springs away."""
|
||
s = []
|
||
turns = 0.4 + min(1.0, t * 1.6) * 2.4
|
||
pts = []
|
||
rot = -i * 0.55
|
||
k = 0
|
||
while k / 10 <= turns:
|
||
a = k / 10 * 2 * math.pi + rot
|
||
r = 0.15 + k / 10 * 0.55
|
||
pts.append((r * math.cos(a), r * math.sin(a) - (0 if i < 9 else (i - 8) * 0.9)))
|
||
k += 1
|
||
s.append(L(pts, 0.16))
|
||
return s
|
||
|
||
|
||
def heart(i, t):
|
||
"""A heart thumps its way up out of the box, big-small-big."""
|
||
size = [0.3, 0.7, 1.1, 0.8, 1.2, 0.85, 1.25, 0.9, 1.2, 1.0, 1.1, 1.0][i]
|
||
y = -0.4 - min(1.0, t * 1.7) * 3.0
|
||
pts = []
|
||
for k in range(20):
|
||
a = k * 2 * math.pi / 20
|
||
x = 16 * math.sin(a) ** 3
|
||
yy = -(13 * math.cos(a) - 5 * math.cos(2 * a) - 2 * math.cos(3 * a) - math.cos(4 * a))
|
||
pts.append((x / 16 * 0.75 * size, y + yy / 16 * 0.75 * size))
|
||
s = [P(pts)]
|
||
if size >= 1.15:
|
||
for m in (-1, 1):
|
||
s.append(L([(m * 1.1, y - 0.6), (m * 1.5, y - 0.9)], 0.1))
|
||
s.append(L([(m * 1.2, y + 0.1), (m * 1.6, y + 0.1)], 0.1))
|
||
return s
|
||
|
||
|
||
def fish(i, t):
|
||
"""A fish leaps out of the box in an arc and dives back in with a splash."""
|
||
s = []
|
||
a = t * math.pi
|
||
x, y = -1.8 * math.cos(a) + 1.8 - 1.8, -3.0 * math.sin(a)
|
||
x = 3.4 * t - 0.2
|
||
head = -math.atan2(3.0 * math.cos(a) * math.pi, 3.4)
|
||
body = [(0.6, 0), (0.15, -0.35), (-0.4, -0.2), (-0.7, -0.45), (-0.6, 0), (-0.7, 0.45), (-0.4, 0.2), (0.15, 0.35)]
|
||
body = [(x + bx * 1.6, y + by * 1.6) for bx, by in body]
|
||
s.append(P(rotate(body, head, x, y)))
|
||
if i in (0, 1):
|
||
for m in range(4):
|
||
s.append(C(-0.6 + m * 0.4, -0.3 - (i + 1) * 0.35 * (1 + m % 2), 0.1))
|
||
if i >= 10:
|
||
for m in range(5):
|
||
dx = (m - 2) * 0.35 * (i - 9)
|
||
s.append(L([(3.2 + dx * 0.5, -0.2), (3.2 + dx, -0.6 - (i - 9) * 0.35 + abs(m - 2) * 0.2)], 0.1))
|
||
return s
|
||
|
||
|
||
def sun(i, t):
|
||
"""The sun rises out of the box; its rays click round one notch per frame."""
|
||
y = -min(1.0, t * 2.0) * 2.2
|
||
r = 0.75
|
||
s = [P(ring(0, y, r, 14, 0, 0.04))]
|
||
n = 9
|
||
rot = i * 0.2
|
||
reach = min(1.0, max(0.0, (t - 0.25) * 2.5))
|
||
for k in range(n):
|
||
a = rot + k * 2 * math.pi / n
|
||
r0 = r + 0.25
|
||
r1 = r0 + (0.25 + 0.6 * reach) * (1.0 if k % 2 else 0.7)
|
||
s.append(L([(r0 * math.cos(a), y + r0 * math.sin(a)), (r1 * math.cos(a), y + r1 * math.sin(a))], 0.16))
|
||
return s
|
||
|
||
|
||
def ripples(i, t):
|
||
"""Rings spread out of the box, a new one every few frames, thinning as they go."""
|
||
s = []
|
||
for start in (0, 3, 6):
|
||
k = i - start
|
||
if k < 0:
|
||
continue
|
||
r = 0.6 + k * 0.5
|
||
w = max(0.04, 0.22 - k * 0.025)
|
||
if r < 4.6:
|
||
s.append(P(ring(0, 0, r, 16, k * 0.3, 0.07), w))
|
||
if i < 3:
|
||
s.append(C(0, 0, 0.3 - i * 0.08))
|
||
return s
|
||
|
||
|
||
def tentacle(i, t):
|
||
"""A tentacle reaches out of the box, curls its tip, waves and uncurls."""
|
||
s = []
|
||
curl = [0.2, 0.6, 1.2, 2.0, 2.6, 3.0, 2.6, 2.0, 2.8, 3.2, 2.4, 1.6][i]
|
||
reach = min(1.0, (i + 1) / 4)
|
||
pts = []
|
||
x, y, a = 0.0, 0.0, -math.pi / 2 + 0.2 + math.sin(i * 1.1) * 0.55
|
||
n = 16
|
||
for k in range(n):
|
||
pts.append((x, y))
|
||
f = k / n
|
||
step = 0.32 * reach * (1 - f * 0.45)
|
||
a += curl * f * f * 0.25 * (1 if i % 4 < 2 else 1.25)
|
||
x += math.cos(a) * step
|
||
y += math.sin(a) * step
|
||
left, right = [], []
|
||
for k, (px, py) in enumerate(pts):
|
||
w = 0.32 * (1 - k / n) + 0.04
|
||
nx, ny = (pts[min(k + 1, n - 1)][1] - pts[max(k - 1, 0)][1]), -(pts[min(k + 1, n - 1)][0] - pts[max(k - 1, 0)][0])
|
||
d = math.hypot(nx, ny) or 1
|
||
left.append((px + nx / d * w, py + ny / d * w))
|
||
right.append((px - nx / d * w, py - ny / d * w))
|
||
s.append(P(left + list(reversed(right)), 0, 0.03))
|
||
for k in range(3, n - 3, 3):
|
||
px, py = pts[k]
|
||
s.append(C(px, py, 0.07))
|
||
return s
|
||
|
||
|
||
def butterfly(i, t):
|
||
"""A butterfly flutters up out of the box, wings snapping open and shut."""
|
||
x = math.sin(i * 0.9) * 1.0 + t * 1.5
|
||
y = -0.6 - t * 4.0
|
||
w = [1.0, 0.35, 1.0, 0.25, 1.0, 0.4, 1.0, 0.3, 1.0, 0.35, 1.0, 0.3][i]
|
||
s = []
|
||
for side in (-1, 1):
|
||
s.append(P([(x, y), (x + side * 0.95 * w, y - 0.75), (x + side * 0.7 * w, y - 0.05)]))
|
||
s.append(P([(x, y + 0.05), (x + side * 0.65 * w, y + 0.55), (x + side * 0.2 * w, y + 0.6)]))
|
||
s.append(L([(x, y - 0.4), (x, y + 0.55)], 0.13))
|
||
s.append(L([(x, y - 0.4), (x - 0.25, y - 0.8)], 0.06))
|
||
s.append(L([(x, y - 0.4), (x + 0.25, y - 0.8)], 0.06))
|
||
return s
|
||
|
||
|
||
def ghost(i, t):
|
||
"""A little ghost bobs up out of the box, says boo with a wide mouth, then fades to dots."""
|
||
if i >= 10:
|
||
y = -3.0
|
||
return [C(R.uniform(-0.8, 0.8), y + R.uniform(-0.8, 0.8), 0.12) for _ in range(7 - (i - 10) * 3)]
|
||
y = -min(1.0, (i + 1) / 5) * 3.0 + math.sin(i * 1.4) * 0.15
|
||
top = [(0.7 * math.cos(a), y - 0.4 + 0.7 * math.sin(a)) for a in [math.pi + k * math.pi / 6 for k in range(7)]]
|
||
hem = []
|
||
for k in range(7):
|
||
hx = 0.7 - k * (1.4 / 6)
|
||
hem.append((hx, y + 0.8 + (0.18 if (k + i) % 2 else -0.05)))
|
||
s = [P(top + hem, 0.13)]
|
||
s.append(C(-0.25, y - 0.4, 0.11))
|
||
s.append(C(0.25, y - 0.4, 0.11))
|
||
if i in (6, 7, 8):
|
||
s.append(C(0, y + 0.15, 0.22, 0.09))
|
||
s.append(L([(0.9, y - 0.6), (1.4, y - 1.0)], 0.08))
|
||
s.append(L([(1.0, y - 0.2), (1.6, y - 0.25)], 0.08))
|
||
return s
|
||
|
||
|
||
# ── set 1 and set 2 (added 2026-11-06) ─────────────────────────────────────────
|
||
|
||
def frog(i, t):
|
||
"""A frog crouches in the box, leaps up and over, flicks its tongue at a fly, lands."""
|
||
s = []
|
||
fly = (2.0, -3.6)
|
||
if i < 3:
|
||
x, y, sq = 0.0, 0.0, 1 - i * 0.12
|
||
elif i < 10:
|
||
u = (i - 3) / 6
|
||
x, y, sq = 3.0 * u, -3.4 * 4 * u * (1 - u), 1.15
|
||
else:
|
||
x, y, sq = 3.0, 0.0, 0.75 + (i - 10) * 0.1
|
||
w, h = 0.75 / sq ** 0.5, 0.55 * sq
|
||
s.append(P([(x - w, y), (x - w * 0.7, y - h), (x - 0.2, y - h * 1.35), (x + 0.2, y - h * 1.35), (x + w * 0.7, y - h), (x + w, y)]))
|
||
s.append(C(x - 0.3, y - h * 1.4, 0.17, 0.08))
|
||
s.append(C(x + 0.3, y - h * 1.4, 0.17, 0.08))
|
||
if 3 <= i < 10:
|
||
s.append(L([(x - w, y), (x - w - 0.4, y + 0.45)], 0.12))
|
||
s.append(L([(x + w, y), (x + w + 0.4, y + 0.45)], 0.12))
|
||
if i in (6, 7):
|
||
s.append(L([(x, y - h), fly], 0.09))
|
||
if i < 7:
|
||
s.append(C(fly[0] + R.uniform(-0.2, 0.2), fly[1] + R.uniform(-0.2, 0.2), 0.08))
|
||
return s
|
||
|
||
|
||
def snail(i, t):
|
||
"""A snail slides out of the box, its eye stalks waving, leaving a trail."""
|
||
x = -0.3 + t * 2.4
|
||
s = [P(ring(x, -0.55, 0.55, 12, 0, 0.03), 0.12)]
|
||
pts = []
|
||
for k in range(18):
|
||
a = k * 0.6 + i * 0.1
|
||
r = 0.45 - k * 0.024
|
||
pts.append((x + r * math.cos(a), -0.55 + r * math.sin(a)))
|
||
s.append(L(pts, 0.08, 0.02))
|
||
s.append(P([(x - 0.6, 0.02), (x + 1.1, 0.02), (x + 1.25, -0.25), (x + 0.6, -0.12), (x - 0.4, -0.1)]))
|
||
for k, ph in ((0, 0.0), (1, 1.3)):
|
||
ex = x + 1.0 + k * 0.25 + math.sin(i * 1.4 + ph) * 0.15
|
||
s.append(L([(x + 1.0 + k * 0.15, -0.2), (ex, -0.85)], 0.07))
|
||
s.append(C(ex, -0.88, 0.09))
|
||
if i > 1:
|
||
s.append(L([(-0.3, 0.12), (x - 0.6, 0.12)], 0.05))
|
||
return s
|
||
|
||
|
||
def cat(i, t):
|
||
"""A cat pops its head up out of the box, looks about, winks, twitches its whiskers."""
|
||
y = [-0.3, -0.8, -1.3, -1.6, -1.5, -1.55, -1.5, -1.5, -1.52, -1.5, -1.45, -1.3][i]
|
||
lean = [0, 0, 0, 0, 0.15, 0.3, 0.3, 0.1, -0.15, -0.3, -0.1, 0][i]
|
||
cx = lean
|
||
s = [P(ring(cx, y, 0.75, 14, 0, 0.03), 0.12)]
|
||
s.append(P([(cx - 0.7, y - 0.25), (cx - 0.65, y - 1.15), (cx - 0.2, y - 0.65)]))
|
||
s.append(P([(cx + 0.7, y - 0.25), (cx + 0.65, y - 1.15), (cx + 0.2, y - 0.65)]))
|
||
if i in (7, 8):
|
||
s.append(L([(cx - 0.38, y - 0.1), (cx - 0.14, y - 0.1)], 0.08))
|
||
else:
|
||
s.append(C(cx - 0.26 + lean * 0.3, y - 0.12, 0.1))
|
||
s.append(C(cx + 0.26 + lean * 0.3, y - 0.12, 0.1))
|
||
tw = 0.12 if i % 3 == 0 else 0
|
||
for side in (-1, 1):
|
||
s.append(L([(cx + side * 0.2, y + 0.2), (cx + side * 1.15, y + 0.05 - tw)], 0.05))
|
||
s.append(L([(cx + side * 0.2, y + 0.28), (cx + side * 1.15, y + 0.38 + tw)], 0.05))
|
||
return s
|
||
|
||
|
||
def umbrella(i, t):
|
||
"""An umbrella shoots up out of the box and pops open; raindrops bounce off it."""
|
||
top = -min(1.0, (i + 1) / 4) * 2.6
|
||
s = [L([(0.15, 0.2), (0, 0.4 + top * 0.0), (0, top)], 0.1)]
|
||
s.append(L([(0, 0.4), (0.25, 0.55), (0.35, 0.35)], 0.1))
|
||
o = [0.0, 0.0, 0.15, 0.35, 0.8, 1.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0][i]
|
||
if o == 0:
|
||
s.append(P([(0, top - 0.2), (0.18, top + 1.2), (-0.18, top + 1.2)]))
|
||
else:
|
||
W = 1.6 * o
|
||
pts = [(-W, top + 0.6), (-W * 0.7, top - 0.2), (0, top - 0.55), (W * 0.7, top - 0.2), (W, top + 0.6)]
|
||
for k in range(4, -1, -1):
|
||
pts.append((-W + k * W / 2, top + 0.6 - (0.25 if k % 2 else 0)))
|
||
s.append(P(pts))
|
||
if i >= 5:
|
||
for m in range(4):
|
||
dx = -1.5 + m
|
||
ph = (i - 5 + m) % 4
|
||
if ph < 2:
|
||
s.append(L([(dx, top - 2.2 + ph * 0.8), (dx, top - 1.9 + ph * 0.8)], 0.08))
|
||
else:
|
||
s.append(C(dx + (ph - 2) * 0.3 * (1 if dx > 0 else -1), top - 0.6 - (ph - 2) * 0.2, 0.07))
|
||
return s
|
||
|
||
|
||
def paperplane(i, t):
|
||
"""A paper plane darts out of the box and does a loop-the-loop, trailing dashes."""
|
||
def pos(u):
|
||
if u < 0.3:
|
||
return (u / 0.3 * 2.0, -u / 0.3 * 1.5)
|
||
if u < 0.8:
|
||
a = (u - 0.3) / 0.5 * 2 * math.pi
|
||
return (2.0 + 1.0 * math.sin(a), -1.5 - 1.0 + 1.0 * math.cos(a))
|
||
return (2.0 + (u - 0.8) / 0.2 * 2.5, -1.5 - (u - 0.8) / 0.2 * 1.2)
|
||
x, y = pos(t)
|
||
x2, y2 = pos(min(1.0, t + 0.04))
|
||
ang = math.atan2(y2 - y, x2 - x)
|
||
s = [P(rotate([(x + 0.55, y), (x - 0.45, y - 0.35), (x - 0.25, y), (x - 0.45, y + 0.3)], ang, x, y))]
|
||
for k in range(1, 5):
|
||
u = t - k * 0.07
|
||
if u > 0:
|
||
px, py = pos(u)
|
||
s.append(C(px, py, 0.06))
|
||
return s
|
||
|
||
|
||
def kite(i, t):
|
||
"""A kite climbs out of the box in a zigzag, its bow tail flapping."""
|
||
x = math.sin(i * 1.1) * 0.6 + t * 1.2
|
||
y = -0.6 - t * 3.6
|
||
tilt = math.sin(i * 1.1) * 0.3
|
||
s = [P(rotate([(x, y - 0.75), (x + 0.5, y), (x, y + 0.45), (x - 0.5, y)], tilt, x, y))]
|
||
tail = [(x, y + 0.45)]
|
||
for k in range(1, 6):
|
||
tail.append((x + math.sin(i * 1.6 + k) * 0.3 - k * 0.1, y + 0.45 + k * 0.4))
|
||
s.append(L(tail, 0.06))
|
||
for k in (2, 4):
|
||
bx, by = tail[k]
|
||
s.append(P([(bx, by), (bx - 0.2, by - 0.12), (bx - 0.2, by + 0.12)]))
|
||
s.append(P([(bx, by), (bx + 0.2, by - 0.12), (bx + 0.2, by + 0.12)]))
|
||
return s
|
||
|
||
|
||
def snowflake(i, t):
|
||
"""A snowflake crystallises out of the box arm by arm, ticking round as it drifts up."""
|
||
y = -1.6 - t * 1.6
|
||
grow = min(1.0, (i + 1) / 6)
|
||
rot = i * math.pi / 18
|
||
s = []
|
||
for k in range(6):
|
||
a = rot + k * math.pi / 3
|
||
L1 = 1.2 * grow
|
||
ca, sa = math.cos(a), math.sin(a)
|
||
s.append(L([(0, y), (L1 * ca, y + L1 * sa)], 0.1))
|
||
for f in (0.45, 0.75):
|
||
if grow * 1.2 > f * 1.2:
|
||
bx, by = f * L1 * ca, y + f * L1 * sa
|
||
for d in (-0.6, 0.6):
|
||
b = a + d
|
||
ln = 0.35 * grow * (1.1 - f)
|
||
s.append(L([(bx, by), (bx + ln * math.cos(b), by + ln * math.sin(b))], 0.07))
|
||
s.append(C(0, y, 0.15))
|
||
return s
|
||
|
||
|
||
def raincloud(i, t):
|
||
"""A cloud puffs up out of the box and rains a little shower on it."""
|
||
cy = -min(1.0, (i + 1) / 4) * 2.8
|
||
sc = min(1.0, (i + 1) / 3)
|
||
s = []
|
||
for dx, dy, r in ((-0.6, 0.1, 0.5), (0, -0.25, 0.65), (0.65, 0.05, 0.5), (0.25, 0.25, 0.45), (-0.25, 0.25, 0.45)):
|
||
s.append(P(ring(dx * sc, cy + dy * sc, r * sc, 10, 0, 0.04)))
|
||
if i >= 4:
|
||
for m in range(5):
|
||
x = -0.8 + m * 0.4
|
||
ph = ((i - 4) * 0.45 + m * 0.37) % 1.6
|
||
y0 = cy + 0.6 + ph
|
||
if y0 < -0.3:
|
||
s.append(L([(x, y0), (x - 0.06, y0 + 0.3)], 0.08))
|
||
else:
|
||
s.append(L([(x - 0.15, -0.25), (x - 0.25, -0.45)], 0.05))
|
||
return s
|
||
|
||
|
||
def moon(i, t):
|
||
"""A crescent moon rises out of the box; little stars blink on around it."""
|
||
y = -0.4 - min(1.0, t * 1.8) * 2.4
|
||
outer = [(0.9 * math.cos(a), y + 0.9 * math.sin(a)) for a in [math.pi * 0.35 + k * math.pi * 1.3 / 10 for k in range(11)]]
|
||
inner = [(0.35 + 0.7 * math.cos(a), y - 0.15 + 0.7 * math.sin(a)) for a in [math.pi * 1.65 - k * math.pi * 1.3 / 10 for k in range(11)]]
|
||
s = [P(outer + inner)]
|
||
spots = [(1.6, -3.4), (-1.4, -2.8), (1.9, -1.6), (-0.8, -4.2), (0.9, -4.5)]
|
||
for k, (sx, sy) in enumerate(spots):
|
||
if i >= 3 + k and (i + k) % 3 != 0:
|
||
s.append(P(star(sx, sy, 0.3, 0.09, 4, 0)))
|
||
return s
|
||
|
||
|
||
def tree(i, t):
|
||
"""A tree grows out of the box: trunk, then branches split, then a canopy pops on."""
|
||
s = []
|
||
depth = min(4, i // 2 + 1)
|
||
|
||
def branch(x, y, a, ln, d):
|
||
x2, y2 = x + ln * math.cos(a), y + ln * math.sin(a)
|
||
s.append(L([(x, y), (x2, y2)], 0.06 + 0.04 * (4 - d)))
|
||
if d + 1 < depth:
|
||
branch(x2, y2, a - 0.45, ln * 0.7, d + 1)
|
||
branch(x2, y2, a + 0.45, ln * 0.7, d + 1)
|
||
elif i >= 8:
|
||
s.append(C(x2, y2, 0.22 + 0.04 * (i - 8)))
|
||
branch(0, 0, -math.pi / 2, 1.3, 0)
|
||
return s
|
||
|
||
|
||
def mushroom(i, t):
|
||
"""A mushroom pushes up out of the box, its spotted cap boinging."""
|
||
h = [0.1, 0.4, 0.9, 1.4, 1.2, 1.35, 1.25, 1.3, 1.3, 1.3, 1.3, 1.3][i]
|
||
sq = [1, 1, 1, 0.8, 1.25, 0.9, 1.1, 1, 1, 1, 1, 1][i]
|
||
s = [P([(-0.25, 0), (-0.2, -h), (0.2, -h), (0.25, 0)])]
|
||
W, H = 1.0 / sq ** 0.5, 0.7 * sq
|
||
cap = [(W * math.cos(a), -h + 0.1 - H * math.sin(a)) for a in [k * math.pi / 10 for k in range(11)]]
|
||
s.append(P(cap))
|
||
for dx, dy in ((-0.45, 0.35), (0.1, 0.55), (0.5, 0.3)):
|
||
s.append(C(dx * W, -h + 0.1 - dy * H, 0.11, 0.06))
|
||
return s
|
||
|
||
|
||
def volcano(i, t):
|
||
"""A volcano heaves up out of the box and spits blobs of lava that arc and fall."""
|
||
hgt = min(1.0, (i + 1) / 3) * 1.3
|
||
s = [P([(-1.3, 0.3), (-0.3, -hgt), (0.3, -hgt), (1.3, 0.3)], 0.12)]
|
||
if i >= 3:
|
||
rng = random.Random(5)
|
||
for m in range(6):
|
||
vx, vy = rng.uniform(-1.8, 1.8), rng.uniform(-5.5, -3.5)
|
||
tt = (i - 3) / 8 - m * 0.05
|
||
if tt <= 0:
|
||
continue
|
||
x, y = vx * tt, -hgt + vy * tt + 6.5 * tt * tt
|
||
if y < 0.3:
|
||
s.append(P(ring(x, y, 0.18, 7, 0, 0.05)))
|
||
if i in (3, 4, 5):
|
||
s.append(P(star(0, -hgt - 0.3, 0.6, 0.25, 6, i)))
|
||
return s
|
||
|
||
|
||
def whale(i, t):
|
||
"""A whale's back rolls up out of the box and blows a fan-shaped spout."""
|
||
s = []
|
||
rise = min(1.0, (i + 1) / 4)
|
||
back = [(-1.4 + k * 0.28, -rise * 0.9 * math.sin(k * math.pi / 10)) for k in range(11)]
|
||
s.append(P(back + [(1.4, 0.1), (-1.4, 0.1)]))
|
||
s.append(P([(1.3, 0), (1.8, -0.6), (1.6, -0.05), (2.05, -0.3), (1.5, 0.1)]))
|
||
if i >= 4:
|
||
h = min(1.0, (i - 3) / 3) * 2.2
|
||
top = -0.9 - h
|
||
s.append(L([(0, -0.9), (0, top)], 0.12))
|
||
for d in (-1, -0.5, 0.5, 1):
|
||
s.append(L([(0, top), (d * 0.7, top + 0.4 + (i % 2) * 0.1)], 0.08))
|
||
if i >= 8:
|
||
for d in (-1, 1):
|
||
s.append(C(d * (0.9 + (i - 8) * 0.25), top + 0.9 + (i - 8) * 0.35, 0.09))
|
||
return s
|
||
|
||
|
||
def ufo(i, t):
|
||
"""A flying saucer swoops down over the box, beams at it, and zips away."""
|
||
if i < 4:
|
||
x, y = 4.0 - i * 1.0, -3.6 + i * 0.3
|
||
elif i < 9:
|
||
x, y = 0.0 + R.uniform(-0.05, 0.05), -2.7
|
||
else:
|
||
x, y = (i - 8) * 1.6, -2.7 - (i - 8) * 1.1
|
||
s = [P([(x - 1.0, y), (x - 0.4, y - 0.3), (x + 0.4, y - 0.3), (x + 1.0, y), (x + 0.4, y + 0.25), (x - 0.4, y + 0.25)])]
|
||
s.append(P(ring(x, y - 0.35, 0.35, 9, 0, 0.02)[5:] + ring(x, y - 0.35, 0.35, 9, 0, 0.02)[:1], 0.08))
|
||
if 4 <= i < 9:
|
||
s.append(P([(x - 0.3, y + 0.3), (x + 0.3, y + 0.3), (x + 0.8, -0.2), (x - 0.8, -0.2)], 0.07))
|
||
for k in range(3):
|
||
yy = -0.4 - ((i - 4) * 0.45 + k * 0.7) % 2.0
|
||
s.append(L([(x - 0.25, yy), (x + 0.25, yy)], 0.05))
|
||
return s
|
||
|
||
|
||
def crab(i, t):
|
||
"""A crab scuttles sideways out of the box, snapping its claws."""
|
||
x = t * 3.0
|
||
y = -0.45 + (0.08 if i % 2 else 0)
|
||
s = [P(ring(x, y, 0.55, 10, 0, 0.04)[0:6] + [(x - 0.55, y + 0.05)])]
|
||
snap = i % 2 == 0
|
||
for side in (-1, 1):
|
||
ax, ay = x + side * 0.55, y - 0.25
|
||
cx, cy = x + side * 0.95, y - 0.85
|
||
s.append(L([(ax, ay), (cx, cy)], 0.09))
|
||
o = 0.35 if snap else 0.1
|
||
s.append(P([(cx, cy), (cx + side * 0.25, cy - 0.35), (cx + side * 0.05, cy - 0.05 - o * 0.3)]))
|
||
s.append(P([(cx, cy), (cx + side * 0.4, cy - 0.05), (cx + side * 0.1, cy + 0.05)]))
|
||
for k in range(3):
|
||
lx = x + side * (0.25 + k * 0.15)
|
||
s.append(L([(lx, y + 0.05), (lx + side * 0.3, y + 0.35 + (0.08 if (i + k) % 2 else 0))], 0.06))
|
||
s.append(L([(x - 0.15, y - 0.5), (x - 0.2, y - 0.8)], 0.05))
|
||
s.append(L([(x + 0.15, y - 0.5), (x + 0.2, y - 0.8)], 0.05))
|
||
return s
|
||
|
||
|
||
def notes(i, t):
|
||
"""Music notes bubble up out of the box, one after another, swaying."""
|
||
s = []
|
||
for k in range(4):
|
||
u = t * 1.3 - k * 0.22
|
||
if u <= 0 or u > 1:
|
||
continue
|
||
x = (k - 1.5) * 0.7 + math.sin(u * 7 + k) * 0.35
|
||
y = -0.5 - u * 4.2
|
||
tilt = math.sin(i + k) * 0.2
|
||
head = rotate(ring(x, y, 0.22, 8, 0, 0.02), tilt - 0.4, x, y)
|
||
s.append(P(head))
|
||
s.append(L([(x + 0.2, y - 0.05), (x + 0.2, y - 0.95)], 0.07))
|
||
if k % 2:
|
||
s.append(L([(x + 0.2, y - 0.95), (x + 0.55, y - 0.6)], 0.07))
|
||
else:
|
||
s.append(P([(x + 0.2, y - 0.95), (x + 0.75, y - 0.8), (x + 0.75, y - 0.6), (x + 0.2, y - 0.75)]))
|
||
return s
|
||
|
||
|
||
def pinwheel(i, t):
|
||
"""A pinwheel on a stick pops up and spins in big 45-degree clicks."""
|
||
top = -min(1.0, (i + 1) / 3) * 2.4
|
||
s = [L([(0, 0.3), (0, top)], 0.1)]
|
||
rot = i * math.pi / 4
|
||
for k in range(4):
|
||
a = rot + k * math.pi / 2
|
||
p1 = (0.95 * math.cos(a), top + 0.95 * math.sin(a))
|
||
p2 = (0.95 * math.cos(a + 0.7), top + 0.95 * math.sin(a + 0.7))
|
||
s.append(P([(0, top), p1, p2]))
|
||
s.append(C(0, top, 0.1))
|
||
return s
|
||
|
||
|
||
def bubbles(i, t):
|
||
"""Soap bubbles wobble up out of the box and pop one by one."""
|
||
s = []
|
||
rng = random.Random(31)
|
||
for k in range(6):
|
||
x0, r, sp, popat = rng.uniform(-1.2, 1.8), rng.uniform(0.35, 0.7), rng.uniform(3, 4.5), rng.randint(5, 11)
|
||
u = t - k * 0.06
|
||
if u <= 0:
|
||
continue
|
||
x, y = x0 + math.sin(u * 8 + k) * 0.2, -0.4 - u * sp
|
||
if i < popat:
|
||
s.append(P(ring(x, y, r, 12, k, 0.05), 0.09))
|
||
s.append(L([(x - r * 0.45, y - r * 0.35), (x - r * 0.2, y - r * 0.6)], 0.07))
|
||
elif i == popat:
|
||
for m in range(5):
|
||
a = m * 1.26
|
||
s.append(L([(x + r * math.cos(a), y + r * math.sin(a)), (x + r * 1.6 * math.cos(a), y + r * 1.6 * math.sin(a))], 0.08))
|
||
return s
|
||
|
||
|
||
def target(i, t):
|
||
"""A target appears; an arrow flies out of the box and thunks into the bullseye."""
|
||
tx, ty = 3.2, -2.4
|
||
s = []
|
||
for r in (1.0, 0.65, 0.3):
|
||
if i >= (1.0 - r) * 4:
|
||
s.append(P(ring(tx, ty, r, 14, 0, 0.03), 0.09))
|
||
if 3 <= i < 7:
|
||
u = (i - 2) / 4
|
||
x, y = u * (tx - 0.1), u * ty
|
||
elif i >= 7:
|
||
x, y = tx - 0.1, ty
|
||
else:
|
||
x, y = 0, 0
|
||
ang = math.atan2(ty, tx)
|
||
if i >= 2:
|
||
wob = math.sin(i * 2.5) * 0.12 if i >= 7 else 0
|
||
back = (x - 1.2 * math.cos(ang + wob), y - 1.2 * math.sin(ang + wob))
|
||
s.append(L([back, (x, y)], 0.08))
|
||
s.append(P(rotate([(x + 0.1, y), (x - 0.25, y - 0.15), (x - 0.25, y + 0.15)], ang + wob, x, y)))
|
||
s.append(P(rotate([(back[0], back[1]), (back[0] - 0.25, back[1] - 0.2), (back[0] + 0.1, back[1])], ang + wob, *back)))
|
||
if i in (7, 8):
|
||
for m in range(4):
|
||
a = m * 1.57 + 0.78
|
||
s.append(L([(tx + 0.5 * math.cos(a), ty + 0.5 * math.sin(a)), (tx + 0.8 * math.cos(a), ty + 0.8 * math.sin(a))], 0.06))
|
||
return s
|
||
|
||
|
||
def dice(i, t):
|
||
"""Two dice tumble out of the box, clatter, and land showing double six."""
|
||
s = []
|
||
for k, (vx, spin) in enumerate(((1.4, 1.2), (2.6, -0.9))):
|
||
if i < 8:
|
||
u = i / 7
|
||
x, y = vx * u, -2.6 * 4 * u * (1 - u) * (1 - k * 0.3) - 0.4
|
||
a = spin * i
|
||
else:
|
||
x, y, a = vx, -0.4, 0.0
|
||
sq = rotate([(x - 0.4, y - 0.4), (x + 0.4, y - 0.4), (x + 0.4, y + 0.4), (x - 0.4, y + 0.4)], a, x, y)
|
||
s.append(P(sq, 0.08))
|
||
pips = [(-0.2, -0.2), (-0.2, 0), (-0.2, 0.2), (0.2, -0.2), (0.2, 0), (0.2, 0.2)] if i >= 8 else \
|
||
[(-0.18, -0.18), (0, 0), (0.18, 0.18)] if (i + k) % 2 else [(0, 0)]
|
||
for px, py in rotate([(x + px, y + py) for px, py in pips], a, x, y):
|
||
s.append(C(px, py, 0.07))
|
||
return s
|
||
|
||
|
||
def hourglass(i, t):
|
||
"""An hourglass rises out of the box, flips over in clicks, and sand trickles down."""
|
||
y = -min(1.0, (i + 1) / 3) * 2.0
|
||
flip = min(1.0, max(0.0, (i - 3) / 4)) * math.pi
|
||
flip = round(flip / (math.pi / 4)) * (math.pi / 4)
|
||
pts = [(-0.6, y - 0.9), (0.6, y - 0.9), (0.08, y), (0.6, y + 0.9), (-0.6, y + 0.9), (-0.08, y)]
|
||
s = [P(rotate(pts, flip, 0, y), 0.09)]
|
||
s.append(L(rotate([(-0.75, y - 0.95), (0.75, y - 0.95)], flip, 0, y), 0.12))
|
||
s.append(L(rotate([(-0.75, y + 0.95), (0.75, y + 0.95)], flip, 0, y), 0.12))
|
||
if i >= 7:
|
||
f = (i - 7) / 4
|
||
s.append(P([(-0.45 * (1 - f), y - 0.75 + f * 0.6), (0.45 * (1 - f), y - 0.75 + f * 0.6), (0, y - 0.1)]))
|
||
s.append(L([(0, y), (0, y + 0.8)], 0.04))
|
||
s.append(P([(-0.5 * f - 0.05, y + 0.85), (0.5 * f + 0.05, y + 0.85), (0, y + 0.85 - 0.5 * f - 0.05)]))
|
||
return s
|
||
|
||
|
||
def gem(i, t):
|
||
"""A cut gem flips up out of the box, facets and all, and throws off sparkles."""
|
||
y = -min(1.0, (i + 1) / 4) * 2.2
|
||
w = abs(math.cos(i * 0.5)) * 0.4 + 0.6
|
||
s = [P([(-0.9 * w, y - 0.3), (-0.5 * w, y - 0.75), (0.5 * w, y - 0.75), (0.9 * w, y - 0.3), (0, y + 0.8)], 0.1)]
|
||
s.append(L([(-0.9 * w, y - 0.3), (0.9 * w, y - 0.3)], 0.07))
|
||
s.append(L([(-0.5 * w, y - 0.75), (-0.25 * w, y - 0.3), (0, y + 0.8), (0.25 * w, y - 0.3), (0.5 * w, y - 0.75)], 0.06))
|
||
for k, (sx, sy) in enumerate(((1.3, -0.6), (-1.2, 0.2), (0.8, 1.0), (-0.6, -1.3))):
|
||
if i >= 4 and (i + k) % 2 == 0:
|
||
r = 0.35 if (i + k) % 4 == 0 else 0.22
|
||
s.append(P(star(sx, y + sy, r, r * 0.25, 4, 0)))
|
||
return s
|
||
|
||
|
||
def padlock(i, t):
|
||
"""A padlock rises out of the box; its shackle springs open and it hops for joy."""
|
||
y = -min(1.0, (i + 1) / 3) * 1.8 - (0.4 if i in (8, 9) else 0)
|
||
s = [P([(-0.6, y - 0.4), (0.6, y - 0.4), (0.6, y + 0.5), (-0.6, y + 0.5)])]
|
||
open_ = min(1.0, max(0.0, (i - 4) / 2)) * 0.5
|
||
arc = [(-0.35 + 0.35 - 0.35 * math.cos(a), y - 0.4 - open_ - 0.5 * math.sin(a)) for a in [k * math.pi / 8 for k in range(9)]]
|
||
arc = [(x - 0.35 + 0.35, yy) for x, yy in arc]
|
||
left = [(-0.35, y - 0.4)] if open_ == 0 else [(-0.35, y - 0.4 - open_ * 0.3)]
|
||
s.append(L(left + [(-0.35, y - 0.4 - open_)] + [(-0.35 + 0.7 * k / 8, y - 0.4 - open_ - 0.55 * math.sin(k * math.pi / 8)) for k in range(9)] + [(0.35, y - 0.4 - open_ + 0.15)], 0.14))
|
||
s.append(P(ring(0, y + 0.05, 0.12, 6, 0, 0.01) + [(0.06, y + 0.3), (-0.06, y + 0.3)]))
|
||
if 5 <= i <= 7:
|
||
s.append(P(star(0.4, y - 1.2, 0.35, 0.12, 5, i)))
|
||
return s
|
||
|
||
|
||
def trophy(i, t):
|
||
"""A trophy cup rises out of the box on its plinth and shines."""
|
||
y = -min(1.0, (i + 1) / 4) * 2.0
|
||
s = [P([(-0.7, y - 0.8), (0.7, y - 0.8), (0.55, y - 0.1), (0.15, y + 0.2), (0.15, y + 0.5), (0.45, y + 0.7),
|
||
(-0.45, y + 0.7), (-0.15, y + 0.5), (-0.15, y + 0.2), (-0.55, y - 0.1)])]
|
||
for side in (-1, 1):
|
||
s.append(L([(side * 0.68, y - 0.65), (side * 1.0, y - 0.6), (side * 0.95, y - 0.25), (side * 0.55, y - 0.15)], 0.08))
|
||
if i >= 4:
|
||
n = 7
|
||
for k in range(n):
|
||
a = -math.pi + k * math.pi / (n - 1)
|
||
if (k + i) % 2 == 0:
|
||
r0, r1 = 1.2, 1.55 + (0.15 if i % 2 else 0)
|
||
s.append(L([(r0 * math.cos(a), y - 0.3 + r0 * math.sin(a)), (r1 * math.cos(a), y - 0.3 + r1 * math.sin(a))], 0.08))
|
||
return s
|
||
|
||
|
||
def crown(i, t):
|
||
"""A crown drops from above onto the box, bounces, and its jewels glint."""
|
||
y = [-5.0, -4.0, -2.8, -1.4, -0.75, -1.1, -0.75, -0.9, -0.75, -0.75, -0.75, -0.75][i]
|
||
sq = 0.8 if i in (4, 6) else 1.0
|
||
s = [P([(-0.9, y + 0.35), (-0.9, y - 0.45 * sq), (-0.45, y - 0.05), (0, y - 0.6 * sq), (0.45, y - 0.05),
|
||
(0.9, y - 0.45 * sq), (0.9, y + 0.35)])]
|
||
for x in (-0.9, 0, 0.9):
|
||
s.append(C(x, y - (0.6 if x == 0 else 0.45) * sq - 0.15, 0.1))
|
||
if i >= 8 and i % 2 == 0:
|
||
s.append(P(star(0.6, y - 0.9, 0.3, 0.08, 4, 0)))
|
||
if i in (4, 6):
|
||
s.append(L([(-1.3, y + 0.3), (-1.6, y + 0.1)], 0.06))
|
||
s.append(L([(1.3, y + 0.3), (1.6, y + 0.1)], 0.06))
|
||
return s
|
||
|
||
|
||
def rainbow(i, t):
|
||
"""A rainbow of nested arcs grows out of the box and lands to the right."""
|
||
s = []
|
||
cx = 1.6
|
||
for k in range(4):
|
||
r = 1.6 - k * 0.3
|
||
reach = min(1.0, max(0.0, t * 1.6 - k * 0.08))
|
||
n = max(2, int(12 * reach) + 1)
|
||
pts = [(cx - r * math.cos(a), -r * math.sin(a)) for a in [m * math.pi * reach / (n - 1) for m in range(n)]]
|
||
s.append(L(pts, 0.14))
|
||
if i >= 9:
|
||
for m in range(3):
|
||
s.append(C(cx + 1.6 - m * 0.3 + R.uniform(-0.1, 0.1), -0.1, 0.12))
|
||
return s
|
||
|
||
|
||
def tornado(i, t):
|
||
"""A little twister spins up out of the box and wanders off to the right."""
|
||
s = []
|
||
base = t * 2.0
|
||
h = min(1.0, (i + 1) / 4)
|
||
for k in range(6):
|
||
y = -k * 0.55 * h
|
||
w = 0.25 + k * 0.22
|
||
x = base + math.sin(i * 1.3 + k * 0.7) * 0.25 * k / 5
|
||
pts = [(x + w * math.cos(a), y + 0.18 * math.sin(a)) for a in [m * math.pi / 5 + i * 0.6 for m in range(11)]]
|
||
s.append(L(pts, 0.07))
|
||
for m in range(3):
|
||
a = i * 0.9 + m * 2.1
|
||
s.append(P(rotate([(base + 1.2 * math.cos(a) - 0.1, -1.6 + 0.4 * math.sin(a)), (base + 1.2 * math.cos(a) + 0.12, -1.6 + 0.4 * math.sin(a)),
|
||
(base + 1.2 * math.cos(a), -1.45 + 0.4 * math.sin(a))], a)))
|
||
return s
|
||
|
||
|
||
def bee(i, t):
|
||
"""A bee buzzes out of the box in a figure of eight, leaving a dotted trail."""
|
||
def pos(u):
|
||
a = u * 2 * math.pi
|
||
return (2.0 * math.sin(a), -1.8 - 0.7 * math.sin(2 * a) - u * 1.4)
|
||
x, y = pos(t)
|
||
z = 1.7
|
||
s = [P(ring(x, y, 0.32 * z, 12, 0, 0.02), 0.1)]
|
||
for d in (-0.12, 0.12):
|
||
s.append(L([(x + d * z, y - 0.28 * z), (x + d * z, y + 0.28 * z)], 0.1))
|
||
s.append(P([(x + 0.3 * z, y - 0.07), (x + 0.55 * z, y), (x + 0.3 * z, y + 0.07)]))
|
||
up = i % 2 == 0
|
||
for d in (-0.15, 0.12):
|
||
s.append(P(ring(x + d * z, y - (0.5 if up else 0.36) * z, (0.2 if up else 0.15) * z, 8, 0, 0.02), 0.07))
|
||
for k in range(1, 8):
|
||
u = t - k * 0.05
|
||
if u > 0:
|
||
px, py = pos(u)
|
||
s.append(C(px, py, 0.06))
|
||
return s
|
||
|
||
|
||
def bat(i, t):
|
||
"""A bat flaps out of the box in jerky swoops."""
|
||
x = math.sin(i * 2.1) * 0.8 + t * 0.8
|
||
y = -0.6 - t * 3.8 + (0.3 if i % 2 else 0)
|
||
up = i % 2 == 0
|
||
wy = -0.55 if up else 0.35
|
||
s = []
|
||
for side in (-1, 1):
|
||
s.append(P([(x, y), (x + side * 0.6, y + wy * 0.6), (x + side * 1.3, y + wy), (x + side * 1.1, y + wy + 0.3),
|
||
(x + side * 0.8, y + wy * 0.3 + 0.25), (x + side * 0.5, y + 0.35), (x + side * 0.2, y + 0.2)]))
|
||
s.append(P(ring(x, y, 0.22, 8, 0, 0.02)))
|
||
s.append(P([(x - 0.18, y - 0.1), (x - 0.12, y - 0.4), (x - 0.02, y - 0.15)]))
|
||
s.append(P([(x + 0.18, y - 0.1), (x + 0.12, y - 0.4), (x + 0.02, y - 0.15)]))
|
||
return s
|
||
|
||
|
||
def chick(i, t):
|
||
"""An egg pops out of the box, wobbles, cracks, and a chick peeks out."""
|
||
y = -1.2
|
||
tilt = [0, 0, 0.15, -0.15, 0.2, -0.2, 0, 0, 0, 0, 0, 0][i]
|
||
egg = [(0.6 * math.cos(a), y + (0.75 if math.sin(a) < 0 else 0.6) * math.sin(a)) for a in [k * math.pi / 8 for k in range(16)]]
|
||
s = []
|
||
if i < 6:
|
||
e = rotate(egg, tilt, 0, y + 0.6)
|
||
s.append(P(e, 0.1))
|
||
if i >= 4:
|
||
s.append(L([(-0.6, y), (-0.3, y - 0.2), (0, y + 0.05), (0.3, y - 0.2), (0.6, y)], 0.07))
|
||
return s
|
||
bottom = [p for p in egg if p[1] >= y - 0.01]
|
||
s.append(L([(-0.6, y)] + sorted(bottom, key=lambda p: -p[0])[::-1] + [(0.6, y)], 0.1))
|
||
s.append(L([(-0.6, y), (-0.3, y - 0.2), (0, y + 0.05), (0.3, y - 0.2), (0.6, y)], 0.07))
|
||
k = i - 6
|
||
hy = y - 0.3 - min(1.0, k / 2) * 0.5
|
||
s.append(P(ring(0, hy, 0.45, 10, 0, 0.03)))
|
||
s.append(P([(0.4, hy - 0.05), (0.75, hy + 0.05), (0.4, hy + 0.15)]))
|
||
s.append(P([(-0.1, hy - 0.45), (0, hy - 0.75), (0.1, hy - 0.45)]))
|
||
lid_y = y - 0.6 - k * 0.55
|
||
s.append(P(rotate([(-0.6, y - 0.2), (-0.3, y - 0.4), (0, y - 0.15), (0.3, y - 0.4), (0.6, y - 0.2), (0, y - 0.9)],
|
||
k * 0.5, 0, y - 0.4), 0.08) if k == 0 else P(rotate([(-0.5, lid_y), (0.5, lid_y), (0, lid_y - 0.6)], k * 0.6, 0, lid_y), 0.08))
|
||
if k >= 3:
|
||
s.append(L([(-0.9, hy - 0.2), (-1.2, hy - 0.4)], 0.05))
|
||
s.append(L([(0.9, hy - 0.5), (1.2, hy - 0.7)], 0.05))
|
||
return s
|
||
|
||
|
||
# ── set 0, second batch (added 2026-11-06: the first ticks of the day get the most variety) ──
|
||
|
||
def popcorn(i, t):
|
||
"""Kernels pop out of the box one after another, puff up and tumble down."""
|
||
s = []
|
||
rng = random.Random(201)
|
||
for k in range(7):
|
||
t0 = k * 0.09
|
||
u = t - t0
|
||
if u <= 0:
|
||
continue
|
||
vx, vy = rng.uniform(-2.2, 2.6), rng.uniform(-6.0, -4.0)
|
||
x, y = vx * u, vy * u + 9.0 * u * u
|
||
y = min(y, 0.2)
|
||
r = 0.18 if u < 0.06 else 0.34
|
||
puffs = [(x + 0.14 * math.cos(a), y + 0.14 * math.sin(a)) for a in (0.3, 2.4, 4.4)]
|
||
for px, py in puffs:
|
||
s.append(C(px, py, r * 0.7))
|
||
if i < 3:
|
||
s.append(P(star(0, -0.2, 0.5, 0.2, 6, i)))
|
||
return s
|
||
|
||
|
||
def yoyo(i, t):
|
||
"""A yo-yo is flung up out of the box on its string, spins at the top, and zips back down."""
|
||
reach = [0.5, 1.6, 2.8, 3.6, 3.8, 3.8, 3.7, 3.0, 1.8, 0.8, 0.4, 0.5][i]
|
||
x, y = 0.6, -reach
|
||
s = [L([(0, 0), (x, y + 0.45)], 0.05)]
|
||
s.append(P(ring(x, y, 0.45, 12, 0, 0.02)))
|
||
a = i * 0.9
|
||
s.append(L([(x - 0.3 * math.cos(a), y - 0.3 * math.sin(a)), (x + 0.3 * math.cos(a), y + 0.3 * math.sin(a))], 0.07))
|
||
if i in (4, 5, 6):
|
||
s.append(L([(x + 0.7, y - 0.3), (x + 1.0, y - 0.5)], 0.06))
|
||
s.append(L([(x - 0.7, y + 0.3), (x - 1.0, y + 0.5)], 0.06))
|
||
return s
|
||
|
||
|
||
def jellyfish(i, t):
|
||
"""A jellyfish pulses its way up out of the box, bell squeezing, tentacles trailing."""
|
||
y = -0.8 - t * 3.6
|
||
squeeze = i % 3 == 1
|
||
w, h = (0.55, 0.85) if squeeze else (0.85, 0.6)
|
||
bell = [(w * math.cos(a), y - h * math.sin(a)) for a in [k * math.pi / 10 for k in range(11)]]
|
||
s = [P(bell + [(-w, y + 0.1), (w, y + 0.1)][::-1][1:])]
|
||
for k in range(4):
|
||
tx = -w * 0.7 + k * w * 0.47
|
||
pts = [(tx, y + 0.1)]
|
||
for m in range(1, 5):
|
||
pts.append((tx + math.sin(i * 1.3 + m + k) * 0.15, y + 0.1 + m * (0.35 if squeeze else 0.25)))
|
||
s.append(L(pts, 0.06))
|
||
return s
|
||
|
||
|
||
def comet(i, t):
|
||
"""A comet bursts out of the box and streaks across, its tail breaking into dust."""
|
||
x, y = -0.2 + t * 5.0, -0.6 - t * 3.4 + t * t * 1.4
|
||
s = [P(star(x, y, 0.45, 0.22, 6, i * 0.5))]
|
||
ang = math.atan2(-3.4 + 2.8 * t, 5.0)
|
||
for k in range(1, 5):
|
||
d = k * 0.45
|
||
bx, by = x - d * math.cos(ang), y - d * math.sin(ang)
|
||
s.append(L([(bx, by - 0.25 + k * 0.04), (bx - 0.5 * math.cos(ang), by - 0.5 * math.sin(ang))], 0.12 - k * 0.02))
|
||
s.append(L([(bx, by + 0.25 - k * 0.04), (bx - 0.5 * math.cos(ang), by - 0.5 * math.sin(ang))], 0.12 - k * 0.02))
|
||
for k in range(3):
|
||
u = t - 0.2 - k * 0.15
|
||
if u > 0:
|
||
s.append(C(-0.2 + u * 5.0 + R.uniform(-0.2, 0.2), -0.6 - u * 3.4 + u * u * 1.4 + 0.3, 0.06))
|
||
return s
|
||
|
||
|
||
def flag(i, t):
|
||
"""A flagpole shoots up out of the box and its flag ripples out in the wind."""
|
||
top = -min(1.0, (i + 1) / 4) * 3.4
|
||
s = [L([(0, 0.2), (0, top)], 0.1), C(0, top - 0.1, 0.12)]
|
||
if i >= 3:
|
||
out = min(1.0, (i - 2) / 3) * 1.8
|
||
pts_t, pts_b = [], []
|
||
for k in range(7):
|
||
f = k / 6
|
||
wv = math.sin(f * 4 + i * 1.4) * 0.15 * f
|
||
pts_t.append((f * out, top + 0.05 + wv))
|
||
pts_b.append((f * out, top + 1.05 + wv))
|
||
s.append(P(pts_t + pts_b[::-1]))
|
||
return s
|
||
|
||
|
||
def exclaim(i, t):
|
||
"""A big exclamation mark springs up out of the box and wobbles, delighted."""
|
||
h = [0.3, 1.2, 2.4, 3.0, 2.6, 2.9, 2.7, 2.8, 2.8, 2.8, 2.8, 2.8][i]
|
||
lean = math.sin(i * 1.6) * 0.25 * (1 - t)
|
||
top = (-h - 1.4, -h)
|
||
bar = rotate([(-0.3, top[0]), (0.3, top[0]), (0.18, top[1] - 0.45), (-0.18, top[1] - 0.45)], lean, 0, 0)
|
||
s = [P(bar)]
|
||
dx, dy = rotate([(0, -h + 0.05)], lean, 0, 0)[0]
|
||
s.append(C(dx, dy, 0.24))
|
||
if i >= 3 and i % 2:
|
||
for side in (-1, 1):
|
||
s.append(L([(side * 0.6, -h - 1.2), (side * 1.0, -h - 1.5)], 0.07))
|
||
return s
|
||
|
||
|
||
def robot(i, t):
|
||
"""A boxy robot head rises out of the box, antenna blinking, eyes looking about."""
|
||
y = -min(1.0, (i + 1) / 4) * 2.0
|
||
s = [P([(-0.7, y - 0.6), (0.7, y - 0.6), (0.7, y + 0.6), (-0.7, y + 0.6)], 0.11)]
|
||
s.append(L([(0, y - 0.6), (0, y - 1.1)], 0.07))
|
||
if i % 2 == 0:
|
||
s.append(C(0, y - 1.2, 0.15))
|
||
s.append(P(star(0, y - 1.2, 0.4, 0.12, 4, 0), 0.05))
|
||
else:
|
||
s.append(C(0, y - 1.2, 0.12, 0.06))
|
||
look = [0, 0, 0, 0, 0.15, 0.15, -0.15, -0.15, 0, 0, 0, 0][i]
|
||
for ex in (-0.3, 0.3):
|
||
s.append(P([(ex + look - 0.12, y - 0.25), (ex + look + 0.12, y - 0.25), (ex + look + 0.12, y), (ex + look - 0.12, y)]))
|
||
s.append(L([(-0.35, y + 0.3), (-0.12, y + 0.38), (0.12, y + 0.3), (0.35, y + 0.38)], 0.06))
|
||
s.append(L([(-0.7, y), (-0.95, y)], 0.08))
|
||
s.append(L([(0.7, y), (0.95, y)], 0.08))
|
||
return s
|
||
|
||
|
||
def helicopter(i, t):
|
||
"""A little helicopter lifts out of the box, rotor chopping, and buzzes away."""
|
||
x, y = t * 2.2, -0.5 - t * 3.4 + math.sin(i * 1.7) * 0.1
|
||
s = [P(ring(x, y, 0.45, 10, 0, 0.02))]
|
||
s.append(L([(x - 0.4, y), (x - 1.4, y - 0.15)], 0.12))
|
||
s.append(L([(x - 1.4, y - 0.4), (x - 1.4, y + 0.1)], 0.07))
|
||
s.append(L([(x, y - 0.45), (x, y - 0.65)], 0.07))
|
||
span = [1.2, 0.3, 1.1, 0.25, 1.2, 0.3][i % 6]
|
||
s.append(L([(x - span, y - 0.7), (x + span, y - 0.7)], 0.09))
|
||
s.append(L([(x - 0.4, y + 0.6), (x + 0.4, y + 0.6)], 0.07))
|
||
s.append(L([(x - 0.2, y + 0.4), (x - 0.2, y + 0.6)], 0.05))
|
||
s.append(L([(x + 0.2, y + 0.4), (x + 0.2, y + 0.6)], 0.05))
|
||
return s
|
||
|
||
|
||
def sailboat(i, t):
|
||
"""A sailboat bobs out of the box onto the waves and sails off to the right."""
|
||
x = t * 3.4
|
||
bob = 0.12 if i % 2 else -0.05
|
||
y = -0.4 + bob
|
||
s = [P([(x - 0.8, y), (x + 0.8, y), (x + 0.5, y + 0.4), (x - 0.5, y + 0.4)])]
|
||
s.append(L([(x, y), (x, y - 1.6)], 0.07))
|
||
puff = 0.1 * (i % 3)
|
||
s.append(P([(x + 0.08, y - 1.55), (x + 0.9 + puff, y - 0.15), (x + 0.08, y - 0.15)]))
|
||
s.append(P([(x - 0.08, y - 1.2), (x - 0.08, y - 0.15), (x - 0.6, y - 0.15)]))
|
||
wave = []
|
||
for k in range(13):
|
||
wx = -0.8 + k * 0.45
|
||
wave.append((wx, 0.15 + math.sin(k * 1.3 + i * 0.9) * 0.1))
|
||
s.append(L(wave, 0.07))
|
||
return s
|
||
|
||
|
||
def lollipop(i, t):
|
||
"""A lollipop pops up out of the box and its swirl spins round in clicks."""
|
||
top = -min(1.0, (i + 1) / 3) * 2.2
|
||
s = [L([(0, 0.3), (0, top + 0.7)], 0.12), P(ring(0, top, 0.75, 14, 0, 0.02), 0.1)]
|
||
pts = []
|
||
rot = i * math.pi / 3
|
||
for k in range(22):
|
||
a = k * 0.55 + rot
|
||
r = 0.06 + k * 0.03
|
||
pts.append((r * math.cos(a), top + r * math.sin(a)))
|
||
s.append(L(pts, 0.1, 0.02))
|
||
if i >= 6 and i % 2 == 0:
|
||
s.append(P(star(0.9, top - 0.8, 0.3, 0.09, 4, 0)))
|
||
return s
|
||
|
||
|
||
def cupcake(i, t):
|
||
"""A cupcake rises out of the box, a candle on top flickers, and puffs out."""
|
||
y = -min(1.0, (i + 1) / 4) * 1.4
|
||
s = [P([(-0.65, y - 0.1), (0.65, y - 0.1), (0.45, y + 0.6), (-0.45, y + 0.6)], 0.1)]
|
||
for k in range(4):
|
||
x = -0.45 + k * 0.3
|
||
s.append(L([(x, y - 0.05), (x + 0.05, y + 0.55)], 0.05))
|
||
s.append(P([(-0.75, y - 0.1), (-0.6, y - 0.55), (-0.2, y - 0.75), (0.25, y - 0.75), (0.6, y - 0.55), (0.75, y - 0.1)]))
|
||
s.append(L([(0, y - 0.75), (0, y - 1.25)], 0.1))
|
||
if i < 9:
|
||
fl = 0.3 + R.uniform(0, 0.2)
|
||
s.append(P([(-0.12, y - 1.3), (0, y - 1.3 - fl - 0.2), (0.12, y - 1.3)]))
|
||
else:
|
||
k = i - 8
|
||
s.append(P(ring(0.1 * k, y - 1.5 - k * 0.35, 0.12 + k * 0.08, 7, 0, 0.04), 0.05))
|
||
return s
|
||
|
||
|
||
def planet(i, t):
|
||
"""A ringed planet rises out of the box while a little moon whips round it."""
|
||
y = -0.4 - min(1.0, (i + 1) / 4) * 2.0
|
||
s = [P(ring(0, y, 0.65, 14, 0, 0.02))]
|
||
s.append(P([(1.3 * math.cos(a), y + 0.32 * math.sin(a) - 0.1 * math.cos(a)) for a in [k * math.pi / 8 for k in range(17)]], 0.08))
|
||
a = i * math.pi / 3
|
||
mx, my = 1.6 * math.cos(a), y + 0.8 * math.sin(a)
|
||
s.append(C(mx, my, 0.17))
|
||
return s
|
||
|
||
|
||
def hammer(i, t):
|
||
"""A toy hammer swings down on the box three times: bonk, bonk, BONK, with stars."""
|
||
lift = [1.1, 0.5, 0.0, 0.9, 0.4, 0.0, 1.2, 0.5, -0.05, -0.05, 0.0, 0.0][i]
|
||
px, py = 1.9, -0.75 # the hand: the handle pivots here
|
||
local = [(0, 0), (-1.75, 0)] # handle, pivot -> head
|
||
head = [(-2.2, -0.35), (-1.5, -0.35), (-1.5, 0.35), (-2.2, 0.35)]
|
||
rot = lambda pts: [(px + x, py + y) for x, y in rotate(pts, lift, 0, 0)]
|
||
s = [L(rot(local), 0.14), P(rot(head))]
|
||
if i in (2, 5, 8, 9):
|
||
n = 2 if i < 8 else 4
|
||
for k in range(n):
|
||
a = -math.pi / 2 + (k - (n - 1) / 2) * 0.8
|
||
s.append(P(star(1.2 * math.cos(a) - 0.1, -0.5 + 1.2 * math.sin(a), 0.3, 0.11, 5, i)))
|
||
return s
|
||
|
||
|
||
def boxingglove(i, t):
|
||
"""A boxing glove on a zigzag spring punches out of the box: POW."""
|
||
ext = [0.3, 1.2, 2.4, 3.0, 2.8, 2.9, 2.85, 2.6, 1.8, 1.0, 0.6, 0.6][i]
|
||
a = -0.55
|
||
pts = []
|
||
for k in range(9):
|
||
f = k / 8
|
||
off = (0.2 if k % 2 else -0.2)
|
||
pts.append((f * ext * math.cos(a) - off * math.sin(a), f * ext * math.sin(a) + off * math.cos(a)))
|
||
s = [L(pts, 0.07)]
|
||
gx, gy = ext * math.cos(a), ext * math.sin(a)
|
||
s.append(P(ring(gx + 0.25, gy - 0.1, 0.5, 12, 0, 0.03)))
|
||
s.append(P(ring(gx + 0.05, gy - 0.55, 0.22, 8, 0, 0.02)))
|
||
if i in (3, 4, 5):
|
||
s.append(P(star(gx + 1.2, gy - 0.4, 0.8, 0.35, 8, i), 0.08))
|
||
return s
|
||
|
||
|
||
def turtle(i, t):
|
||
"""A turtle pokes its head and feet out of its shell and plods out of the box."""
|
||
x = t * 1.8
|
||
s = [P([(x - 0.8, 0), (x - 0.6, -0.55), (x, -0.8), (x + 0.6, -0.55), (x + 0.8, 0)])]
|
||
s.append(L([(x - 0.35, -0.6), (x, -0.25), (x + 0.35, -0.6)], 0.05))
|
||
out = min(1.0, (i + 1) / 3)
|
||
s.append(C(x + 0.8 + 0.35 * out, -0.3, 0.22 * out + 0.05))
|
||
step = 0.12 if i % 2 else -0.12
|
||
for fx, d in ((-0.45, step), (0.45, -step)):
|
||
s.append(L([(x + fx, 0), (x + fx + d, 0.25 * out)], 0.12))
|
||
s.append(P([(x - 0.8, -0.1), (x - 1.05, 0.0), (x - 0.8, 0.05)]))
|
||
return s
|
||
|
||
|
||
def owl(i, t):
|
||
"""An owl pops up out of the box, blinks its big eyes, and swivels its head."""
|
||
y = -min(1.0, (i + 1) / 4) * 1.6
|
||
s = [P(ring(0, y, 0.75, 14, 0, 0.03), 0.1)]
|
||
s.append(P([(-0.65, y - 0.4), (-0.55, y - 1.0), (-0.25, y - 0.65)]))
|
||
s.append(P([(0.65, y - 0.4), (0.55, y - 1.0), (0.25, y - 0.65)]))
|
||
turn = [0, 0, 0, 0, 0.18, 0.18, 0.18, 0, -0.18, -0.18, 0, 0][i]
|
||
for ex in (-0.3, 0.3):
|
||
s.append(P(ring(ex + turn, y - 0.15, 0.26, 10, 0, 0.01), 0.07))
|
||
if i in (6, 7):
|
||
s.append(L([(ex + turn - 0.2, y - 0.15), (ex + turn + 0.2, y - 0.15)], 0.07))
|
||
else:
|
||
s.append(C(ex + turn * 1.4, y - 0.15, 0.1))
|
||
s.append(P([(turn - 0.1, y + 0.12), (turn + 0.1, y + 0.12), (turn, y + 0.35)]))
|
||
return s
|
||
|
||
|
||
def icecream(i, t):
|
||
"""An ice-cream cone pops out of the box and scoops drop onto it, plop plop plop."""
|
||
s = [P([(-0.45, -0.9), (0.45, -0.9), (0, 0.3)], 0.09)]
|
||
s.append(L([(-0.3, -0.6), (0.15, -0.1)], 0.05))
|
||
s.append(L([(0.3, -0.6), (-0.15, -0.1)], 0.05))
|
||
for k, start in enumerate((0, 3, 6)):
|
||
land = -1.25 - k * 0.6
|
||
if i < start:
|
||
continue
|
||
u = min(1.0, (i - start + 1) / 3)
|
||
y = -5.5 + (5.5 + land) * u
|
||
sq = 0.75 if u == 1.0 and i - start == 2 else 1.0
|
||
s.append(P([(0.5 / sq ** 0.5 * math.cos(a), y + 0.42 * sq * math.sin(a)) for a in [m * math.pi / 7 for m in range(14)]]))
|
||
if i >= 9:
|
||
s.append(C(0.05, -2.95 - (i - 9) * 0.05, 0.13))
|
||
return s
|
||
|
||
|
||
def sparkler(i, t):
|
||
"""A sparkler pops up out of the box, fizzing, and writes a loop in the air."""
|
||
a = t * 2 * math.pi
|
||
tx, ty = 0.9 * math.sin(a), -2.0 - 0.9 * math.cos(a) + 0.9
|
||
s = [L([(0, 0.2), (tx, ty)], 0.11)]
|
||
trail = []
|
||
for k in range(int(t * 16) + 1):
|
||
b = k / 16 * 2 * math.pi
|
||
trail.append((0.9 * math.sin(b), -2.0 - 0.9 * math.cos(b) + 0.9))
|
||
if len(trail) > 1:
|
||
s.append(L(trail[-8:], 0.09))
|
||
for k in range(7):
|
||
ang = R.uniform(0, 2 * math.pi)
|
||
r = R.uniform(0.25, 0.7)
|
||
s.append(L([(tx + 0.12 * math.cos(ang), ty + 0.12 * math.sin(ang)), (tx + r * math.cos(ang), ty + r * math.sin(ang))], 0.07))
|
||
s.append(P(star(tx, ty, 0.35, 0.13, 6, i)))
|
||
return s
|
||
|
||
|
||
def spider(i, t):
|
||
"""A spider drops from above on its thread, bounces on the box, and climbs back up."""
|
||
y = [-5.0, -3.4, -1.8, -0.55, -1.0, -0.6, -0.85, -0.65, -1.4, -2.6, -3.8, -5.0][i]
|
||
s = [L([(0, -6.5), (0, y - 0.35)], 0.04), P(ring(0, y, 0.35, 10, 0, 0.02))]
|
||
wig = 0.12 if i % 2 else -0.12
|
||
for side in (-1, 1):
|
||
for k in range(4):
|
||
ly = y - 0.2 + k * 0.15
|
||
s.append(L([(side * 0.3, ly), (side * 0.65, ly - 0.25 + wig * side), (side * 0.85, ly + 0.15)], 0.05))
|
||
s.append(C(-0.12, y - 0.05, 0.05))
|
||
s.append(C(0.12, y - 0.05, 0.05))
|
||
return s
|
||
|
||
|
||
def parachute(i, t):
|
||
"""A parachute pops open high above and floats a little crate gently down onto the box."""
|
||
y = -5.0 + t * 4.2
|
||
sway = math.sin(i * 0.9) * 0.4
|
||
x = sway
|
||
o = min(1.0, (i + 1) / 3)
|
||
W = 1.3 * o
|
||
canopy = [(x + W * math.cos(a), y - 1.5 - 0.8 * o * math.sin(a)) for a in [k * math.pi / 10 for k in range(11)]]
|
||
s = [P(canopy)]
|
||
for k in (-1, -0.33, 0.33, 1):
|
||
s.append(L([(x + k * W, y - 1.5), (x + k * 0.2, y - 0.25)], 0.04))
|
||
s.append(P([(x - 0.3, y - 0.3), (x + 0.3, y - 0.3), (x + 0.3, y + 0.25), (x - 0.3, y + 0.25)], 0.07))
|
||
return s
|
||
|
||
|
||
SET0_MORE = [
|
||
(popcorn, "yellow", "popple"), (yoyo, "red", "zipzip"),
|
||
(jellyfish, "blue", "wubwub"), (comet, "yellow", "streak"),
|
||
(flag, "red", "flap"), (exclaim, "red", "ding"),
|
||
(robot, "blue", "beepboop"), (helicopter, "blue", "chop"),
|
||
(sailboat, "blue", "lapping"), (lollipop, "red", "twirl"),
|
||
(cupcake, "red", "toot"), (planet, "yellow", "orbit"),
|
||
(hammer, "yellow", "bonk"), (boxingglove, "red", "punch"),
|
||
(turtle, "blue", "plod"), (owl, "yellow", "hoot"),
|
||
(icecream, "red", "plop"), (sparkler, "yellow", "crackle"),
|
||
(spider, "blue", "dangle"), (parachute, "blue", "floaty"),
|
||
]
|
||
|
||
|
||
# ── the calm set (added 2026-11-07): 2 s each, slow, small and quiet, for tasks marked
|
||
# "calm animation" (early mornings, late nights). They never play for other tasks. ──
|
||
|
||
|
||
def fog(i, t):
|
||
"""Banks of fog drift slowly across the box in soft layers, then thin away."""
|
||
g = inout(t)
|
||
s = []
|
||
for k, (y, sp) in enumerate(((-0.5, 1.0), (-1.3, 0.6), (-2.1, 1.3))):
|
||
x = -2.4 + k * 0.4 + t * sp * 1.6
|
||
s.append(cl(wavy(x, x + 3.4, y, 0.12, i * 0.2 + k, 8), 0.04 + 0.24 * g))
|
||
return s
|
||
|
||
|
||
def canoe(i, t):
|
||
"""A canoe glides out across still water, the paddle dipping in slow strokes."""
|
||
x, y = t * 3.4, -0.4 + 0.04 * math.sin(i * 0.5)
|
||
s = [cp([(x - 1.3, y - 0.25), (x - 0.9, y + 0.05), (x, y + 0.2), (x + 0.9, y + 0.05), (x + 1.3, y - 0.25)])]
|
||
s.append(cc(x - 0.15, y - 0.75, 0.17))
|
||
s.append(cl([(x - 0.15, y - 0.6), (x - 0.12, y - 0.2)], 0.18))
|
||
a = math.sin(i * math.pi / 6) * 0.7
|
||
top = (x + 0.1 + 0.5 * math.sin(a), y - 0.9)
|
||
bot = (x + 0.2 - 0.6 * math.sin(a), y + 0.55)
|
||
s.append(cl([top, bot], 0.07))
|
||
s.append(cp(oval(bot[0], bot[1], 0.1, 0.22, 8)))
|
||
s.append(cl(wavy(x - 2.6, x - 1.4, y + 0.2, 0.04, i * 0.4, 6), 0.05))
|
||
return s
|
||
|
||
|
||
def yarn(i, t):
|
||
"""A ball of yarn rolls lazily out of the box, unwinding a loose thread behind it."""
|
||
r = 0.6 - 0.12 * t
|
||
x, y = ease_out(t) * 3.2, -r
|
||
rot = x / r
|
||
s = [cc(x, y, r, 0.1)]
|
||
for k in range(3):
|
||
a = rot + k * math.pi / 3
|
||
s.append(cl([(x + r * math.cos(a), y + r * math.sin(a)), (x - r * math.cos(a), y - r * math.sin(a))], 0.06))
|
||
s.append(cl([(0, 0.4), (x * 0.3, 0.45 + 0.05 * math.sin(i * 0.3)), (x * 0.65, 0.38), (x, 0.0)], 0.05))
|
||
return s
|
||
|
||
|
||
def candle(i, t):
|
||
"""A candle rises out of the box and its flame sways, slow and steady."""
|
||
h = 1.6 * min(1.0, t * 3)
|
||
top = 0.2 - h
|
||
s = [cp([(-0.3, 0.2), (0.3, 0.2), (0.3, top), (-0.3, top)])]
|
||
if t > 0.3:
|
||
g = min(1.0, (t - 0.3) * 4)
|
||
sw = 0.12 * math.sin(i * 0.5)
|
||
s.append(cl([(0, top), (0, top - 0.15)], 0.05))
|
||
s.append(cp([(sw * 1.6, top - 0.15 - 0.9 * g), (0.2 * g, top - 0.45), (0.12 * g, top - 0.22), (0, top - 0.15),
|
||
(-0.12 * g, top - 0.22), (-0.2 * g, top - 0.45)]))
|
||
return s
|
||
|
||
|
||
def grass(i, t):
|
||
"""Tufts of grass grow up around the box and lean, all together, in a soft wind."""
|
||
g = min(1.0, t * 2.5)
|
||
s = []
|
||
for k in range(9):
|
||
bx = -2 + k * 0.5
|
||
h = (1.0 + 0.3 * ((k * 7) % 3)) * g
|
||
w = 0.35 * math.sin(i * 0.3 + k * 0.4) + 0.25
|
||
s.append(cl([(bx, 0.5), (bx + w * 0.3, 0.5 - h * 0.5), (bx + w, 0.5 - h)], 0.1))
|
||
return s
|
||
|
||
|
||
def stream(i, t):
|
||
"""A little stream flows past the box, its ripples sliding steadily along."""
|
||
g = inout(t)
|
||
s = []
|
||
for k, y in enumerate((-0.5, -0.9, -1.3)):
|
||
s.append(cl(wavy(-2.8 + k * 0.3, 2.8 - k * 0.2, y, 0.08, -i * 0.5 + k * 1.3, 12, 4), 0.03 + 0.08 * g))
|
||
px = -2.4 + t * 5.0
|
||
s.append(cc(px, -0.9 + 0.05 * math.sin(i), 0.08))
|
||
return s
|
||
|
||
|
||
def catnap(i, t):
|
||
"""A cat settles down beside the box, curls its tail round, and dozes off."""
|
||
u = min(1.0, t * 2)
|
||
breath = 0.03 * math.sin(i * 0.5) if t > 0.5 else 0
|
||
s = [cp(oval(0.3, -0.45, 1.0, 0.42 + breath, 16))]
|
||
hx, hy = 1.05 - 0.15 * u, -1.35 + 0.65 * u
|
||
s.append(cp(ring(hx, hy, 0.36, 10, 0, 0.02)))
|
||
s.append(cp([(hx - 0.3, hy - 0.15), (hx - 0.22, hy - 0.55), (hx - 0.05, hy - 0.3)]))
|
||
s.append(cp([(hx + 0.05, hy - 0.3), (hx + 0.22, hy - 0.55), (hx + 0.3, hy - 0.15)]))
|
||
wrap = u * math.pi * 0.9
|
||
s.append(cl([(-0.65 + 0.4 * math.sin(a), -0.35 + 0.25 * (1 - math.cos(a))) for a in
|
||
[wrap * m / 6 for m in range(7)]], 0.14))
|
||
if t > 0.6:
|
||
for k in range(int((t - 0.6) * 10) + 1):
|
||
zx, zy, z = 1.4 + k * 0.3, -1.4 - k * 0.45 - (t - 0.6) * 0.5, 0.15 + k * 0.04
|
||
s.append(cl([(zx, zy), (zx + z, zy), (zx, zy + z), (zx + z, zy + z)], 0.05))
|
||
return s
|
||
|
||
|
||
def squirrel(i, t):
|
||
"""A squirrel scampers along a branch above the box, sits up, and nibbles an acorn."""
|
||
s = [cl([(-2.6, -2.0), (2.4, -2.1)], 0.18), cl([(1.0, -2.08), (1.6, -2.6)], 0.08)]
|
||
x = -1.8 + 2.2 * ease_out(min(1.0, t / 0.4))
|
||
sit = min(1.0, max(0.0, (t - 0.4) * 4))
|
||
by = -2.45 - 0.15 * sit
|
||
s.append(cp(oval(x, by, 0.38 - 0.08 * sit, 0.26 + 0.1 * sit, 12)))
|
||
hx, hy = x + 0.35, by - 0.3 - 0.15 * sit
|
||
s.append(cp(ring(hx, hy, 0.2, 10, 0, 0.01)))
|
||
s.append(cp([(hx - 0.05, hy - 0.15), (hx + 0.02, hy - 0.38), (hx + 0.12, hy - 0.15)]))
|
||
flick = 0.15 * math.sin(i * 0.35)
|
||
s.append(cp([(x - 0.3, by + 0.1), (x - 0.75, by - 0.2), (x - 0.85 + flick, by - 0.8), (x - 0.5 + flick, by - 1.05),
|
||
(x - 0.35, by - 0.75), (x - 0.5, by - 0.3)]))
|
||
if sit > 0:
|
||
nib = 0.04 * math.sin(i * 1.6)
|
||
s.append(cc(hx + 0.25, hy + 0.2 + nib, 0.1))
|
||
return s
|
||
|
||
|
||
def dove(i, t):
|
||
"""A bird glides out of the box and away, with only a couple of slow wingbeats."""
|
||
x, y = -0.3 + t * 4.2, -0.9 - t * 2.0 + 0.1 * math.sin(i * 0.4)
|
||
flap = math.sin(i * math.pi / 6) * (1 if i < 12 else 0.2)
|
||
s = [cp(oval(x, y, 0.5, 0.17, 12, -0.15))]
|
||
s.append(cc(x + 0.5, y - 0.12, 0.14))
|
||
s.append(cp([(x + 0.66, y - 0.14), (x + 0.82, y - 0.1), (x + 0.66, y - 0.06)]))
|
||
s.append(cp([(x - 0.45, y), (x - 0.8, y - 0.2), (x - 0.75, y + 0.12)]))
|
||
tip = y - 0.6 * flap - 0.1
|
||
s.append(cp([(x - 0.15, y - 0.05), (x - 0.35, tip), (x + 0.25, y - 0.05)]))
|
||
return s
|
||
|
||
|
||
def cake(i, t):
|
||
"""A freshly baked cake rises out of the box, still warm, with steam drifting off it."""
|
||
u = ease_out(min(1.0, t * 2.5))
|
||
top = 0.3 - 1.4 * u
|
||
s = [cp([(-1.0, 0.3), (1.0, 0.3), (1.0, top + 0.65 * u), (-1.0, top + 0.65 * u)]),
|
||
cp([(-0.8, top + 0.7 * u), (0.8, top + 0.7 * u), (0.8, top), (-0.8, top)])]
|
||
s.append(cl([(-1.3, 0.45), (1.3, 0.45)], 0.08))
|
||
if t > 0.35:
|
||
s += steam(0, top, i, (t - 0.35) / 0.65)
|
||
return s
|
||
|
||
|
||
def pie(i, t):
|
||
"""A pie slides out of the oven onto the box, its lattice golden, steam curling up."""
|
||
x = -2.5 * (1 - ease_out(min(1.0, t * 2.2)))
|
||
s = [cl([(x - 1.0, -0.2), (x - 0.8, 0.25), (x + 0.8, 0.25), (x + 1.0, -0.2)], 0.1)]
|
||
s.append(cl([(x - 1.1, -0.2)] + [(x + 1.1 * math.cos(math.pi - math.pi * m / 8), -0.2 - 0.4 * math.sin(math.pi * m / 8))
|
||
for m in range(1, 8)] + [(x + 1.1, -0.2)], 0.1))
|
||
for k in (-0.5, 0, 0.5):
|
||
s.append(cl([(x + k - 0.15, -0.2), (x + k + 0.15, -0.55)], 0.06))
|
||
if t > 0.45:
|
||
s += steam(x, -0.6, i, (t - 0.45) / 0.55, 2, 1.2)
|
||
return s
|
||
|
||
|
||
def teacup(i, t):
|
||
"""A teacup on its saucer; the teabag's tag sways on its string while the tea steeps."""
|
||
s = [cl([(-1.0, 0.3), (1.0, 0.3)], 0.1),
|
||
cl([(-0.65, -0.65), (-0.55, 0.0), (-0.3, 0.2), (0.3, 0.2), (0.55, 0.0), (0.65, -0.65)], 0.11),
|
||
cl([(-0.65, -0.65), (0.65, -0.65)], 0.06)]
|
||
s.append(cl(ring(0.85, -0.3, 0.2, 8, 0, 0.0)[1:7], 0.08))
|
||
sw = 0.15 * math.sin(i * 0.4)
|
||
s.append(cl([(-0.2, -0.65), (-0.35, -0.95), (-0.75 + sw, -0.6)], 0.035))
|
||
s.append(cp([(-0.85 + sw, -0.6), (-0.65 + sw, -0.6), (-0.65 + sw, -0.35), (-0.85 + sw, -0.35)]))
|
||
s += steam(0.15, -0.75, i, t, 2, 1.0)
|
||
return s
|
||
|
||
|
||
def lantern(i, t):
|
||
"""A paper lantern lowers on its cord and sways gently, glowing."""
|
||
drop = ease_out(min(1.0, t * 2))
|
||
a = 0.22 * math.sin(i * 0.4) * min(1.0, t * 3)
|
||
top = (0, -4.2)
|
||
lx, ly = top[0] + math.sin(a) * (1.5 + drop), top[1] + math.cos(a) * (1.5 + drop)
|
||
s = [cl([top, (lx, ly)], 0.04)]
|
||
s.append(cp(rotate(oval(lx, ly + 0.55, 0.42, 0.55, 12), a, lx, ly)))
|
||
s.append(cl(rotate([(lx - 0.25, ly + 0.05), (lx + 0.25, ly + 0.05)], a, lx, ly), 0.1))
|
||
if t > 0.4:
|
||
g = inout((t - 0.4) / 0.6, 0.3)
|
||
for k in range(6):
|
||
ang = k * math.pi / 3 + 0.3
|
||
r0, r1 = 0.8, 0.8 + 0.3 * g
|
||
cx, cy = lx, ly + 0.55
|
||
s.append(cl([(cx + r0 * math.cos(ang), cy + r0 * math.sin(ang)), (cx + r1 * math.cos(ang), cy + r1 * math.sin(ang))], 0.04))
|
||
return s
|
||
|
||
|
||
def leaf(i, t):
|
||
"""A single leaf drifts down from above, rocking side to side, and settles on the box."""
|
||
u = min(1.0, t * 1.25)
|
||
y = -4.0 + 3.4 * u
|
||
x = 1.0 * math.sin(u * math.pi * 2.5) * (1 - u)
|
||
rot = 0.6 * math.cos(u * math.pi * 2.5) * (1 - u) + 0.3
|
||
pts = [(x - 0.45, y), (x - 0.2, y - 0.2), (x + 0.25, y - 0.16), (x + 0.45, y), (x + 0.25, y + 0.16), (x - 0.2, y + 0.2)]
|
||
return [cp(rotate(pts, rot, x, y)), cl(rotate([(x - 0.6, y + 0.05), (x + 0.4, y)], rot, x, y), 0.04)]
|
||
|
||
|
||
def wateringcan(i, t):
|
||
"""A watering can tips over the box and a sprinkle of drops falls on a little bud."""
|
||
tip = 0.5 * min(1.0, t * 3)
|
||
cx, cy = -1.4, -2.2
|
||
body = rotate([(cx - 0.5, cy - 0.35), (cx + 0.5, cy - 0.35), (cx + 0.5, cy + 0.35), (cx - 0.5, cy + 0.35)], tip, cx, cy)
|
||
s = [cp(body), cl(rotate([(cx + 0.45, cy + 0.15), (cx + 1.2, cy - 0.35)], tip, cx, cy), 0.1)]
|
||
s.append(cl(rotate([(cx - 0.4, cy - 0.35), (cx - 0.1, cy - 0.75), (cx + 0.25, cy - 0.35)], tip, cx, cy), 0.07))
|
||
nx, ny = rotate([(cx + 1.2, cy - 0.35)], tip, cx, cy)[0]
|
||
if t > 0.25:
|
||
for k in range(8):
|
||
ph = ((t - 0.25) * 2.5 + k / 8) % 1.0
|
||
s.append(cc(nx + 0.1 * (k % 3 - 1) + ph * 0.2, ny + ph * (0.5 - ny), 0.04))
|
||
lean = 0.4 * (1 - min(1.0, max(0.0, (t - 0.5) * 3)))
|
||
s.append(cl([(0.4, 0.5), (0.4 + lean * 0.3, 0.0), (0.4 + lean, -0.35 + lean * 0.3)], 0.07))
|
||
s.append(cp(oval(0.4 + lean, -0.45 + lean * 0.3, 0.12, 0.18, 8, lean)))
|
||
return s
|
||
|
||
|
||
def firefly(i, t):
|
||
"""A few fireflies drift about over the box, each glowing and dimming in its own time."""
|
||
s = []
|
||
for k in range(6):
|
||
x = -1.6 + k * 0.65 + 0.4 * math.sin(t * 3 + k * 2.1)
|
||
y = -1.0 - (k % 3) * 0.7 - 0.4 * math.cos(t * 2.4 + k)
|
||
glow = 0.5 + 0.5 * math.sin(i * 0.45 + k * 1.7)
|
||
s.append(cc(x, y, 0.04 + 0.12 * glow * inout(t, 0.15)))
|
||
return s
|
||
|
||
|
||
def dandelion(i, t):
|
||
"""A dandelion clock stands by the box; one by one its seeds float off on the air."""
|
||
s = [cl([(0.3, 0.5), (0.2, -0.6), (0.3, -1.6)], 0.07)]
|
||
hx, hy = 0.3, -1.9
|
||
gone = int(t * 9)
|
||
for k in range(12):
|
||
a = k * math.pi / 6
|
||
if k < gone:
|
||
u = t - k / 9
|
||
sx, sy = hx + 0.3 * math.cos(a) + u * 2.6, hy + 0.3 * math.sin(a) - u * 1.4 + 0.1 * math.sin(u * 8)
|
||
s.append(cc(sx, sy, 0.03))
|
||
s.append(cl([(sx - 0.12, sy - 0.15), (sx, sy), (sx + 0.12, sy - 0.15)], 0.025))
|
||
else:
|
||
s.append(cl([(hx, hy), (hx + 0.32 * math.cos(a), hy + 0.32 * math.sin(a))], 0.03))
|
||
s.append(cc(hx, hy, 0.09))
|
||
return s
|
||
|
||
|
||
def lotus(i, t):
|
||
"""On still water beside the box, a lotus opens its petals, slowly, one ring at a time."""
|
||
s = [cl(wavy(-2.2, 2.2, 0.0, 0.03, i * 0.2, 10), 0.05)]
|
||
for ring_n, (n, ln, start) in enumerate(((5, 1.1, 0.1), (4, 0.8, 0.35))):
|
||
g = ease_out(min(1.0, max(0.0, (t - start) / 0.5)))
|
||
for k in range(n):
|
||
spread = (k - (n - 1) / 2) / ((n - 1) / 2)
|
||
a = -math.pi / 2 + spread * (0.25 + 0.95 * g) * (1.0 if ring_n == 0 else 0.7)
|
||
tx, ty = ln * math.cos(a), -0.05 + ln * math.sin(a)
|
||
nx, ny = -math.sin(a) * 0.22, math.cos(a) * 0.22
|
||
s.append(cp([(0, -0.05), (tx * 0.5 + nx, ty * 0.5 + ny), (tx, ty), (tx * 0.5 - nx, ty * 0.5 - ny)]))
|
||
return s
|
||
|
||
|
||
def hammock(i, t):
|
||
"""A hammock strung between two posts sways, slow as breathing."""
|
||
sw = 0.25 * math.sin(i * 0.35)
|
||
s = [cl([(-2.0, 0.5), (-2.0, -1.8)], 0.12), cl([(2.0, 0.5), (2.0, -1.8)], 0.12)]
|
||
pts = [(-2.0 + 4.0 * m / 10, -1.6 + 0.9 * math.sin(math.pi * m / 10)) for m in range(11)]
|
||
pts = [(x + sw * math.sin(math.pi * m / 10), y) for m, (x, y) in enumerate(pts)]
|
||
s.append(cl(pts, 0.14))
|
||
s.append(cp(oval(sw - 0.1, -0.95, 0.8, 0.2, 12)))
|
||
return s
|
||
|
||
|
||
def windchime(i, t):
|
||
"""A wind chime turns a little in the breeze, its tubes swinging out of step."""
|
||
s = [cl([(0, -4.0), (0, -3.4)], 0.04), cl([(-1.0, -3.4), (1.0, -3.4)], 0.1)]
|
||
for k, (x, ln) in enumerate(((-0.8, 1.3), (-0.3, 1.7), (0.2, 1.5), (0.7, 1.1))):
|
||
a = 0.14 * math.sin(i * 0.38 + k * 1.3) * min(1.0, t * 3)
|
||
s.append(cl([(x, -3.4), (x + math.sin(a) * 0.3, -3.1)], 0.02))
|
||
s.append(cl([(x + math.sin(a) * 0.3, -3.1), (x + math.sin(a) * (0.3 + ln), -3.1 + ln * math.cos(a))], 0.12))
|
||
a = 0.2 * math.sin(i * 0.3)
|
||
s.append(cl([(0, -3.4), (math.sin(a) * 1.6, -3.4 + 1.6 * math.cos(a))], 0.02))
|
||
s.append(cc(math.sin(a) * 1.8, -3.4 + 1.8 * math.cos(a), 0.15))
|
||
return s
|
||
|
||
|
||
def cumulus(i, t):
|
||
"""A puffy cloud drifts slowly over the box, its puffs swelling and settling."""
|
||
x = -1.6 + t * 3.2
|
||
s = []
|
||
for k, (dx, dy, r) in enumerate(((-0.8, 0.1, 0.45), (-0.2, -0.25, 0.65), (0.5, -0.1, 0.55), (1.0, 0.15, 0.4))):
|
||
s.append(cc(x + dx, -2.0 + dy, r + 0.05 * math.sin(i * 0.3 + k)))
|
||
s.append(cp([(x - 1.2, -1.85), (x + 1.35, -1.85), (x + 1.35, -1.65), (x - 1.2, -1.65)]))
|
||
return s
|
||
|
||
|
||
def aurora(i, t):
|
||
"""Curtains of light ripple above the box, folding and unfolding."""
|
||
g = inout(t)
|
||
s = []
|
||
for k in range(13):
|
||
x = -2.4 + k * 0.4
|
||
base = -1.6 - 0.5 * math.sin(k * 0.5 + i * 0.25)
|
||
h = (0.6 + 0.6 * (0.5 + 0.5 * math.sin(k * 0.9 - i * 0.3))) * g
|
||
s.append(cl([(x, base), (x + 0.1 * math.sin(i * 0.2 + k), base - h)], 0.03 + 0.07 * g))
|
||
return s
|
||
|
||
|
||
def tide(i, t):
|
||
"""A wave washes gently up toward the box, lays down a shell, and slides back out."""
|
||
reach = math.sin(t * math.pi)
|
||
y = 1.6 - 1.4 * reach
|
||
s = [cl(wavy(-2.6, 2.6, y, 0.1, i * 0.35, 12, 3), 0.12)]
|
||
for k in range(5):
|
||
s.append(cc(-2.0 + k, y - 0.25 - 0.05 * math.sin(i + k), 0.05))
|
||
if t > 0.45:
|
||
s.append(cp([(1.1, 0.55), (1.25, 0.25), (1.4, 0.55)]))
|
||
s.append(cl([(1.1, 0.55), (1.25, 0.6), (1.4, 0.55)], 0.06))
|
||
return s
|
||
|
||
|
||
def lighthouse(i, t):
|
||
"""A lighthouse stands by the box, its beam sweeping slowly round."""
|
||
s = [cp([(-0.5, 0.5), (0.5, 0.5), (0.3, -1.8), (-0.3, -1.8)]),
|
||
cp([(-0.4, -1.85), (0.4, -1.85), (0.4, -2.0), (-0.4, -2.0)]),
|
||
cl([(-0.25, -2.0), (-0.25, -2.45), (0.25, -2.45), (0.25, -2.0)], 0.06),
|
||
cp([(-0.35, -2.45), (0.35, -2.45), (0, -2.8)])]
|
||
a = t * math.pi * 2 - math.pi / 2
|
||
w = abs(math.cos(a))
|
||
if w > 0.15:
|
||
d = 1 if math.cos(a) > 0 else -1
|
||
ln = 2.6 * w
|
||
s.append(cl([(0, -2.2), (d * ln, -2.2 - 0.35)], 0.05))
|
||
s.append(cl([(0, -2.2), (d * ln, -2.2 + 0.35)], 0.05))
|
||
return s
|
||
|
||
|
||
def moth(i, t):
|
||
"""A small moth loops slowly round a lamp above the box."""
|
||
s = [cl([(0, -0.6), (0, -1.6)], 0.06), cp([(-0.45, -1.6), (0.45, -1.6), (0.25, -2.1), (-0.25, -2.1)])]
|
||
a = t * math.pi * 2.2 + 0.4
|
||
mx, my = 1.2 * math.cos(a), -1.9 + 0.65 * math.sin(a)
|
||
f = 0.6 + 0.4 * math.sin(i * 1.1)
|
||
s.append(cp([(mx, my), (mx - 0.35, my - 0.22 * f), (mx - 0.3, my + 0.12)]))
|
||
s.append(cp([(mx, my), (mx + 0.35, my - 0.22 * f), (mx + 0.3, my + 0.12)]))
|
||
return s
|
||
|
||
|
||
def breath(i, t):
|
||
"""A ring swells slowly out of the box for one breath in, then shrinks back for the breath out."""
|
||
r = 0.5 + 1.3 * math.sin(t * math.pi)
|
||
return [cl(ring(0, -1.2, r, 18, 0, 0.02) + [ring(0, -1.2, r, 18, 0, 0.0)[0]], 0.12),
|
||
cc(0, -1.2, 0.08 + 0.1 * math.sin(t * math.pi))]
|
||
|
||
|
||
def rake(i, t):
|
||
"""Lines are raked, one after another, into a little sand garden beside the box."""
|
||
s = [cl([(-2.0, 0.4), (2.0, 0.4)], 0.05)]
|
||
done = t * 5
|
||
for k in range(5):
|
||
y = -0.1 - k * 0.32
|
||
ln = max(0.0, min(1.0, done - k))
|
||
if ln > 0:
|
||
s.append(cl(wavy(-1.8, -1.8 + 3.6 * ln, y, 0.05, k, 8), 0.05))
|
||
k = min(4, int(done))
|
||
rx = -1.8 + 3.6 * min(1.0, done - k)
|
||
ry = -0.1 - k * 0.32
|
||
s.append(cl([(rx, ry - 0.25), (rx, ry + 0.25)], 0.06))
|
||
s.append(cl([(rx, ry), (rx + 0.9, ry - 1.0)], 0.05))
|
||
return s
|
||
|
||
|
||
def cairn(i, t):
|
||
"""Smooth stones settle one onto another in a little stack on the box."""
|
||
stones = ((0.0, 0.85, 0.3), (0.05, 0.65, 0.25), (-0.05, 0.48, 0.2), (0.03, 0.32, 0.16))
|
||
s = []
|
||
y = 0.4
|
||
for k, (dx, rx, ry) in enumerate(stones):
|
||
start = k * 0.2
|
||
u = min(1.0, max(0.0, (t - start) / 0.2))
|
||
if u <= 0:
|
||
break
|
||
rest = y - ry
|
||
cy = rest - (1 - ease_out(u)) * 1.5
|
||
s.append(cp(oval(dx, cy, rx, ry, 14, 0.05 * (k % 2 * 2 - 1))))
|
||
y = rest - ry
|
||
return s
|
||
|
||
|
||
def fern(i, t):
|
||
"""A fern frond uncurls from a tight spiral beside the box, leaflet by leaflet."""
|
||
u = ease_out(min(1.0, t * 1.4))
|
||
pts, x, y, a = [], 0.0, 0.5, -math.pi / 2
|
||
n = 14
|
||
for m in range(n + 1):
|
||
pts.append((x, y))
|
||
curl = (1 - u) * 1.1 * (m / n) ** 2 + 0.03
|
||
a += curl
|
||
x += 0.22 * math.cos(a)
|
||
y += 0.22 * math.sin(a)
|
||
s = [cl(pts, 0.07)]
|
||
for m in range(2, n, 2):
|
||
if m / n > u - 0.1:
|
||
continue
|
||
(x0, y0), (x1, y1) = pts[m], pts[m + 1]
|
||
d = math.atan2(y1 - y0, x1 - x0)
|
||
ln = 0.45 * (1 - m / n) + 0.1
|
||
for side in (1, -1):
|
||
b = d + side * 1.1
|
||
s.append(cl([(x0, y0), (x0 + ln * math.cos(b), y0 + ln * math.sin(b))], 0.05))
|
||
return s
|
||
|
||
|
||
def sloth(i, t):
|
||
"""A sloth hangs from a branch over the box and, very slowly, turns its head to look."""
|
||
s = [cl([(-2.4, -3.0), (2.4, -3.05)], 0.16)]
|
||
y = -1.9 + 0.05 * math.sin(i * 0.3)
|
||
s.append(cp(oval(0, y, 0.45, 0.75, 14)))
|
||
for dx in (-0.25, 0.25):
|
||
s.append(cl([(dx, y - 0.5), (dx * 1.6, -3.0)], 0.12))
|
||
s.append(cl([(dx * 1.6 - 0.08, -2.92), (dx * 1.6 + 0.1, -3.12)], 0.04))
|
||
turn = 0.25 * math.sin(min(1.0, t * 1.2) * math.pi / 2)
|
||
s.append(cp(ring(0.5 + turn, y - 0.1 + 0.15 * turn, 0.3, 10, 0, 0.01)))
|
||
return s
|
||
|
||
|
||
def koi(i, t):
|
||
"""A koi swims a slow circle round the box, its tail sweeping."""
|
||
a = t * math.pi * 1.8 - math.pi / 2
|
||
x, y = 1.6 * math.cos(a), -0.6 + 0.9 * math.sin(a)
|
||
head = a + math.pi / 2
|
||
body = [(x + 0.5, y), (x + 0.2, y - 0.2), (x - 0.35, y - 0.12), (x - 0.35, y + 0.12), (x + 0.2, y + 0.2)]
|
||
wag = 0.35 * math.sin(i * 0.8)
|
||
tail = [(x - 0.32, y), (x - 0.7, y - 0.22 + wag * 0.3), (x - 0.62, y + 0.22 + wag * 0.3)]
|
||
return [cp(rotate(body, head, x, y)), cp(rotate(tail, head, x, y))]
|
||
|
||
|
||
def constellation(i, t):
|
||
"""Stars wink on one by one above the box and are joined, softly, into a constellation."""
|
||
pts = ((-1.8, -1.8), (-0.9, -2.5), (0.1, -2.2), (0.9, -2.9), (1.8, -2.4), (0.6, -1.4))
|
||
s = []
|
||
on = t * 8
|
||
for k, (x, y) in enumerate(pts):
|
||
if on > k:
|
||
s.append(P(star(x, y, 0.18, 0.08, 4, i * 0.05), 0, CB))
|
||
for k in range(len(pts) - 1):
|
||
u = max(0.0, min(1.0, on - 5.5 - k * 0.4))
|
||
if u > 0 and k < 5:
|
||
(x0, y0), (x1, y1) = pts[k], pts[k + 1]
|
||
s.append(cl([(x0, y0), (x0 + (x1 - x0) * u, y0 + (y1 - y0) * u)], 0.025))
|
||
return s
|
||
|
||
|
||
def honey(i, t):
|
||
"""A honey dipper above the box lets a slow golden thread fall and pool."""
|
||
dy = -2.4
|
||
s = [cl([(-1.6, dy - 0.8), (-0.1, dy)], 0.08)]
|
||
for k in range(4):
|
||
s.append(cp(oval(0.15 * k - 0.05, dy + 0.02 * k, 0.12, 0.28 - 0.02 * k, 8, 0.5)))
|
||
fall = min(1.0, t * 1.6)
|
||
s.append(cl([(0.3, dy + 0.3), (0.3 + 0.03 * math.sin(i * 0.3), dy + 0.3 + (2.6 - 0.3) * fall)], 0.06))
|
||
if fall >= 1:
|
||
p = min(1.0, (t - 0.625) * 2.5)
|
||
s.append(cp(oval(0.3, 0.45, 0.2 + 0.6 * p, 0.06 + 0.1 * p, 12)))
|
||
return s
|
||
|
||
|
||
def quilt(i, t):
|
||
"""Patches are laid down one by one into a little quilt above the box, then stitched."""
|
||
s = []
|
||
n = int(t * 11)
|
||
for k in range(min(9, n)):
|
||
r, c = divmod(k, 3)
|
||
x, y = -0.9 + c * 0.6, -2.4 + r * 0.6
|
||
sq = [(x - 0.27, y - 0.27), (x + 0.27, y - 0.27), (x + 0.27, y + 0.27), (x - 0.27, y + 0.27)]
|
||
s.append(cp(sq) if (r + c) % 2 == 0 else cl(sq + [sq[0]], 0.05))
|
||
if n > 9:
|
||
s.append(cl([(-1.25, -2.75), (0.65, -2.75), (0.65, -0.85), (-1.25, -0.85), (-1.25, -2.75)], 0.03))
|
||
return s
|
||
|
||
|
||
def book(i, t):
|
||
"""A book lies open above the box and a page turns over, slowly."""
|
||
s = [cl([(-1.6, -1.2), (-0.8, -1.35), (0, -1.2), (0.8, -1.35), (1.6, -1.2)], 0.08),
|
||
cl([(-1.6, -1.2), (-1.6, -2.4), (-0.8, -2.55), (0, -2.4), (0, -1.2)], 0.07),
|
||
cl([(0, -2.4), (0.8, -2.55), (1.6, -2.4), (1.6, -1.2)], 0.07)]
|
||
for k in range(3):
|
||
y = -2.15 + k * 0.3
|
||
s.append(cl([(-1.35, y), (-0.25, y)], 0.03))
|
||
u = min(1.0, max(0.0, (t - 0.2) / 0.6))
|
||
ex = 1.6 * math.cos(u * math.pi)
|
||
lift = 0.35 * math.sin(u * math.pi)
|
||
s.append(cp([(0, -1.2), (0, -2.4), (ex, -2.4 - lift), (ex, -1.2 - lift)]))
|
||
return s
|
||
|
||
|
||
def campfire(i, t):
|
||
"""A small campfire burns low beside the box; embers drift up and fade."""
|
||
s = [cl([(-0.8, 0.45), (0.8, 0.15)], 0.16), cl([(-0.8, 0.15), (0.8, 0.45)], 0.16)]
|
||
for k, (dx, h) in enumerate(((-0.3, 0.8), (0.0, 1.2), (0.3, 0.9))):
|
||
hh = h * (0.85 + 0.15 * math.sin(i * 0.6 + k * 2))
|
||
sw = 0.1 * math.sin(i * 0.4 + k)
|
||
s.append(cp([(dx - 0.22, 0.2), (dx + 0.22, 0.2), (dx + sw, 0.2 - hh)]))
|
||
for k in range(4):
|
||
ph = (t * 1.3 + k * 0.25) % 1.0
|
||
s.append(cc(0.4 * math.sin(k * 2 + ph * 4), -0.9 - ph * 2.2, 0.06 * (1 - ph) + 0.01))
|
||
return s
|
||
|
||
|
||
def bowl(i, t):
|
||
"""A singing bowl sits on the box; the striker circles its rim and soft rings rise off it."""
|
||
s = [cl([(-0.8, -0.6)] + [(0.8 * math.cos(math.pi - math.pi * m / 8), -0.6 + 0.6 * math.sin(math.pi * m / 8))
|
||
for m in range(1, 8)] + [(0.8, -0.6)], 0.12)]
|
||
a = t * math.pi * 4
|
||
sx, sy = 0.85 * math.cos(a), -0.6 + 0.12 * math.sin(a)
|
||
s.append(cl([(sx, sy), (sx + 0.3, sy - 0.8)], 0.08))
|
||
for k in range(3):
|
||
ph = (t * 1.5 + k / 3) % 1.0
|
||
r = 0.9 + ph * 1.2
|
||
s.append(cl([(r * math.cos(b), -0.8 - 0.3 * ph * 3 + 0.4 * r * math.sin(b)) for b in
|
||
[math.pi + math.pi * m / 8 for m in range(9)]], 0.04 * (1 - ph) + 0.01))
|
||
return s
|
||
|
||
|
||
def nest(i, t):
|
||
"""Twigs weave into a nest on the box, and three eggs settle into it."""
|
||
s = []
|
||
n = min(5, int(t * 9) + 1)
|
||
for k in range(n):
|
||
y = 0.2 - k * 0.12
|
||
w = 1.0 + 0.1 * k
|
||
s.append(cl([(-w, y - 0.3), (-w * 0.5, y + 0.05 * (k % 2)), (w * 0.5, y + 0.05 * ((k + 1) % 2)), (w, y - 0.3)], 0.07))
|
||
for k in range(3):
|
||
u = min(1.0, max(0.0, (t - 0.5 - k * 0.12) / 0.15))
|
||
if u > 0:
|
||
s.append(cp(oval(-0.4 + k * 0.4, -0.25 - (1 - u) * 1.2, 0.18, 0.24, 10)))
|
||
return s
|
||
|
||
|
||
def ink(i, t):
|
||
"""A drop of ink falls into water above the box and blooms into slow curling clouds."""
|
||
s = [cl([(-2.0, -2.6), (2.0, -2.6)], 0.04)]
|
||
if t < 0.2:
|
||
s.append(cc(0, -3.6 + t * 5, 0.12))
|
||
return s
|
||
u = (t - 0.2) / 0.8
|
||
for k in range(3):
|
||
a = k * 2 * math.pi / 3 + u * 1.5
|
||
d = u * 1.2
|
||
cx, cy = d * math.cos(a) * 0.8, -2.2 + d * (0.6 + 0.4 * math.sin(a))
|
||
s.append(cl([(0, -2.55)] + [(cx * m / 4 + 0.2 * math.sin(m + u * 3), -2.55 + (cy + 2.55) * m / 4) for m in range(1, 5)], 0.05))
|
||
s.append(cc(cx, cy, 0.1 + 0.25 * u, 0.04))
|
||
return s
|
||
|
||
|
||
def rockingchair(i, t):
|
||
"""An empty rocking chair rocks to and fro beside the box, slower and slower."""
|
||
a = 0.22 * math.sin(i * 0.45) * (1 - 0.6 * t)
|
||
cx, cy = 0.0, 0.3
|
||
chair = [[(-0.9, 0.3), (-0.4, 0.45), (0.4, 0.45), (0.9, 0.3)],
|
||
[(-0.5, 0.42), (-0.5, -0.4), (0.5, -0.4), (0.5, 0.42)],
|
||
[(0.5, -0.4), (0.6, -1.7)],
|
||
[(-0.5, -0.4), (-0.4, -0.75)],
|
||
[(0.55, -1.0), (0.05, -1.0)]]
|
||
return [cl(rotate(seg, a, cx, cy), 0.1) for seg in chair]
|
||
|
||
|
||
CALM = [
|
||
(fog, "blue", "hush"), (canoe, "red", "paddle"),
|
||
(yarn, "red", "unspool"), (candle, "yellow", "glow"),
|
||
(grass, "yellow", "rustle"), (stream, "blue", "babble"),
|
||
(catnap, "red", "purr"), (squirrel, "red", "nibble"),
|
||
(dove, "blue", "coo"), (cake, "yellow", "warmth"),
|
||
(pie, "red", "waft"), (teacup, "blue", "steep"),
|
||
(lantern, "red", "flicker"), (leaf, "yellow", "drift"),
|
||
(wateringcan, "blue", "sprinkle"), (firefly, "yellow", "crickets"),
|
||
(dandelion, "yellow", "airy"), (lotus, "red", "still"),
|
||
(hammock, "blue", "sway"), (windchime, "yellow", "tingle"),
|
||
(cumulus, "blue", "airflow"), (aurora, "blue", "drone"),
|
||
(tide, "blue", "surf"), (lighthouse, "red", "foghorn"),
|
||
(moth, "yellow", "flit"), (breath, "blue", "inhale"),
|
||
(rake, "yellow", "sand"), (cairn, "blue", "stack"),
|
||
(fern, "yellow", "dew"), (sloth, "red", "yawn"),
|
||
(koi, "red", "glide"), (constellation, "yellow", "celesta"),
|
||
(honey, "yellow", "ooze"), (quilt, "red", "stitch"),
|
||
(book, "blue", "page"), (campfire, "red", "embers"),
|
||
(bowl, "yellow", "hum"), (nest, "red", "nestle"),
|
||
(ink, "blue", "seep"), (rockingchair, "red", "rocker"),
|
||
]
|
||
|
||
|
||
# ── the star: 2 s, all three primaries, plays (as well) once every set has been used up ──
|
||
|
||
STAR_FRAMES = 24
|
||
|
||
|
||
def star_special(i, t):
|
||
"""THE STAR: a big star spins up out of the box, pulses, flies up and bursts into little stars."""
|
||
s = []
|
||
cols = ["red", "yellow", "blue"]
|
||
if i < 14:
|
||
g = min(1.0, (i + 1) / 6)
|
||
y = -0.6 - g * 2.0 - (max(0, i - 10) ** 1.5) * 0.4
|
||
pulse = 1.0 + (0.25 if i in (7, 9) else 0)
|
||
rot = i * math.pi / 10
|
||
r1 = 1.6 * g * pulse
|
||
s.append(["k", "yellow"])
|
||
s.append(P(star(0, y, r1, r1 * 0.42, 5, -math.pi / 2 + rot)))
|
||
s.append(["k", "red"])
|
||
s.append(P(star(0, y, r1 * 1.4, r1 * 0.75, 5, -math.pi / 2 - rot * 1.5 + math.pi / 5), 0.11))
|
||
if i >= 4:
|
||
s.append(["k", "blue"])
|
||
for k in range(10):
|
||
a = rot + k * math.pi / 5
|
||
if (k + i) % 2 == 0:
|
||
r0 = r1 * 1.5
|
||
s.append(L([(r0 * math.cos(a), y + r0 * math.sin(a)), ((r0 + 0.5) * math.cos(a), y + (r0 + 0.5) * math.sin(a))], 0.1))
|
||
return s
|
||
k = i - 13
|
||
top = -0.6 - 2.0 - (3 ** 1.5) * 0.4
|
||
for m in range(15):
|
||
a = m * 2 * math.pi / 15 + 0.2
|
||
r = k * 0.45 + (m % 3) * 0.15
|
||
x, y = r * math.cos(a), top + r * math.sin(a) + k * k * 0.035
|
||
s.append(["k", cols[m % 3]])
|
||
size = 0.32 if (m + i) % 2 else 0.22
|
||
s.append(P(star(x, y, size, size * 0.42, 5, i * 0.5 + m)))
|
||
if k <= 2:
|
||
s.append(["k", "yellow"])
|
||
s.append(P(star(0, top, 2.6 - k * 0.6, 1.0 - k * 0.2, 8, k), 0.12))
|
||
return s
|
||
|
||
|
||
ANIMS = [
|
||
# set 0
|
||
(bloom, "red", "plip"), (rocket, "blue", "whoosh"),
|
||
(starburst, "yellow", "chime"), (bounce, "red", "boing"),
|
||
(jack, "blue", "sproing"), (balloon, "red", "pop"),
|
||
(firework, "yellow", "fizzbang"), (bird, "blue", "tweet"),
|
||
(sprout, "yellow", "kalimba"), (confetti, "red", "rattle"),
|
||
(worm, "blue", "wobble"), (lightning, "yellow", "zap"),
|
||
(spiral, "red", "slide"), (heart, "red", "thump"),
|
||
(fish, "blue", "splash"), (sun, "yellow", "rise"),
|
||
(ripples, "blue", "drip"), (tentacle, "red", "bloop"),
|
||
(butterfly, "yellow", "flutter"), (ghost, "blue", "boo"),
|
||
# set 1
|
||
(frog, "blue", "ribbit"), (snail, "yellow", "squelch"),
|
||
(cat, "red", "mew"), (umbrella, "blue", "fwump"),
|
||
(paperplane, "yellow", "swish"), (kite, "red", "breeze"),
|
||
(snowflake, "blue", "tinkle"), (raincloud, "blue", "patter"),
|
||
(moon, "yellow", "lullaby"), (tree, "red", "creak"),
|
||
(mushroom, "red", "pomp"), (volcano, "red", "rumble"),
|
||
(whale, "blue", "spout"), (ufo, "yellow", "warble"),
|
||
(crab, "red", "clack"), (notes, "blue", "tune"),
|
||
(pinwheel, "yellow", "whirr"), (bubbles, "blue", "blub"),
|
||
(target, "red", "thunk"), (dice, "yellow", "clatter"),
|
||
# set 2
|
||
(hourglass, "blue", "trickle"), (gem, "red", "sparkle"),
|
||
(padlock, "yellow", "click"), (trophy, "yellow", "fanfare"),
|
||
(crown, "red", "regal"), (rainbow, "red", "shimmer"),
|
||
(tornado, "blue", "howl"), (bee, "yellow", "buzz"),
|
||
(bat, "blue", "squeak"), (chick, "yellow", "cheep"),
|
||
]
|
||
STAR = (star_special, "yellow", "twinkle")
|
||
# The sets, in order. Set 0 (the first 5 ticks of the day) is the biggest on purpose: those
|
||
# ticks happen every day, so they get the most variety.
|
||
SETS = [ANIMS[:20] + SET0_MORE, ANIMS[20:40], ANIMS[40:]]
|
||
ALL = [a for st in SETS for a in st]
|
||
|
||
|
||
LEVELS = [7, 21, 42, 66, 100, 150, 254, 365] # routine/model.py STREAK_LEVELS
|
||
EVERY = 100 # ... and STREAK_EVERY
|
||
STREAK_SEED = 2000 # level k's animation m: seed 2000 + 100 k + m; calm 2900 + m
|
||
|
||
|
||
def streak_mods(strict=True, only=None):
|
||
"""({level: ANIMS}, calm ANIMS, {key: sound names}) from tools/streak_anims (see its __init__)."""
|
||
import streak_anims
|
||
mods = streak_anims.load("", strict, only)
|
||
snds = streak_anims.load("_sounds", strict, only)
|
||
levels = {k: list(m.ANIMS) for k, m in mods.items() if k != "calm"}
|
||
calm = list(mods["calm"].ANIMS) if "calm" in mods else []
|
||
sounds = {k: [fn.__name__ for fn in m.SOUNDS] for k, m in snds.items()}
|
||
return levels, calm, sounds
|
||
|
||
|
||
def check_unique(levels, calm, sounds):
|
||
"""Every name and every sound once, across every set, the calm ones, the star and every
|
||
streak module; and each streak animation's sound defined in its level's sounds module."""
|
||
streak = [a for k in sorted(levels) for a in levels[k]] + calm
|
||
every = ALL + CALM + [STAR] + streak
|
||
names = [fn.__name__ for fn, _, _ in every]
|
||
snd = [x for _, _, x in every]
|
||
dup = {n for n in names if names.count(n) > 1} | {n for n in snd if snd.count(n) > 1}
|
||
if dup:
|
||
raise SystemExit("not unique: %s" % sorted(dup))
|
||
for key, anims in list(levels.items()) + [("calm", calm)]:
|
||
for fn, col, x in anims:
|
||
if col not in COLORS:
|
||
raise SystemExit("%s: no colour %r" % (fn.__name__, col))
|
||
if x not in sounds.get(key, []):
|
||
raise SystemExit("%s: its sound %r isn't in streak_anims/%s_sounds.py" % (
|
||
fn.__name__, x, key if key == "calm" else "level%d" % key))
|
||
if anims and len(anims) != (4 if key == "calm" else 8):
|
||
print("note: streak %s has %d animations (%d wanted)" % (key, len(anims), 4 if key == "calm" else 8))
|
||
|
||
|
||
def level_label(k):
|
||
return "streak %d" % LEVELS[k] + (", %d, %d, ... (every %d more)" % (LEVELS[k] + EVERY, LEVELS[k] + 2 * EVERY, EVERY)
|
||
if k == len(LEVELS) - 1 else "")
|
||
|
||
|
||
def catalogue(levels, calm):
|
||
lines = ["# The check-off animations", "",
|
||
"Generated by `tools/gen_animations.py` (don't edit by hand). The first 5 ticks of a day draw at random",
|
||
"from set 0, the next 5 from set 1, and so on; past the last set, the last set keeps playing and",
|
||
"**the star** plays as well, which means it's time to ask for more animations. Picks are purely random",
|
||
"within a set: nothing remembers what has played, so repeats can happen.",
|
||
"Every name and every sound is used once; the generator refuses duplicates.", ""]
|
||
n = 0
|
||
for k, st in enumerate(SETS):
|
||
lines += ["## Set %d (ticks %d–%d, %d animations)" % (k, k * 5 + 1, k * 5 + 5, len(st)), "",
|
||
"| # | name | colour | sound | what happens |", "|---|---|---|---|---|"]
|
||
for fn, col, snd in st:
|
||
n += 1
|
||
lines.append("| %d | %s | %s | %s | %s |" % (n, fn.__name__, col, snd, fn.__doc__.strip()))
|
||
lines.append("")
|
||
lines += ["## The calm set (2 s each, %d animations)" % len(CALM), "",
|
||
"Only for tasks marked *calm animation*: one of these plays instead of the set's, never the star.",
|
||
"The tick still counts toward the next set.", "",
|
||
"| # | name | colour | sound | what happens |", "|---|---|---|---|---|"]
|
||
for k, (fn, col, snd) in enumerate(CALM):
|
||
lines.append("| c%d | %s | %s | %s | %s |" % (k + 1, fn.__name__, col, snd, fn.__doc__.strip()))
|
||
lines.append("")
|
||
lines += ["## The star (2 s, all three colours)", "", "| name | sound | what happens |", "|---|---|---|",
|
||
"| %s | %s | %s |" % (STAR[0].__name__, STAR[2], STAR[0].__doc__.strip()), ""]
|
||
lines += ["## Streak animations (2 s each, each shows the streak number)", "",
|
||
"A task ticked by hand whose streak reaches a level plays one of that level's instead of its set's",
|
||
"(a calm task, one of the calm streak ones). A level with none yet falls back to the nearest lower one.",
|
||
"Modules: `tools/streak_anims/levelK.py` and `calm.py`, sounds beside them in `*_sounds.py`.", ""]
|
||
for k in range(len(LEVELS)):
|
||
st = levels.get(k, [])
|
||
lines += ["### Level %d: %s (%d animations)" % (k, level_label(k), len(st)), ""]
|
||
if not st:
|
||
lines += ["(none yet)", ""]
|
||
continue
|
||
lines += ["| # | name | colour | sound | what happens |", "|---|---|---|---|---|"]
|
||
for m, (fn, col, snd) in enumerate(st):
|
||
lines.append("| s%d.%d | %s | %s | %s | %s |" % (k, m + 1, fn.__name__, col, snd, fn.__doc__.strip()))
|
||
lines.append("")
|
||
lines += ["### Calm streak animations (any level, calm tasks; %d animations)" % len(calm), ""]
|
||
if calm:
|
||
lines += ["| # | name | colour | sound | what happens |", "|---|---|---|---|---|"]
|
||
for m, (fn, col, snd) in enumerate(calm):
|
||
lines.append("| sc%d | %s | %s | %s | %s |" % (m + 1, fn.__name__, col, snd, fn.__doc__.strip()))
|
||
else:
|
||
lines.append("(none yet)")
|
||
lines.append("")
|
||
return "\n".join(lines)
|
||
|
||
|
||
def anim(fn, color, sound, n, seed):
|
||
return {"name": fn.__name__, "color": color, "sound": sound + ".wav", "frames": frames_of(fn, n, seed)}
|
||
|
||
|
||
def build(levels, calm):
|
||
out = {"fps": FPS, "colors": COLORS, "perSet": 5, "sets": [len(st) for st in SETS], "animations": []}
|
||
for n, (fn, color, sound) in enumerate(ALL):
|
||
out["animations"].append(anim(fn, color, sound, N, n))
|
||
out["calm"] = [anim(fn, color, sound, CALM_FRAMES, 500 + n) for n, (fn, color, sound) in enumerate(CALM)]
|
||
fn, color, sound = STAR
|
||
out["star"] = anim(fn, color, sound, STAR_FRAMES, 999)
|
||
out["streak"] = {
|
||
"levels": LEVELS, "every": EVERY,
|
||
"sets": [[anim(fn, color, sound, STREAK_FRAMES, STREAK_SEED + 100 * k + m)
|
||
for m, (fn, color, sound) in enumerate(levels.get(k, []))] for k in range(len(LEVELS))],
|
||
"calm": [anim(fn, color, sound, STREAK_FRAMES, STREAK_SEED + 900 + m) for m, (fn, color, sound) in enumerate(calm)]}
|
||
return out
|
||
|
||
|
||
def main():
|
||
import argparse
|
||
ap = argparse.ArgumentParser(description="Generate animations.json + ANIMATIONS.md")
|
||
ap.add_argument("--level", help="only this streak level (0-7, or calm) of the streak animations: "
|
||
"the others are left empty, and modules of other levels that fail to import are skipped")
|
||
ap.add_argument("--out", help="write into this folder instead of shared/ (always use it with --level)")
|
||
a = ap.parse_args()
|
||
only = None if a.level is None else ("calm" if a.level == "calm" else int(a.level))
|
||
if only is not None and not a.out:
|
||
raise SystemExit("--level writes a partial animations.json: give --out DIR (a scratch folder)")
|
||
levels, calm, sounds = streak_mods(strict=only is None, only=only)
|
||
check_unique(levels, calm, sounds) # across everything that exists, even with --level
|
||
if only is not None:
|
||
levels = {k: v for k, v in levels.items() if k == only}
|
||
calm = calm if only == "calm" else []
|
||
data = build(levels, calm)
|
||
out = a.out or os.path.join(ROOT, "shared")
|
||
os.makedirs(out, exist_ok=True)
|
||
path = os.path.join(out, "animations.json")
|
||
with open(path, "w") as f:
|
||
json.dump(data, f, separators=(",", ":"))
|
||
with open(os.path.join(out, "ANIMATIONS.md"), "w") as f:
|
||
f.write(catalogue(levels, calm))
|
||
ns = sum(len(st) for st in data["streak"]["sets"])
|
||
print(f"wrote {path}: {len(data['animations'])} animations, {len(data['calm'])} calm + the star, "
|
||
f"{ns} streak + {len(data['streak']['calm'])} calm streak, {os.path.getsize(path)} bytes")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|