v0.23.0: Routine, first public version

This commit is contained in:
2026-11-15 02:22:09 -08:00
commit 5ea848bddc
285 changed files with 23886 additions and 0 deletions
+588
View File
@@ -0,0 +1,588 @@
"""Streak level 6: a 254-day streak. Eight big 2-second celebrations, each showing the streak number.
Same rules as level0.py: fn(i, t) -> shapes, i = frame 0..23, t = 0..1; NUM(...) is where the
number goes (laid out for 3 digits). These are the second-rarest rewards in the app, so they're
built big: mythic beasts, monuments and great machines. Sounds: level6_sounds.py, same names.
"""
import math
from anim_kit import NUM, K, C, L, P, ease_out, ring, rotate, star
def rays(cx, cy, r0, r1, n, rot=0.0, w=0.1):
"""n short lines radiating from (cx, cy), between radius r0 and r1."""
out = []
for k in range(n):
a = rot + k * 2 * math.pi / n
out.append(L([(cx + r0 * math.cos(a), cy + r0 * math.sin(a)), (cx + r1 * math.cos(a), cy + r1 * math.sin(a))], w))
return out
def pop_scale(t, t0, dur=0.12, over=1.25):
"""0 before t0, then grows to over and settles back to 1 (a springy pop)."""
if t < t0:
return 0.0
u = (t - t0) / dur
if u < 1:
return over * ease_out(u)
return 1 + (over - 1) * math.exp(-(u - 1) * 1.6) * math.cos((u - 1) * 2.2)
def tf(pts, ox, oy, sc=1.0, rot=0.0):
"""Local points scaled by sc, turned rot, moved to (ox, oy)."""
c, s = math.cos(rot), math.sin(rot)
return [(ox + sc * (x * c - y * s), oy + sc * (x * s + y * c)) for x, y in pts]
def tube(spine, w0, w1):
"""A tapering band round a polyline: width w0 at its start, w1 at its end."""
left, right = [], []
n = len(spine)
for k, (x, y) in enumerate(spine):
px, py = spine[max(0, k - 1)]
nx, ny = spine[min(n - 1, k + 1)]
dx, dy = nx - px, ny - py
d = math.hypot(dx, dy) or 1.0
w = (w0 + (w1 - w0) * k / (n - 1)) / 2
left.append((x - dy / d * w, y + dx / d * w))
right.append((x + dy / d * w, y - dx / d * w))
return left + right[::-1]
# ── 1. dragon ──
def dragon(i, t):
"""A dragon rears up behind the box, beats a wing, draws a breath and roars a great cone of fire; the number glows in the flames and is left smouldering."""
s = []
u = ease_out(min(1.0, i / 6))
back = (-0.35, -0.3) if i in (6, 7) else (0.0, 0.0) # the breath in
thrust = 0.3 if 8 <= i <= 16 else 0.0
shake = 0.08 * math.sin(i * 2.7) if 8 <= i <= 16 else 0.0
hx, hy = -2.3 + back[0] + thrust, -0.4 - 4.0 * u + back[1] + shake
flap = [0.0, -0.6, -1.2, -0.4, 0.6, 1.0, 0.2][i % 7] if i < 14 else 0.3 * math.sin(i * 0.8)
s.append(L([(-3.6, 0.9), (-4.6, 1.0), (-5.0, 0.5), (-4.7, 0.15 + 0.1 * math.sin(i))], 0.22)) # the tail
s.append(P(ring(-3.0, 0.65, 1.0, 12, 0, 0.05))) # the haunch
wing = [(-2.9, -0.9), (-3.6, -2.9 + flap), (-5.3, -3.9 + flap * 1.4), (-4.9, -2.9 + flap), (-5.2, -2.0 + flap * 0.6),
(-4.5, -1.8 + flap * 0.5), (-4.4, -0.9 + flap * 0.3), (-3.7, -0.7), (-3.2, 0.0)]
s.append(P(wing)) # the wing
s.append(K("yellow"))
for k in (2, 4, 6): # its finger bones
s.append(L([(-3.6, -2.9 + flap), wing[k]], 0.05))
s.append(K("red"))
spine = [(-2.7, 1.0), (-3.4, -0.4), (-3.3, -1.7 * u - 0.2), (hx - 0.6, hy + 1.6), (hx, hy)]
s.append(P(tube(spine, 1.5, 0.75))) # the neck
for k in range(1, 4): # spines down its back
x, y = spine[k]
s.append(P([(x - 0.4, y), (x - 0.95, y - 0.25), (x - 0.35, y - 0.5)]))
jaw = 0.55 if 8 <= i <= 16 else 0.3 if i in (6, 7) else 0.08
s.append(P(tf([(-0.3, -0.5), (0.6, -0.62), (1.6, -0.42), (2.1, -0.12), (1.9, 0.05), (0.6, 0.12), (-0.3, 0.35)], hx, hy)))
s.append(P(tf(rotate([(0.2, 0.1), (1.7, 0.1), (1.6, 0.32), (0.2, 0.55)], jaw, 0.2, 0.1), hx, hy))) # the jaw
s.append(P(tf([(-0.1, -0.5), (-1.0, -1.4), (0.3, -0.62)], hx, hy))) # horns
s.append(P(tf([(0.4, -0.58), (-0.2, -1.6), (0.8, -0.62)], hx, hy)))
s.append(K("yellow"))
s.append(C(hx + 0.7, hy - 0.3, 0.13)) # the eye
mx, my = hx + 2.1, hy + 0.35 # the mouth
if 8 <= i <= 19: # the fire cone
grow = min(1.0, (i - 7) / 3)
tail = max(0.0, (i - 16) / 4)
d0, d1 = 6.4 * tail, 6.4 * grow
ang = 0.06
def edge(d, side):
hw = (0.35 + 0.33 * d) * (1 + 0.08 * math.sin(d * 3 + i * 2.1 + side))
return (mx + d * math.cos(ang) - side * hw * math.sin(ang), my + d * math.sin(ang) + side * hw * math.cos(ang))
ds = [d0 + (d1 - d0) * m / 9 for m in range(10)]
top = [edge(d, -1) for d in ds]
bot = [edge(d, 1) for d in ds]
tip = [(mx + d1 + 0.6, my + 0.4 * math.sin(i * 1.7) + d1 * math.sin(ang))]
s.append(P(top + tip + bot[::-1], 0, 0.12))
for m in range(0, 9, 2): # licks off the edges
x, y = top[m]
s.append(P([(x - 0.3, y + 0.1), (x + 0.15, y - 0.55 - 0.2 * ((m + i) % 2)), (x + 0.4, y + 0.1)]))
x, y = bot[m]
s.append(P([(x - 0.3, y - 0.1), (x + 0.15, y + 0.45 + 0.2 * ((m + i) % 2)), (x + 0.4, y - 0.1)]))
if i <= 16:
s.append(K("red"))
s.append(P([(mx, my - 0.25), (mx + 1.4 * grow, my + 0.05 + 0.15 * math.sin(i)), (mx, my + 0.3)]))
s.append(K("red"))
nx, ny = mx + 3.35, my + 0.25
if i >= 10:
g = pop_scale(t, 10 / 23, 0.12, 1.25)
s.append(NUM(nx, ny, 2.05 * g, rot=0.06 + 0.04 * math.sin(i * 1.3)))
if i >= 18: # smouldering: sparks
s.append(K("yellow"))
for k in range(6):
a = k * 1.05 + i * 0.4
s.append(C(nx + 2.9 * math.cos(a), ny + 1.5 * math.sin(a), 0.08 + 0.05 * ((k + i) % 2)))
if i >= 15: # smoke from the nostrils
s.append(K("red"))
for k in range(2):
age = i - 15 - k * 3
if 0 <= age < 8:
s.append(C(hx + 1.6 - age * 0.12, hy - 0.8 - age * 0.3, 0.12 + age * 0.05, 0.06))
return s
# ── 2. excavator ──
def excavator(i, t):
"""A big excavator by the box swings its arm down, bites deep into the ground and heaves up a scoop of earth; the number rises out of the hole it dug while the digger shakes its loaded bucket in triumph."""
s = []
g = -0.55 # the ground line
up, dig = (-2.4, -2.9, 0.4), (-2.95, 1.6, -0.4) # (boom, stick, bucket curl)
poses = [up, (-2.55, -1.6, 0.2), (-2.75, -0.1, 0.0), (-2.9, 1.1, -0.3), dig,
(-2.95, 1.62, 0.3), (-2.9, 1.5, 1.1), (-2.85, 1.2, 1.8), (-2.75, 0.2, 1.9), (-2.6, -1.2, 1.9),
(-2.48, -2.3, 1.9), (-2.42, -2.8, 1.9), (-2.4, -2.9, 1.9)]
if i < len(poses):
a1, a2, cu = poses[i]
elif i < 16:
a1, a2, cu = -2.4, -2.9, 1.9 + 0.12 * math.sin(i * 2.0)
else: # shakes it, triumphant
a1, a2, cu = -2.4 - 0.06 * math.sin(i * 1.7), -2.9 + 0.12 * math.sin(i * 1.3), 1.9 + 0.3 * math.sin(i * 2.2)
bob = -0.12 if i in (5, 6, 16, 17) else 0.0
s.append(K("blue"))
s.append(P([(3.0, g), (7.4, g), (7.7, g - 0.45), (7.4, g - 0.9), (3.0, g - 0.9), (2.7, g - 0.45)])) # the tracks
s.append(K("yellow"))
for k in range(5):
s.append(C(3.3 + k * 1.0, g - 0.45, 0.24))
by = g - 0.9 + bob
s.append(P([(3.4, by), (7.2, by), (7.2, by - 1.5), (5.0, by - 1.5), (5.0, by - 2.9), (3.5, by - 2.9), (3.3, by - 1.5)])) # house + cab
s.append(L([(6.6, by - 1.5), (6.6, by - 2.3)], 0.16)) # the exhaust
s.append(K("blue"))
s.append(P([(3.75, by - 1.75), (4.75, by - 1.75), (4.75, by - 2.65), (3.85, by - 2.65)])) # the window
if i in (2, 3, 6, 7, 8, 9): # it works hard: smoke
s.append(C(6.7 + (i % 3) * 0.2, by - 2.7 - (i % 3) * 0.35, 0.18 + (i % 3) * 0.08, 0.07))
bx, byy = 4.0, by - 1.6 # the boom's pivot
ex, ey = bx + 3.6 * math.cos(a1), byy + 3.6 * math.sin(a1)
tx, ty = ex + 3.2 * math.cos(a2), ey + 3.2 * math.sin(a2)
s.append(K("yellow"))
s.append(P([(bx, byy - 0.35), (ex, ey - 0.25), (ex, ey + 0.25), (bx, byy + 0.35)])) # the boom
s.append(L([(ex, ey), (tx, ty)], 0.38)) # the stick
s.append(K("blue"))
mx, my = bx + 1.8 * math.cos(a1), byy + 1.8 * math.sin(a1)
s.append(L([(bx + 0.5, byy + 0.4), (mx, my + 0.3)], 0.14)) # its ram
s.append(C(ex, ey, 0.2))
full = i >= 6
bucket = rotate([(tx, ty), (tx + 0.9, ty + 0.1), (tx + 1.0, ty + 0.9), (tx + 0.3, ty + 1.05), (tx - 0.25, ty + 0.6)], a2 - 1.3 + cu, tx, ty)
s.append(K("yellow"))
s.append(P(bucket))
s.append(K("blue"))
s.append(L([bucket[2], bucket[3]], 0.1)) # the teeth's edge
s.append(K("red"))
if full: # the heaped earth in the bucket
cx, cy = sum(p[0] for p in bucket) / 5, sum(p[1] for p in bucket) / 5
s.append(P(ring(cx, cy - 0.25, 0.6, 9, i, 0.12)))
for k in range(4): # clods falling off as it lifts
age = i - 8 - k
if 0 <= age < 6:
s.append(C(tx + 0.4 + k * 0.3 - age * 0.1, min(g - 0.1, ty + 0.9 + age * age * 0.18), 0.13 + 0.04 * (k % 2)))
if 4 <= i <= 7: # dirt flicked up by the bite
for k in range(5):
a = -math.pi / 2 + (k - 2) * 0.45
r = 0.7 + (i - 4) * 0.4
s.append(C(0.3 + r * math.cos(a), g + 0.2 + r * math.sin(a), 0.12))
if i >= 5: # the dug-up mounds either side
for x in (-1.6, 1.7):
s.append(P([(x - 0.7, g + 0.1), (x - 0.2, g - 0.45), (x + 0.3, g - 0.35), (x + 0.7, g + 0.1)]))
if i >= 10: # the number rises out of the hole
rise = ease_out(min(1.0, (i - 10) / 4))
gg = pop_scale(t, 10 / 23, 0.15, 1.25)
s.append(K("blue"))
s.append(NUM(-0.4, g - 0.2 - 1.5 * rise, 1.95 * gg, rot=0.05 * math.sin(i * 1.1)))
if i in (11, 12, 13):
s.append(K("red"))
s += rays(-0.4, g - 1.7, 2.5, 3.0, 9, -0.2, 0.08)
return s
# ── 3. geyser ──
def geyser(i, t):
"""The ground by the box rumbles and spits, then a geyser blasts up in a towering column and holds the number high on its crown of spray."""
s = []
vx, vy = 1.3, -0.55 # the vent
sh = 0.1 * math.sin(i * 3.1) if i < 7 else 0.0
s.append(K("yellow"))
s.append(P([(vx - 2.3 + sh, vy + 0.2), (vx - 1.5 + sh, vy - 0.35), (vx - 0.55, vy - 0.45), (vx + 0.55, vy - 0.45),
(vx + 1.5 + sh, vy - 0.35), (vx + 2.3 + sh, vy + 0.2)])) # the sinter mound
s.append(K("blue"))
if i < 7: # spits and bubbles
hgt = [0.3, 0.8, 0.2, 1.4, 0.4, 1.9, 0.6][i]
s.append(P([(vx - 0.3, vy - 0.4), (vx - 0.1, vy - 0.4 - hgt), (vx + 0.15, vy - 0.4 - hgt * 0.8), (vx + 0.3, vy - 0.4)]))
for k in range(2):
s.append(C(vx - 0.6 + k * 1.2, vy - 0.6 - (i % 3) * 0.2, 0.12, 0.05))
if i in (3, 5, 6):
s.append(K("red"))
s += rays(vx, vy - 0.5, 0.6, 1.0, 5, -math.pi * 0.9, 0.06)
return s
H = [3.5, 6.4, 7.4, 7.0][i - 7] if i < 11 else 6.8 + 0.35 * math.sin(i * 1.4)
if i >= 21:
H -= (i - 20) * 0.6
top = vy - 0.45 - H
n = 10
left = [(vx - 0.45 - 0.35 * m / n + 0.12 * math.sin(m * 1.7 + i * 1.9), vy - 0.45 - H * m / n) for m in range(n + 1)]
right = [(vx + 0.45 + 0.35 * m / n + 0.12 * math.sin(m * 1.3 + i * 2.3 + 1), vy - 0.45 - H * m / n) for m in range(n + 1)]
s.append(P(left + right[::-1], 0, 0.06)) # the column
for k in range(7): # the crown of spray, curling over
a = math.pi + k * math.pi / 6
r = 1.5 + 0.2 * ((k + i) % 2)
s.append(P(ring(vx + r * 0.9 * math.cos(a), top + 0.3 + r * 0.55 * math.sin(a), 0.42, 9, k + i, 0.06)))
s.append(P(ring(vx, top + 0.1, 1.0, 12, i, 0.08)))
for side in (-1, 1): # spray raining down both sides
for m in range(6):
u = ((i * 0.33 + m / 6) % 1.0)
x = vx + side * (1.2 + 2.3 * u)
y = top + 0.8 - 1.2 * u + 7.4 * u * u
if y < vy:
s.append(C(x, y, 0.1 + 0.06 * (m % 2)))
if i >= 8: # steam drifting off
s.append(K("yellow"))
for k in range(3):
age = (i - 8 + k * 4) % 12
s.append(C(vx + 1.6 + age * 0.15, vy - 1.5 - age * 0.4 - k, 0.22 + age * 0.05, 0.07))
s.append(K("red"))
g = pop_scale(t, 8 / 23, 0.12, 1.3)
s.append(NUM(vx, top - 1.9, 2.25 * g, rot=0.08 * math.sin(i * 0.9)))
return s
# ── 4. pyramid ──
def pyramid(i, t):
"""A pyramid builds itself above the box, one course of stone blocks thudding down at a time; a capstone lands on top and the number is carved into its face in a blaze of light."""
s = []
bx, by, hw, H = 1.0, -0.55, 4.3, 6.6 # base centre, half-width, height
nc = 5
ch = 1.05
def half(y):
return hw * (1 - (by - y) / H)
if i >= 13: # the blaze behind it
s.append(K("yellow"))
s += rays(bx, by - H + 0.3, 1.4, 2.4 + 0.3 * (i % 2), 14, i * 0.05, 0.12)
s.append(K("yellow"))
for k in range(nc):
land = 1 + 2 * k
if i < land:
break
drop = 0.9 if i == land else 0.0
y0, y1 = by - k * ch - drop, by - (k + 1) * ch - drop
w0, w1 = half(by - k * ch), half(by - (k + 1) * ch)
nb = nc + 1 - k
for m in range(nb):
f0, f1 = m / nb, (m + 1) / nb
g = 0.05
pts = [(bx - w0 + 2 * w0 * f0 + g, y0 - g), (bx - w0 + 2 * w0 * f1 - g, y0 - g),
(bx - w1 + 2 * w1 * f1 - g, y1 + g), (bx - w1 + 2 * w1 * f0 + g, y1 + g)]
s.append(P(pts, 0, 0.03))
if i == land + 1: # dust as it lands
s.append(K("red"))
for side in (-1, 1):
x = bx + side * (w0 + 0.3)
s.append(C(x, y0 - 0.25, 0.25, 0.06))
s.append(C(x + side * 0.45, y0 - 0.5, 0.18, 0.06))
s.append(K("yellow"))
yt = by - nc * ch
capy = {11: -2.6, 12: -0.9}.get(i, 0.0)
if i >= 11:
s.append(K("red"))
w = half(yt)
s.append(P([(bx - w, yt - capy), (bx + w, yt - capy), (bx, by - H - capy)], 0, 0.03))
if i in (12, 13):
s.append(K("yellow"))
s.append(P(star(bx, by - H, 1.3, 0.45, 8, i * 0.3)))
elif i >= 14 and i % 3 != 1: # its glint
s.append(K("yellow"))
s.append(P(star(bx + 0.1, by - H + 0.35, 0.6, 0.15, 4, 0.3 * (i % 2))))
if i >= 13:
g = pop_scale(t, 13 / 23, 0.1, 1.2)
s.append(K("blue"))
s.append(NUM(bx, by - 2.15, 1.65 * g, w=0.32, rot=0.0))
if i in (13, 14):
s += rays(bx, by - 2.15, 2.4, 3.0, 10, 0.2, 0.08)
return s
# ── 5. eagle ──
def eagle_shape(x, y, sc, flap, tilt=0.0):
"""An eagle seen from the front, wings spread; flap: -1 = tips up, 0 = level, 1 = tips down."""
s = []
for side in (-1, 1):
ty = flap * 1.6
pts = [(side * 0.35, -0.35), (side * 1.6, -0.75 + ty * 0.4), (side * 3.2, -0.8 + ty), (side * 4.0, -0.55 + ty)]
for m in range(5): # the fingered primaries
fx = side * (4.0 - m * 0.35)
fy = -0.55 + ty + 0.15 + m * 0.18
pts += [(fx + side * 0.25, fy + 0.35), (fx - side * 0.1, fy + 0.12)]
pts += [(side * 1.6, 0.2 + ty * 0.3), (side * 0.35, 0.35)]
s.append(P(tf(pts if side > 0 else pts, x, y, sc, tilt)))
s.append(P(tf([(-0.5, -0.6), (0.5, -0.6), (0.6, 0.6), (0.0, 1.0), (-0.6, 0.6)], x, y, sc, tilt))) # body
s.append(P(tf([(-0.35, 0.8), (0.35, 0.8), (0.7, 1.7), (-0.7, 1.7)], x, y, sc, tilt))) # tail fan
s.append(K("yellow"))
s.append(P(tf(ring(0, -0.95, 0.45, 10, 0, 0.02), x, y, sc, tilt))) # head
s.append(K("red"))
s.append(P(tf([(-0.15, -0.85), (0.15, -0.85), (0.05, -0.4), (-0.05, -0.45)], x, y, sc, tilt))) # hooked beak
s.append(C(*tf([(-0.2, -1.05)], x, y, sc, tilt)[0], 0.07 * sc))
s.append(C(*tf([(0.2, -1.05)], x, y, sc, tilt)[0], 0.07 * sc))
s.append(K("blue"))
return s
def eagle(i, t):
"""An eagle stoops out of the sky onto the box, snatches the number up in its talons and climbs away on huge wingbeats, then soars, the number hanging below it."""
s = []
if i < 5: # the stoop, wings swept up
u = i / 5
x, y = 5.0 + (0.2 - 5.0) * u, -8.0 + (-2.2 + 8.0) * u * u
sc, flap, tilt = 0.55 + 0.2 * u, -1.1, -0.5 * (1 - u)
s.append(K("blue"))
for k in range(3):
s.append(L([(x + 0.6 + k * 0.4, y - 1.0 - k * 0.3), (x + 1.6 + k * 0.4, y - 2.4 - k * 0.3)], 0.07))
s += eagle_shape(x, y, sc, flap, tilt)
return s
if i < 8: # the grab
x, y = 0.3, -2.4 - (i - 5) * 0.4
sc, flap, tilt = 0.8, [1.0, 0.0, -1.0][i - 5], 0.0
else: # the climb, then the soar
u = ease_out(min(1.0, (i - 8) / 9))
x, y = 0.3 + 1.0 * u, -3.6 - 2.6 * u + 0.15 * math.sin(i * 0.9)
sc = 0.8 + 0.35 * u
flap = [-1.0, 0.1, 1.0][i % 3] if i < 17 else 0.15 * math.sin(i * 0.8)
tilt = 0.05 * math.sin(i * 0.7)
ny = y + sc * 1.7 + 1.25
s.append(K("red"))
g = pop_scale(t, 5 / 23, 0.15, 1.3)
s.append(NUM(x, ny, 2.0 * g * min(1.0, 0.75 + 0.25 * sc), rot=0.1 * math.sin(i * 0.6)))
s.append(K("yellow"))
for side in (-1, 1): # talons gripping the number
tx = x + side * 0.6 * sc
s.append(L([(tx, y + 0.7 * sc), (tx + side * 0.1, ny - 1.0), (tx + side * 0.35, ny - 0.75)], 0.1))
if i in (5, 6):
s.append(K("red"))
s += rays(x, ny, 2.5, 3.1, 9, 0.2, 0.09)
s.append(K("blue"))
s += eagle_shape(x, y, sc, flap, tilt)
for k in range(3): # a feather or two, drifting down
age = i - 8 - k * 4
if age >= 0:
fx, fy = x - 1.8 + k * 1.6 + 0.3 * math.sin(age * 0.9), min(0.8, y + 0.6 + age * 0.22)
s.append(P(rotate([(fx - 0.25, fy), (fx, fy - 0.08), (fx + 0.25, fy), (fx, fy + 0.08)], math.sin(age) * 0.8, fx, fy)))
return s
# ── 6. drawbridge ──
def drawbridge(i, t):
"""A castle springs up over the box; its drawbridge clanks down on its chains and slams flat, banners unroll down the towers and the number stands in the lit gateway."""
s = []
gy = -0.55 # the ground line
grow = [0.2, 0.55, 0.9, 1.08, 0.97, 1.0][i] if i < 6 else 1.0
def at(pts):
return [(x, gy + (y - gy) * grow) for x, y in pts]
crenel = []
for k in range(9):
x = -1.4 + k * 0.6
crenel += [(x, -5.6), (x, -6.0), (x + 0.3, -6.0), (x + 0.3, -5.6)]
s.append(P(at([(-1.6, gy)] + [(-1.6, -5.6)] + crenel + [(3.6, -5.6), (3.6, gy)]))) # the gatehouse wall
for tx in (-3.4, 3.4): # the towers
cr = []
for k in range(4):
x = tx + k * 0.6
cr += [(x, -7.0), (x, -7.5), (x + 0.3, -7.5), (x + 0.3, -7.0)]
s.append(P(at([(tx, gy), (tx, -7.0)] + cr[2:] + [(tx + 2.0, -7.0), (tx + 2.0, gy)])))
s.append(K("yellow"))
for tx in (-2.4, 4.4):
for wy in (-5.6, -3.4):
s.append(P(at([(tx - 0.1, wy), (tx + 0.1, wy), (tx + 0.1, wy + 0.8), (tx - 0.1, wy + 0.8)]))) # arrow slits
cx, cy, r = 1.0, -3.3, 1.95 # the gateway: an arch, lit inside
arch = [(cx - r, gy)] + [(cx + r * math.cos(math.pi + k * math.pi / 8), cy + r * math.sin(math.pi + k * math.pi / 8)) for k in range(9)] + [(cx + r, gy)]
s.append(P(at(arch)))
if i >= 6:
for tx in (-2.4, 4.4): # pennants on poles
s.append(K("blue"))
s.append(L([(tx, -7.5), (tx, -9.0)], 0.08))
s.append(K("yellow"))
s.append(P([(tx, -9.0)] + [(tx + 0.4 * k, -8.8 + 0.18 * math.sin(i * 1.4 - k * 1.1)) for k in range(1, 5)] + [(tx, -8.4)]))
if i >= 6:
g = pop_scale(t, 12 / 23, 0.1, 1.2) if i >= 12 else 0.0
if g:
s.append(K("blue"))
s.append(NUM(cx, -2.55, 1.55 * g, w=0.28, rot=0.0))
edges = [-5.4, -5.3, -5.3, -5.3, -5.2, -5.2, -5.2, -4.8, -4.2, -3.4, -2.4, -1.4, 1.0, 0.5, 0.65]
e = edges[i] if i < len(edges) else 0.6
e = gy + (e - gy) * grow
s.append(K("blue"))
if e < gy: # still up: planks over the gateway
w = 2.15 + (e + 5.4) * 0.05
s.append(P([(cx - 2.15, gy), (cx + 2.15, gy), (cx + w, e), (cx - w, e)]))
s.append(K("red"))
for k in range(1, 5):
x = cx - 2.15 + k * 0.86
s.append(L([(x, gy - 0.1), (x, e + 0.1)], 0.05))
s.append(K("blue"))
for side in (-1, 1):
s.append(L([(cx + side * 2.3, gy + (-5.5 - gy) * grow), (cx + side * 2.0, e + 0.05)], 0.07)) # the chains
else: # down, toward us
w = 2.15 + (e - gy) * 0.7
s.append(P([(cx - 2.15, gy), (cx + 2.15, gy), (cx + w, e), (cx - w, e)]))
s.append(K("red"))
for k in range(1, 5):
f = k / 5
s.append(L([(cx - 2.15 + 4.3 * f, gy + 0.05), (cx - w + 2 * w * f, e - 0.05)], 0.05))
s.append(K("blue"))
for side in (-1, 1):
s.append(L([(cx + side * 2.3, -5.5), (cx + side * 2.3, gy - 0.2), (cx + side * w, e)], 0.06))
if i in (12, 13): # the slam
s.append(K("red"))
for side in (-1, 1):
for k in range(3):
s.append(C(cx + side * (w + 0.3 + k * 0.4), e - 0.1 - k * 0.25, 0.22 + k * 0.05, 0.06))
s.append(K("yellow"))
s += rays(cx, -2.55, 2.3, 2.9, 10, 0.1, 0.08)
if i >= 13: # banners unroll down the towers
n = min(1.0, (i - 12) / 4)
for tx, col in ((-2.4, "yellow"), (4.4, "yellow")):
bot = -6.8 + 3.6 * n
s.append(K(col))
s.append(P([(tx - 0.65, -6.8), (tx + 0.65, -6.8), (tx + 0.65, bot), (tx, bot - 0.45), (tx - 0.65, bot)]))
s.append(K("blue"))
s.append(L([(tx, -6.5), (tx, bot - 0.2)], 0.1))
s.append(L([(tx - 0.8, -6.85), (tx + 0.8, -6.85)], 0.1))
return s
# ── 7. crane ──
def crane(i, t):
"""A tower crane over the box runs its hook down, hoists a great sign with the number up out of the box and swings it into place, cables singing."""
s = []
mx0, mx1, jy = 4.4, 5.1, -7.0 # the mast, the jib's height
s.append(K("yellow"))
s.append(L([(mx0, 0.6), (mx0, jy)], 0.16))
s.append(L([(mx1, 0.6), (mx1, jy)], 0.16))
s.append(L([(mx0 if k % 2 == 0 else mx1, 0.6 - k * 0.76) for k in range(11)], 0.1)) # its lattice
s.append(L([(-2.6, jy), (7.4, jy)], 0.15)) # the jib
s.append(L([(-2.6, jy + 0.45), (7.4, jy + 0.45)], 0.13))
s.append(L([(-2.6 + k * 0.5, jy + (0.45 if k % 2 else 0.0)) for k in range(21)], 0.08))
s.append(L([(-2.6, jy), (mx0 + 0.35, jy - 1.4), (7.4, jy)], 0.06)) # the ties
s.append(L([(mx0 + 0.35, jy - 1.4), (mx0 + 0.35, jy)], 0.08))
s.append(K("blue"))
s.append(P([(6.4, jy + 0.45), (7.4, jy + 0.45), (7.4, jy + 1.5), (6.4, jy + 1.5)])) # the counterweight
s.append(P([(mx0 - 0.4, jy + 0.45), (mx1 + 0.05, jy + 0.45), (mx1 + 0.05, jy + 1.4), (mx0 - 0.4, jy + 1.4)])) # the cab
s.append(K("yellow"))
s.append(P([(mx0 - 0.3, jy + 0.6), (mx0 + 0.2, jy + 0.6), (mx0 + 0.2, jy + 1.0), (mx0 - 0.3, jy + 1.0)]))
# the trolley's x and the hook's y, frame by frame
if i < 6:
u = ease_out(i / 5)
tx, hy = 3.2 + (0.0 - 3.2) * u, jy + 1.2 + (-1.0 - jy - 1.2) * u
elif i < 9:
tx, hy = 0.0, -1.0 - (i - 6) * 0.15
else:
u = ease_out(min(1.0, (i - 9) / 7))
tx, hy = 0.0 + 1.2 * u, -1.45 + (-5.0 + 1.45) * u
sw = 0.0
if i >= 9:
sw = 0.22 * math.exp(-(i - 9) * 0.18) * math.sin((i - 9) * 0.95)
s.append(K("blue"))
s.append(P([(tx - 0.4, jy + 0.35), (tx + 0.4, jy + 0.35), (tx + 0.4, jy + 0.7), (tx - 0.4, jy + 0.7)])) # the trolley
hx = tx + (hy - jy) * -math.sin(sw) * 0.0
s.append(L([(tx - 0.1, jy + 0.7), (hx - 0.1, hy)], 0.04))
s.append(L([(tx + 0.1, jy + 0.7), (hx + 0.1, hy)], 0.04))
s.append(L([(hx, hy - 0.05), (hx, hy + 0.3), (hx + 0.2, hy + 0.45), (hx + 0.05, hy + 0.6)], 0.09)) # the hook
if i >= 6:
g = min(1.0, 0.35 + (i - 6) * 0.22)
pw, ph = 5.4 * g, 2.6 * g
top = hy + 0.6 + 0.9 * g
corners = [(hx - pw / 2, top), (hx + pw / 2, top), (hx + pw / 2, top + ph), (hx - pw / 2, top + ph)]
corners = rotate(corners, sw, hx, hy + 0.5)
s.append(L([corners[0], rotate([(hx, hy + 0.55)], sw, hx, hy + 0.5)[0], corners[1]], 0.05)) # the sling
s.append(K("yellow"))
s.append(P(corners, 0, 0.03))
s.append(K("blue"))
s.append(P(corners, 0.12, 0.03))
for c in corners:
ix, iy = c[0] + (hx - c[0]) * 0.08, c[1] + (top + ph / 2 - c[1]) * 0.15
s.append(C(ix, iy, 0.07))
ncx, ncy = rotate([(hx, top + ph / 2)], sw, hx, hy + 0.5)[0]
s.append(K("red"))
s.append(NUM(ncx, ncy, 1.85 * g, rot=sw))
if i >= 16 and i % 2 == 0: # lights along the sign
s.append(K("red"))
s += rays(ncx, ncy, 3.3, 3.9, 12, i * 0.1, 0.08)
return s
# ── 8. longship ──
def longship(i, t):
"""A longship rows up a great swell, its striped sail bursting full with the number on it, crests, and crashes down in a burst of spray before riding on."""
s = []
x = -1.2 + 2.6 * ease_out(t)
if i < 9:
pitch, lift = -0.32 * i / 8, -0.9 * i / 8
elif i < 12:
pitch, lift = [-0.05, 0.22, 0.08][i - 9], [-1.0, -0.3, 0.1][i - 9]
else:
pitch, lift = 0.06 * math.sin((i - 12) * 0.9), 0.1 * math.sin((i - 12) * 0.9)
wy = -0.9 + lift # the waterline under the ship
s.append(K("blue"))
for row in range(3): # the sea
y = -0.6 + row * 0.5
ph = i * 0.9 + row * 1.3
amp = 0.25 + (0.5 if i < 10 and row == 0 else 0)
s.append(L([(-5.0 + m * 0.6, y + amp * math.sin(ph + m * 0.8) * (1.0 if m > 3 else 0.6)) for m in range(19)], 0.12))
def at(pts):
return rotate([(x + px, wy + py) for px, py in pts], pitch, x, wy)
s.append(K("red"))
hull = [(-3.4, -1.0), (-2.6, -0.2), (-1.2, 0.35), (1.2, 0.35), (2.6, -0.2), (3.4, -1.0), (3.1, -0.9), (2.4, -0.6),
(-2.4, -0.6), (-3.1, -0.9)]
s.append(P(at(hull)))
s.append(L(at([(3.2, -0.9), (3.6, -1.7), (3.3, -2.3), (2.9, -2.1), (3.0, -1.8)]), 0.16)) # the curled prow
s.append(L(at([(-3.2, -0.9), (-3.6, -1.7), (-3.4, -2.1), (-3.05, -2.0)]), 0.16)) # and stern
s.append(K("yellow"))
for k in range(6): # shields along the side
s.append(P(at(ring(-2.0 + k * 0.8, -0.35, 0.27, 8, k, 0.02))))
s.append(K("red"))
sweep = math.sin(i * 1.1)
for k in range(5): # the oars, all together
ox, oy = at([(-1.6 + k * 0.8, -0.1)])[0]
s.append(L([(ox, oy), (ox - 0.7 - 0.5 * sweep, oy + 1.1 - 0.2 * abs(sweep))], 0.07))
s.append(L(at([(0.0, -0.6), (0.0, -5.8)]), 0.14)) # the mast
full = min(1.0, max(0.0, (i - 2) / 4))
s.append(L(at([(-2.6, -5.5), (2.6, -5.5)]), 0.12)) # the yard
if full > 0:
bel = 0.45 * full + 0.06 * math.sin(i * 1.5)
hgt = 3.4 * full
xs = [-2.5 + 5.0 * m / 8 for m in range(9)]
edge = [(px, -5.4) for px in xs] + [(px, -5.4 + hgt + bel * math.sin(math.pi * (px + 2.5) / 5.0)) for px in reversed(xs)]
s.append(K("yellow"))
s.append(P(at(edge), 0, 0.03))
s.append(K("red"))
for sx in (-2.15, 2.15): # its stripes, down each side
s.append(P(at([(sx - 0.3, -5.4), (sx + 0.3, -5.4), (sx + 0.3, -5.4 + hgt + bel * 0.45), (sx - 0.3, -5.4 + hgt + bel * 0.45)])))
if i >= 6:
s.append(K("blue"))
ncx, ncy = at([(0.0, -3.55 + bel * 0.5)])[0]
s.append(NUM(ncx, ncy, 1.85 * pop_scale(t, 6 / 23, 0.12, 1.2), rot=pitch))
if 10 <= i <= 15: # the crash of spray
k = i - 10
s.append(K("blue"))
for side in (-1, 1):
bx = x + side * 3.0
for m in range(5):
a = -math.pi / 2 + side * (0.3 + m * 0.25)
r = 0.5 + k * 0.5
px, py = bx + r * math.cos(a), wy - 0.6 + r * math.sin(a) + k * k * 0.06
s.append(C(px, py, max(0.06, 0.24 - k * 0.03)))
return s
ANIMS = [
(dragon, "red", "scorch"), (excavator, "yellow", "hydraulic"),
(geyser, "blue", "gush"), (pyramid, "yellow", "quarry"),
(eagle, "blue", "screech"), (drawbridge, "red", "clank"),
(crane, "yellow", "winch"), (longship, "red", "oarstroke"),
]