"""Streak level 5: a 150-day streak. Eight 2-second celebrations, each showing the streak number. Bigger than level 4: whole skies and whole stages, the cosmos turning out for it. Same rules as level0.py: fn(i, t) -> shapes, i = frame 0..23, NUM(...) is the number (laid out for 3 digits). Sounds: level5_sounds.py, same names as below. """ import math from anim_kit import NUM, K, C, L, P, ease_out, oval, 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 clamp(x): return max(0.0, min(1.0, x)) def lerp(a, b, u): return a + (b - a) * u def twinkles(pts, i, r=0.22): """Little four-point stars at pts, blinking out of step.""" out = [] for k, (x, y) in enumerate(pts): if (i + k) % 4: out.append(P(star(x, y, r if (i + k) % 3 else r * 0.6, r * 0.32, 4, 0))) return out def supernova(i, t): """A star above the box swells and throbs, collapses to a point, then explodes: a blinding flash, shockwaves racing out, and the number blazing in the glowing remnant.""" s = [] cx, cy = 0.7, -4.5 s.append(K("blue")) s += twinkles([(-3.2, -8.6), (4.6, -8.0), (-3.4, -1.8), (4.8, -1.4), (-1.2, -9.4)], i, 0.18) if i < 9: # swelling, throbbing r = 1.1 + 0.13 * i + 0.3 * math.sin(i * 1.9) s.append(K("red")) s.append(P(ring(cx, cy, r + 0.45, 18, i, 0.12), 0.1)) s.append(K("yellow")) s.append(P(star(cx, cy, r, r * 0.7, 12, i * 0.2))) elif i < 11: # collapse s.append(K("yellow")) s.append(C(cx, cy, 0.3 if i == 9 else 0.15)) s.append(K("red")) for k in range(10): a = k * 2 * math.pi / 10 + i r0 = 2.6 - (i - 9) * 1.0 s.append(L([(cx + r0 * math.cos(a), cy + r0 * math.sin(a)), (cx + (r0 - 0.9) * math.cos(a), cy + (r0 - 0.9) * math.sin(a))], 0.08)) elif i == 11: # the flash s.append(K("yellow")) s.append(P(star(cx, cy, 5.2, 2.4, 16, 0.1))) s.append(K("red")) s.append(P(star(cx, cy, 2.6, 1.4, 10, 0.4))) if i >= 12: k = i - 12 for m, col in enumerate(("red", "blue", "yellow")): # shockwaves r = 2.9 + (k - m * 2.5) * 0.55 if 2.9 <= r < 7.5: s.append(K(col)) s.append(P(ring(cx, cy, r, 30, i * 0.2 + m, 0.12), max(0.03, 0.16 - k * 0.01))) s.append(K("red")) # debris flying out for m in range(14): a = m * 2 * math.pi / 14 + 0.2 r = 3.0 + k * 0.5 + (m % 3) * 0.3 x, y = cx + r * math.cos(a), cy + r * math.sin(a) * 0.95 s.append(P(rotate([(x - 0.18, y), (x + 0.2, y - 0.08), (x, y + 0.2)], m + i, x, y))) s.append(K("yellow")) # the remnant, glowing gr = 2.6 + 0.12 * math.sin(i * 1.7) s.append(P(star(cx, cy, gr + 0.4, gr - 0.1, 20, i * 0.05))) g = pop_scale(t, 12 / 23, 0.12, 1.4) s.append(K("blue")) s.append(NUM(cx, cy, 1.85 * g, rot=0.05 * math.sin(i))) return s def eclipse(i, t): """The moon slides across the sun above the box; at totality the corona flares out, a diamond ring flashes, and the number shines from the black disc.""" s = [] cx, cy, r = 0.7, -4.4, 2.05 total = 11 if i < total: s.append(K("yellow")) s += rays(cx, cy, r + 0.3, r + 0.8 + 0.15 * (i % 2), 16, i * 0.08, 0.12) s.append(C(cx, cy, r)) else: k = i - total s.append(K("yellow")) # the corona cr = 2.9 + 0.6 * ease_out(clamp(k / 4)) s.append(P(star(cx, cy, cr + 0.25 * math.sin(i), r + 0.1, 14, i * 0.04))) s.append(K("red")) s.append(P(star(cx, cy, cr * 0.82, r + 0.05, 9, 0.3 - i * 0.03), 0.07)) s.append(K("yellow")) s += twinkles([(-3.0, -8.4), (4.6, -8.2), (-3.3, -1.6), (4.7, -1.4), (-2.6, -6.0), (4.3, -2.6)], i, 0.24) mx = lerp(-5.2, cx, ease_out(clamp(i / total))) if i < total else cx s.append(K("blue")) s.append(C(mx, cy - 0.05 * (i < total), r + 0.04)) if i in (total, total + 1): # the diamond ring dx, dy = cx + r * 0.72, cy - r * 0.72 s.append(K("yellow")) s.append(P(star(dx, dy, 1.3 - (i - total) * 0.4, 0.2, 4, 0.3))) s.append(C(dx, dy, 0.3)) if i >= total + 1: g = pop_scale(t, (total + 1) / 23, 0.14, 1.3) s.append(K("yellow")) s.append(NUM(cx, cy, 1.45 * g, rot=0.04 * math.sin(i * 0.6))) return s def galaxy(i, t): """A spiral galaxy winds itself out of the dark above the box, arms of stars sweeping round a blazing core that holds the number.""" s = [] cx, cy, tilt, sq = 0.7, -4.5, -0.22, 0.55 spin = -i * 0.09 grow = ease_out(clamp(t * 1.5)) def at(r, a): x, y = r * math.cos(a), r * math.sin(a) * sq c, sn = math.cos(tilt), math.sin(tilt) return (cx + x * c - y * sn, cy + x * sn + y * c) for arm in range(2): # the arms, dots of stars for m in range(26): th = m * 0.24 if th > 6.2 * grow + 0.2: break r = 2.75 * math.exp(0.095 * th) a = arm * math.pi + th + spin col = ("blue", "yellow", "blue", "red")[(m + arm) % 4] s.append(K(col)) x, y = at(r, a) s.append(C(x, y, max(0.08, 0.24 - m * 0.006))) if m % 3 == 0: x2, y2 = at(r * 1.12, a - 0.1) s.append(C(x2, y2, 0.08)) s.append(K("yellow")) # the core cg = 0.5 + 0.5 * ease_out(clamp(t * 2.5)) s.append(P(rotate(oval(cx, cy, 2.5 * cg, 1.5 * cg, 16), tilt, cx, cy))) s.append(K("blue")) s += twinkles([(-3.2, -8.4), (4.6, -8.6), (-3.4, -1.4), (4.8, -1.6)], i, 0.2) if i >= 6: g = pop_scale(t, 6 / 23, 0.14, 1.35) s.append(K("red")) s.append(NUM(cx, cy, 1.45 * g, rot=tilt + 0.05 * math.sin(i * 0.5))) return s def hyperspace(i, t): """A starship above the box jumps to light speed: the stars stretch into streaks, it vanishes in a flash, and the number hurtles out of the vanishing point.""" s = [] cx, cy = 0.7, -4.5 warp = clamp((i - 3) / 7) # how stretched the stars are shown = i >= 10 for k in range(30): # the stars / streaks a = k * 2.399 + 0.3 r0 = 0.8 + (k * 0.731) % 4.5 r = r0 + (i * 0.55 * warp if i > 3 else 0) * (1 + (k % 3) * 0.3) r = 0.9 + (r - 0.9) % 6.0 ln = 0.05 + warp * (0.8 + 0.25 * r) ca, sa = math.cos(a), math.sin(a) * 0.85 if shown: # keep clear of the number need = min(2.7 / max(1e-3, abs(ca)), 1.4 / max(1e-3, abs(sa))) if r < need: r = need + (r % 1.5) x0, y0 = cx + r * ca, cy + r * sa if not (-4.2 < x0 < 5.8 and -10.5 < y0 < 0.0): continue s.append(K("yellow" if k % 3 else "blue")) if warp < 0.08: s.append(C(x0, y0, 0.08 + 0.04 * (k % 2))) else: s.append(L([(x0, y0), (cx + (r + ln) * ca, cy + (r + ln) * sa)], 0.06 + 0.04 * warp)) if i < 10: # the ship, rushing away z = 1.6 * (1 - ease_out(clamp((i - 5) / 5)) * 0.92) y = lerp(-1.6, cy, ease_out(clamp((i - 4) / 6))) x = lerp(0.7, cx, clamp((i - 4) / 6)) s.append(K("red")) s.append(P([(x, y - 0.9 * z), (x + 1.3 * z, y + 0.45 * z), (x + 0.4 * z, y + 0.25 * z), (x, y + 0.45 * z), (x - 0.4 * z, y + 0.25 * z), (x - 1.3 * z, y + 0.45 * z)])) s.append(K("blue")) s.append(P([(x - 0.15 * z, y - 0.35 * z), (x + 0.15 * z, y - 0.35 * z), (x, y - 0.6 * z)])) s.append(K("yellow")) for side in (-1, 1): s.append(C(x + side * 0.35 * z, y + 0.42 * z, (0.16 + 0.06 * (i % 2)) * z)) if i in (10, 11): # the flash s.append(K("yellow")) s.append(P(star(cx, cy, 2.6 - (i - 10) * 0.9, 0.5, 8, 0.3))) if i >= 11: u = ease_out(clamp((i - 11) / 5)) g = 1.0 if i > 16 else 1 + 0.12 * (i == 16) s.append(K("red")) s.append(NUM(cx, cy, (0.3 + 1.6 * u) * g, rot=(1 - u) * 1.2)) return s def pipeorgan(i, t): """A cathedral organ rises behind the box, rank on rank of golden pipes, and thunders three great chords that shake the number out above it.""" s = [] cx = 0.7 grow = ease_out(clamp(t * 4)) base = -1.3 hs = [2.3, 2.9, 3.4, 3.0, 3.9, 4.6, 3.9, 3.0, 3.4, 2.9, 2.3] chord = i in (6, 7, 12, 13, 18, 19) s.append(K("yellow")) for k, h in enumerate(hs): # the pipes x = cx + (k - 5) * 0.62 hh = h * grow + (0.12 if chord and k % 2 == i % 2 else 0) top = base - hh s.append(P([(x - 0.24, base), (x + 0.24, base), (x + 0.24, top), (x - 0.24, top)], 0, 0.03)) s.append(K("blue")) my = base - 0.55 s.append(P([(x - 0.17, my), (x + 0.17, my), (x, my - 0.3)], 0, 0.02)) # its mouth if chord and h > 2.8: s.append(L([(x - 0.2, top - 0.25), (x + 0.2, top - 0.25)], 0.06)) s.append(K("yellow")) s.append(K("red")) # the case and console s.append(P([(cx - 3.6, base), (cx + 3.6, base), (cx + 3.4, -0.2), (cx - 3.4, -0.2)])) s.append(P([(cx - 3.7, base - 0.25), (cx + 3.7, base - 0.25), (cx + 3.7, base + 0.05), (cx - 3.7, base + 0.05)])) s.append(K("yellow")) s.append(P([(cx - 1.6, -0.75), (cx + 1.6, -0.75), (cx + 1.6, -0.5), (cx - 1.6, -0.5)], 0, 0.02)) s.append(K("blue")) for k in range(9): s.append(L([(cx - 1.4 + k * 0.35, -0.75), (cx - 1.4 + k * 0.35, -0.6)], 0.06, 0.01)) if i >= 6: # sound rolling off the top s.append(K("blue")) for m in range(3): age = (i - 6) % 6 + m * 2 rr = 3.3 + age * 0.35 if rr < 6.5: for side in (-1, 1): arc = [(cx + side * rr * math.cos(a), base - 1.6 - rr * math.sin(a) * 0.9) for a in (0.15, 0.4, 0.65)] s.append(L(arc, max(0.04, 0.13 - age * 0.012))) if i >= 6: g = pop_scale(t, 6 / 23, 0.14, 1.35) kick = 1.08 if chord else 1.0 y = base - 4.9 - 0.9 - 0.4 * ease_out(clamp((i - 6) / 6)) s.append(K("red")) s.append(NUM(cx, y, 1.85 * g * kick, rot=0.06 * math.sin(i * 1.1))) if chord: s.append(K("yellow")) s += rays(cx, y, 2.5, 3.0, 12, i * 0.2, 0.08) return s def headliner(i, t): """A rock stage by the box: speaker stacks thump, the lights strobe, pyro columns roar up off the stacks and the number takes the stage.""" s = [] cx, floor = 0.7, -0.4 beat = i % 3 == 0 s.append(K("blue")) # the stage s.append(P([(cx - 4.5, floor), (cx + 4.5, floor), (cx + 4.3, floor + 0.45), (cx - 4.3, floor + 0.45)])) s.append(K("red")) # the lighting truss s.append(L([(cx - 4.2, -7.6), (cx + 4.2, -7.6)], 0.14)) s.append(L([(cx - 4.2, -7.3), (cx + 4.2, -7.3)], 0.08)) for k in range(9): x = cx - 4.0 + k * 1.0 s.append(L([(x, -7.6), (x + 0.5, -7.3)], 0.05)) for k in range(5): # the lamps, strobing x = cx - 3.2 + k * 1.6 on = (k + i) % 2 == 0 if i < 8 else (k + i // 2) % 2 == 0 s.append(K(["yellow", "blue", "red", "blue", "yellow"][k])) s.append(P([(x - 0.25, -7.3), (x + 0.25, -7.3), (x + 0.32, -6.85), (x - 0.32, -6.85)])) if on: s.append(K("yellow")) s += rays(x, -6.75, 0.3, 0.7 + 0.2 * (i % 2), 5, math.pi * 0.3, 0.06) for side in (-1, 1): # speaker stacks x0 = cx + side * 3.35 for m in range(2): y1 = floor - m * 1.2 s.append(K("blue")) s.append(P([(x0 - 0.65, y1), (x0 + 0.65, y1), (x0 + 0.65, y1 - 1.15), (x0 - 0.65, y1 - 1.15)])) s.append(K("yellow")) s.append(C(x0, y1 - 0.58, 0.38 + (0.1 if beat else 0.0), 0.09)) s.append(C(x0, y1 - 0.58, 0.1)) if i >= 8: # pyro off the top k = (i - 8) % 7 fh = [2.6, 3.4, 3.0, 2.2, 1.4, 0.7, 0.3][k] top = floor - 2.4 s.append(K("red")) s.append(P([(x0 - 0.55, top), (x0 - 0.2, top - fh * 0.6), (x0, top - fh), (x0 + 0.25, top - fh * 0.55), (x0 + 0.55, top)])) s.append(K("yellow")) s.append(P([(x0 - 0.3, top), (x0, top - fh * 0.6), (x0 + 0.3, top)])) if k < 3: for m in range(3): s.append(C(x0 + (m - 1) * 0.5 + 0.1 * math.sin(i + m), top - fh - 0.3 - m * 0.25, 0.1)) if i >= 8: g = pop_scale(t, 8 / 23, 0.12, 1.2) * (1.05 if beat else 1.0) y = -3.6 - 0.5 * ease_out(clamp((i - 8) / 4)) s.append(K("red")) s.append(NUM(cx, y, 1.6 * g, rot=0.08 * math.sin(i * 1.4))) else: # a guitar waits in the spotlight s.append(K("red")) gy = -2.0 s.append(P(ring(cx - 0.3, gy, 0.55, 10, 0, 0.04))) s.append(P(ring(cx + 0.25, gy - 0.25, 0.4, 10, 0, 0.04))) s.append(K("yellow")) s.append(L([(cx, gy - 0.1), (cx + 1.6, gy - 1.4)], 0.12)) s.append(C(cx - 0.2, gy - 0.05, 0.12)) return s def diva(i, t): """An opera diva rises by the box and sings one soaring note: her song ripples out, a row of glasses shatters, and the number swells out of the aria.""" s = [] rise = ease_out(clamp(t * 5)) dy = (1 - rise) * 2.5 dx = -2.1 breath = 0.06 * math.sin(i * 0.9) s.append(K("red")) # her gown s.append(P([(dx - 0.45, -2.6 + dy), (dx + 0.45, -2.6 + dy), (dx + 1.3, -0.3 + dy * 0.2), (dx - 1.3, -0.3 + dy * 0.2)])) s.append(P(oval(dx, -2.85 + dy, 0.55 + breath, 0.5 + breath, 10))) sing = i >= 4 s.append(K("yellow")) # arms flung wide when she sings for side in (-1, 1): a = (0.9 if sing else 0.2) + 0.1 * math.sin(i * 0.7 + side) hx, hy = dx + side * 1.3 * math.cos(-a), -2.9 + dy - 1.2 * math.sin(a) * (1 if sing else -0.3) s.append(L([(dx + side * 0.45, -3.0 + dy), (hx, hy)], 0.13)) hy0 = -3.75 + dy s.append(C(dx, hy0, 0.45)) # her head s.append(K("blue")) s.append(P([(dx - 0.5, hy0 - 0.1), (dx - 0.4, hy0 - 0.5), (dx, hy0 - 0.62), (dx + 0.4, hy0 - 0.5), (dx + 0.5, hy0 - 0.1)])) # helmet s.append(K("yellow")) for side in (-1, 1): # its horns s.append(P([(dx + side * 0.4, hy0 - 0.35), (dx + side * 0.85, hy0 - 1.0), (dx + side * 0.55, hy0 - 0.3)])) s.append(K("red")) mo = 0.06 if not sing else 0.16 + 0.04 * (i % 2) s.append(P(oval(dx + 0.15, hy0 + 0.18, 0.12, mo, 8))) mx, my = dx + 0.3, hy0 + 0.15 gx = [2.8, 3.6, 4.4] shatter = 13 if sing: # the song rippling out s.append(K("blue")) for m in range(4): age = (i - 4) % 8 + m * 2 rr = 0.8 + age * 0.55 if rr < 6.0: arc = [(mx + rr * math.cos(a), my + rr * math.sin(a)) for a in (-0.1, 0.12, 0.34, 0.56, 0.75)] s.append(L(arc, max(0.04, 0.12 - age * 0.007))) s.append(K("blue")) # the glasses on their shelf s.append(L([(gx[0] - 0.5, -0.5), (gx[2] + 0.5, -0.5)], 0.1)) for k, x in enumerate(gx): if i < shatter: wob = 0.06 * math.sin(i * 3 + k) * (i > 8) s.append(P([(x - 0.3 + wob, -1.55), (x + 0.3 + wob, -1.55), (x + 0.05, -1.05), (x - 0.05, -1.05)], 0.06)) s.append(L([(x, -1.05), (x, -0.6)], 0.06)) else: kk = i - shatter s.append(L([(x, -0.95), (x, -0.6)], 0.06)) for m in range(5): a = -math.pi / 2 + (m - 2) * 0.55 r = 0.3 + kk * 0.35 px, py = x + r * math.cos(a), -1.3 + r * math.sin(a) + kk * kk * 0.05 if py < -0.55: s.append(P(rotate([(px - 0.12, py), (px + 0.12, py - 0.05), (px, py + 0.14)], m + kk, px, py))) if i in (shatter, shatter + 1): s.append(K("yellow")) for x in gx: s.append(P(star(x, -1.3, 0.55, 0.15, 6, i))) if i >= 6: u = ease_out(clamp((i - 6) / 6)) g = 1.0 + 0.1 * (i in (shatter, shatter + 1)) x, y = lerp(mx + 1.6, 1.6, u), lerp(my - 0.9, -6.0, u) s.append(K("red")) s.append(NUM(x, y, (0.6 + 1.25 * u) * g, rot=0.12 * math.sin(i * 1.5) * (1 - 0.5 * u))) return s def premiere(i, t): """It's opening night by the box: searchlights sweep the sky, cameras flash along the red carpet, and the beams swing in to cross over the number.""" s = [] cx, ny = 0.7, -3.7 lamps = ((-3.8, -0.6), (5.2, -0.6)) settle = ease_out(clamp((i - 9) / 5)) for k, (lx, ly) in enumerate(lamps): # the beams side = -1 if k == 0 else 1 sweep = -math.pi / 2 + side * (0.15 + 0.5 * math.sin(i * 0.55 + k * 1.7)) final = math.atan2(-9.2 - ly, cx - lx) a = lerp(sweep, final, settle) ln, wd = 9.5, 0.06 ca, sa = math.cos(a), math.sin(a) nx_, ny_ = -sa, ca s.append(K("yellow")) s.append(P([(lx + 0.18 * nx_, ly + 0.18 * ny_), (lx + ln * ca + ln * wd * nx_, ly + ln * sa + ln * wd * ny_), (lx + ln * ca - ln * wd * nx_, ly + ln * sa - ln * wd * ny_), (lx - 0.18 * nx_, ly - 0.18 * ny_)], 0, 0.03)) s.append(K("blue")) # the searchlight itself s.append(P(rotate([(lx - 0.4, ly - 0.35), (lx + 0.4, ly - 0.35), (lx + 0.4, ly + 0.35), (lx - 0.4, ly + 0.35)], a + math.pi / 2, lx, ly))) s.append(P([(lx - 0.5, ly + 0.3), (lx + 0.5, ly + 0.3), (lx + 0.6, -0.1 + 0.3), (lx - 0.6, -0.1 + 0.3)])) s.append(K("red")) # the red carpet s.append(P([(cx - 1.5, -0.25), (cx + 1.5, -0.25), (cx + 0.6, -1.6), (cx - 0.6, -1.6)])) s.append(K("blue")) # rope posts for side in (-1, 1): s.append(L([(cx + side * 1.7, -0.3), (cx + side * 1.7, -0.95)], 0.08)) s.append(L([(cx + side * 1.0, -1.65), (cx + side * 1.0, -2.05)], 0.06)) s.append(L([(cx + side * 1.7, -0.9), (cx + side * 1.35, -1.25), (cx + side * 1.0, -1.95)], 0.05)) flashes = [(-1.9, -1.4), (3.3, -1.5), (-1.5, -2.6), (2.9, -2.5), (-2.4, -0.7), (3.9, -0.9)] s.append(K("yellow")) # camera flashes for k, (x, y) in enumerate(flashes): if (i * 5 + k * 3) % 7 == 0: s.append(P(star(x, y, 0.55, 0.14, 8, k))) if i >= 9: g = pop_scale(t, 11 / 23, 0.14, 1.15) if i >= 11 else 0.0 if g > 0: s.append(K("red")) s.append(NUM(cx, ny, 1.6 * g, rot=0.04 * math.sin(i))) if i % 2: s.append(K("yellow")) s += rays(cx, ny, 2.5, 2.9, 10, i * 0.15, 0.08) return s ANIMS = [ (supernova, "yellow", "nova"), (eclipse, "yellow", "totality"), (galaxy, "blue", "cosmos"), (hyperspace, "red", "warpjump"), (pipeorgan, "yellow", "toccata"), (headliner, "red", "powerchord"), (diva, "red", "aria"), (premiere, "yellow", "klieg"), ]