"""Streak level 4: a 100-day streak. Eight 2-second celebrations, each showing the streak number. A big milestone, so each one is a show: the stage, the screen, the sky and the moon. Same rules as level0.py: fn(i, t) -> shapes, i = frame 0..23, NUM(...) is the number (laid out for 3 digits). Sounds: level4_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 curtaincall(i, t): """Red stage curtains sweep open, a spotlight snaps on, and the number rises centre stage, takes a bow and is showered with roses.""" s = [] cx, x0, x1, top, floor = 0.6, -3.6, 4.8, -6.8, -0.4 s.append(K("blue")) # the stage boards s.append(P([(x0 - 0.3, floor), (x1 + 0.3, floor), (x1 + 0.1, floor + 0.45), (x0 - 0.1, floor + 0.45)])) op = ease_out(clamp((i - 1) / 6)) # 0 closed .. 1 open if i >= 7: # the spotlight s.append(K("yellow")) w = 0.5 + 1.9 * clamp((i - 7) / 3) s.append(P([(cx - 0.3, top + 0.7), (cx + 0.3, top + 0.7), (cx + w, floor - 0.1), (cx - w, floor - 0.1)], 0, 0.03)) s.append(P(oval(cx, floor - 0.1, w + 0.25, 0.3))) if i >= 8: # the number rises and bows g = pop_scale(t, 8 / 23, 0.14, 1.3) y = -2.5 - 0.5 * ease_out(clamp((i - 8) / 5)) rot = 0.0 if 16 <= i <= 19: bow = [0.5, 1.0, 1.0, 0.4][i - 16] y += 0.35 * bow rot = -0.22 * bow s.append(K("blue")) s.append(NUM(cx, y, 1.8 * g, rot=rot)) if i in (10, 12, 20, 22): s.append(K("yellow")) s += rays(cx, y, 2.6, 3.1, 8, 0.2 + i * 0.1, 0.09) s.append(K("red")) # the curtains sway = 0.12 * math.sin(i * 0.9) * (1 - op) for side in (-1, 1): outer = x0 if side < 0 else x1 pts = [(outer, top)] for m in range(9): f = m / 8 w = 1.6 - 1.1 * math.sin(math.pi * f * 0.85) # tied back: narrow at the tie xi = lerp(cx + side * 0.05 + sway * f, outer - side * w, op) pts.append((xi, top + (floor - top) * f)) pts.append((outer, floor)) s.append(P(pts if side < 0 else list(reversed(pts)))) if op > 0.6: # the gold tie-backs s.append(K("yellow")) s.append(C(outer - side * 0.6, top + (floor - top) * 0.6, 0.22)) s.append(K("red")) s.append(K("yellow")) # the valance, scalloped val = [(x0 - 0.4, top - 0.4), (x1 + 0.4, top - 0.4)] for m in range(14, -1, -1): x = x0 - 0.4 + (x1 - x0 + 0.8) * m / 14 val.append((x, top + (0.75 if m % 2 else 0.45))) s.append(P(val)) if i >= 15: # roses thrown on for k in range(6): u = clamp((i - 15 - k * 0.8) / 4) if u <= 0: continue side = -1 if k % 2 else 1 sx = cx + side * 5.0 ex = cx + side * (2.6 - (k // 2) * 0.35) x = lerp(sx, ex, u) y = lerp(-5.5, floor - 0.2, u) - 2.0 * u * (1 - u) * 2 a = u * 5 + k s.append(K("blue")) s.append(L([(x, y), (x + 0.45 * math.cos(a), y + 0.45 * math.sin(a))], 0.06)) s.append(K("red")) s.append(C(x, y, 0.18)) return s def marquee(i, t): """A cinema marquee rises out of the box, its bulbs chasing round the frame, and the number drops onto the board in lights.""" s = [] rise = ease_out(clamp(t * 4)) dy = (1 - rise) * 4.5 cx = 0.6 bx0, bx1, by0, by1 = cx - 2.8, cx + 2.8, -5.6 + dy, -2.0 + dy s.append(K("blue")) for px in (cx - 1.9, cx + 1.9): # the posts s.append(L([(px, by1), (px, -0.3 + dy * 0.2)], 0.22)) s.append(K("yellow")) # the crest on top, with a star s.append(P([(cx - 1.6, by0 - 0.3), (cx - 0.9, by0 - 1.25), (cx + 0.9, by0 - 1.25), (cx + 1.6, by0 - 0.3)])) s.append(K("red")) s.append(P(star(cx, by0 - 0.78, 0.4 + 0.1 * (i % 2), 0.18, 5, -math.pi / 2 + i * 0.15))) s.append(P([(bx0 - 0.45, by0 - 0.45), (bx1 + 0.45, by0 - 0.45), (bx1 + 0.45, by1 + 0.45), (bx0 - 0.45, by1 + 0.45)])) s.append(K("blue")) s.append(P([(bx0, by0), (bx1, by0), (bx1, by1), (bx0, by1)], 0, 0.03)) per = [] # bulbs round the frame nx, ny = 13, 8 for k in range(nx): per.append((bx0 - 0.22 + (bx1 - bx0 + 0.44) * k / nx, by0 - 0.22)) for k in range(ny): per.append((bx1 + 0.22, by0 - 0.22 + (by1 - by0 + 0.44) * k / ny)) for k in range(nx): per.append((bx1 + 0.22 - (bx1 - bx0 + 0.44) * k / nx, by1 + 0.22)) for k in range(ny): per.append((bx0 - 0.22, by1 + 0.22 - (by1 - by0 + 0.44) * k / ny)) s.append(K("yellow")) for k, (x, y) in enumerate(per): lit = (k - i) % 3 == 0 if i < 14 else (i % 2 == 0) s.append(C(x, y, 0.15 if lit else 0.07, 0, 0.02)) if i >= 5: # the number drops in, in lights u = clamp((i - 5) / 3) b = [0, 0, 0, 0.25, -0.1, 0.04, 0][min(6, i - 5)] y = lerp(by0 - 1.2, (by0 + by1) / 2, ease_out(u)) + b s.append(NUM(cx, y, 1.75 * (0.6 + 0.4 * u))) if i >= 9: # starbursts at the corners s.append(K(["yellow", "red"][i % 2])) for x, y in ((bx0 - 0.5, by0 - 0.5), (bx1 + 0.5, by0 - 0.5)): s.append(P(star(x, y - 0.5, 0.75 if i % 2 else 0.5, 0.2, 8, i * 0.2))) return s def filmleader(i, t): """A projector clatters by the box and throws a countdown onto a big screen: the hand sweeps round, round, round, then the number fills the screen.""" s = [] sx0, sx1, sy0, sy1 = -1.0, 4.4, -6.5, -2.6 scx, scy = (sx0 + sx1) / 2, (sy0 + sy1) / 2 lx, ly = -1.35, -1.0 # the lens s.append(K("yellow")) # the beam bw = 0.06 if i % 2 else 0.1 s.append(L([(lx, ly), (sx0 + 0.1, sy0 + 0.15)], bw, 0.03)) s.append(L([(lx, ly), (sx0 + 0.1, sy1 - 0.15)], bw, 0.03)) s.append(L([(lx, ly), (scx, sy1 - 0.1)], 0.04, 0.03)) s.append(K("blue")) # the projector s.append(P([(-3.3, -1.5), (-1.6, -1.5), (-1.6, -0.35), (-3.3, -0.35)])) s.append(P([(-1.65, -1.25), (lx, -1.2), (lx, -0.8), (-1.65, -0.75)])) s.append(L([(-2.9, -0.35), (-3.1, 0.3)], 0.12)) s.append(L([(-2.0, -0.35), (-1.8, 0.3)], 0.12)) s.append(K("red")) for rx in (-2.95, -1.95): # the reels, spinning s.append(C(rx, -2.15, 0.55, 0.1)) for k in range(3): a = k * 2 * math.pi / 3 + i * 0.7 + rx s.append(L([(rx, -2.15), (rx + 0.5 * math.cos(a), -2.15 + 0.5 * math.sin(a))], 0.07)) s.append(L([(-2.95, -2.7), (-2.45, -2.95), (-1.95, -2.7)], 0.05)) # the film over the top if i >= 13: # the lit screen s.append(K("yellow")) s.append(P([(sx0, sy0), (sx1, sy0), (sx1, sy1), (sx0, sy1)], 0, 0.03)) s.append(K("blue")) s.append(P([(sx0, sy0), (sx1, sy0), (sx1, sy1), (sx0, sy1)], 0.2, 0.03)) s.append(L([(scx - 0.6, sy1), (scx - 0.9, -0.3)], 0.1)) # the screen's stand s.append(L([(scx + 0.6, sy1), (scx + 0.9, -0.3)], 0.1)) if i < 13: # the leader: three sweeps s.append(K("yellow")) frac = (i % 4 + 1) / 4 pts = [(scx, scy)] + [(scx + 1.45 * math.cos(-math.pi / 2 + a * frac * 2 * math.pi / 12), scy + 1.45 * math.sin(-math.pi / 2 + a * frac * 2 * math.pi / 12)) for a in range(13)] s.append(P(pts, 0, 0.03)) s.append(K("red")) s.append(C(scx, scy, 1.5, 0.1)) s.append(C(scx, scy, 1.15, 0.07)) s.append(L([(sx0 + 0.3, scy), (sx1 - 0.3, scy)], 0.06)) s.append(L([(scx, sy0 + 0.25), (scx, sy1 - 0.25)], 0.06)) if i % 4 == 3: s.append(K("yellow")) s += rays(scx, scy, 1.7, 1.9, 12, i, 0.08) else: g = pop_scale(t, 13 / 23, 0.12, 1.3) s.append(K("red")) s.append(NUM(scx, scy + 0.05, 2.1 * g, rot=0.05 * math.sin(i))) if i in (13, 14): s.append(K("blue")) s += rays(scx, scy, 2.8, 3.6, 12, 0.1, 0.1) if i >= 16: s.append(K("red")) for k, (x, y) in enumerate(((sx0 - 0.4, sy0 - 0.3), (sx1 + 0.4, sy0 - 0.3), (sx1 + 0.4, sy1 + 0.2))): if (i + k) % 3: s.append(P(star(x, y, 0.35, 0.12, 4, i * 0.3))) return s def note(x, y, a=0.0, z=1.0): """A quaver: a head, a stem and a flag, turned a, scaled z.""" head = rotate(oval(x, y, 0.24 * z, 0.17 * z, 8, -0.4), a, x, y) stem = rotate([(x + 0.2 * z, y), (x + 0.2 * z, y - 0.75 * z), (x + 0.5 * z, y - 0.45 * z)], a, x, y) return [P(head), L(stem, 0.07 * z)] def grandpiano(i, t): """A grand piano rises by the box, its lid swings open, the keys ripple and a fountain of notes sprays out, carrying the number high.""" s = [] rise = ease_out(clamp(t * 5)) dy = (1 - rise) * 2.0 top, bot = -2.1 + dy, -1.3 + dy xl, xr = -2.4, 3.2 s.append(K("blue")) for lx in (-1.9, 2.8): # legs s.append(L([(lx, bot), (lx - 0.05, -0.25 + dy * 0.3)], 0.2)) s.append(L([(0.4, bot), (0.4, -0.45 + dy * 0.3)], 0.08)) # the pedal lyre s.append(P([(0.2, -0.45 + dy * 0.3), (0.6, -0.45 + dy * 0.3), (0.55, -0.3 + dy * 0.3), (0.25, -0.3 + dy * 0.3)])) s.append(P([(xl, top), (xr - 0.4, top), (xr, top + 0.25), (xr, bot), (xl, bot)])) # the body ang = 0.36 * ease_out(clamp((i - 1) / 4)) # the lid opens hx, hy = xl + 0.9, top lid = rotate([(hx, top), (xr, top), (xr, top - 0.18), (hx, top - 0.14)], -ang, hx, hy) s.append(P(lid)) if ang > 0.05: px = 2.2 ty = hy - (px - hx) * math.tan(ang) s.append(K("yellow")) s.append(L([(px - 0.3, top), (px, ty + 0.1)], 0.07)) # the prop stick s.append(K("yellow")) # the keyboard ky0, ky1 = bot - 0.05, bot + 0.3 s.append(P([(xl - 0.5, ky0), (xl + 2.6, ky0), (xl + 2.6, ky1), (xl - 0.5, ky1)], 0, 0.02)) s.append(K("blue")) for k in range(12): x = xl - 0.35 + k * 0.25 down = 3 <= i < 13 and (k - (i - 3) * 1.4) % 7 < 1.5 s.append(L([(x, ky0), (x, ky0 + (0.28 if down else 0.15))], 0.07 if not down else 0.11, 0.01)) if i >= 4: # the fountain of notes for k in range(12): u = (i - 4 - k * 0.7) / 9 if 0 < u <= 1: side = 1 if k % 2 else -1 x = 0.9 + side * (0.4 + (k % 4) * 0.5) * u * 2.4 y = top - 0.4 - 6.0 * u + 4.0 * u * u * (k % 3 == 0) if abs(x - 0.8) < 2.6 and abs(y + 6.2) < 1.3 and i >= 11: continue # keep clear of the number s.append(K(["red", "yellow", "blue"][k % 3])) s += note(x, y, side * u * 0.8, 0.9 + 0.3 * (k % 2)) if i >= 10: g = pop_scale(t, 10 / 23, 0.14, 1.35) y = -4.9 - 1.3 * ease_out(clamp((i - 10) / 5)) s.append(K("red")) s.append(NUM(0.8, y, 1.9 * g, rot=0.1 * math.sin(i * 0.8))) if i in (11, 13, 18, 20): s.append(K("yellow")) s += rays(0.8, y, 2.6, 3.0, 10, i * 0.2, 0.08) return s def gong(i, t): """A great gong hangs in its frame over the box; a mallet winds back, strikes, and the gong shudders out rings as the number glows on its face.""" s = [] gx, gy, gr = 0.6, -3.6, 1.95 hit = 8 shake = 0.0 if i >= hit: shake = 0.22 * math.exp(-(i - hit) * 0.18) * math.sin((i - hit) * 2.3) s.append(K("red")) # the frame s.append(L([(gx - 2.6, -0.3), (gx - 2.6, -6.4)], 0.24)) s.append(L([(gx + 2.6, -0.3), (gx + 2.6, -6.4)], 0.24)) s.append(P([(gx - 3.2, -6.3), (gx + 3.2, -6.3), (gx + 3.6, -6.9), (gx + 2.8, -6.65), (gx - 2.8, -6.65), (gx - 3.6, -6.9)])) s.append(L([(gx - 3.0, -0.3), (gx - 2.2, -0.3)], 0.14)) s.append(L([(gx + 2.2, -0.3), (gx + 3.0, -0.3)], 0.14)) cx, cy = gx + shake * 0.4, gy s.append(K("blue")) # its cords s.append(L([(gx - 1.0, -6.3), (cx - 0.9, cy - gr + 0.25)], 0.05)) s.append(L([(gx + 1.0, -6.3), (cx + 0.9, cy - gr + 0.25)], 0.05)) if i >= hit: # rings shuddering off it for k in range(3): age = (i - hit) - k * 3 if 0 <= age < 10: s.append(K(["yellow", "red", "blue"][k])) s.append(P(ring(cx, cy, gr + 0.35 + age * 0.38, 26, i * 0.3, 0.1), max(0.03, 0.14 - age * 0.012))) s.append(K("yellow")) wob = 0.04 if i < hit else 0.04 + 0.16 * math.exp(-(i - hit) * 0.2) s.append(P(rotate(ring(cx, cy, gr, 22, 0, wob), shake, cx, cy))) s.append(K("red")) s.append(P(rotate(ring(cx, cy, gr - 0.25, 22, 0, wob), shake, cx, cy), 0.06)) if i < hit + 1: s.append(C(cx, cy, 0.45, 0.08)) # the boss else: g = pop_scale(t, (hit + 1) / 23, 0.12, 1.3) s.append(NUM(cx, cy, 1.4 * g, rot=shake)) a = [0.25, 0.4, 0.6, 0.85, 1.0, 1.05, 0.9, 0.45, -0.25, -0.15, 0.05, 0.25, 0.4][min(12, i)] # the mallet if i > 12: a = 0.45 px, py, ln = gx + 4.6, -0.8, 3.4 base = math.atan2(cy + 0.4 - py, cx + 1.3 - px) ma = base + a hx, hy = px + ln * math.cos(ma), py + ln * math.sin(ma) s.append(K("blue")) s.append(L([(px, py), (hx, hy)], 0.14)) s.append(K("red")) s.append(C(hx, hy, 0.38)) if i in (hit, hit + 1): s.append(K("yellow")) s += rays(cx + 1.2, cy + 0.4, 0.5, 1.2, 6, math.pi * 0.7, 0.1) return s def hw(y, cy, r): """The balloon envelope's half-width at height y.""" mouth = cy + 1.45 * r knee = cy + 0.55 * r if y <= knee: return math.sqrt(max(0.0, r * r - (y - cy) ** 2)) w0 = math.sqrt(r * r - (knee - cy) ** 2) return w0 + (0.4 * r - w0) * (y - knee) / (mouth - knee) def hotairballoon(i, t): """A striped hot-air balloon swells up out of the box and climbs past the clouds, burner roaring, the number emblazoned on its band.""" s = [] r = 2.2 cx = 0.6 + 0.15 * math.sin(i * 0.4) cy = -2.4 - 3.2 * ease_out(clamp(t * 1.6)) s.append(K("blue")) # clouds drifting down past it for k, (x, y0) in enumerate(((-2.4, -8.0), (3.9, -10.5), (-2.9, -12.5), (4.1, -6.0))): y = y0 + t * 9.0 if -9.5 < y < -0.5: for m in range(3): s.append(C(x + (m - 1) * 0.42, y - 0.15 * (m == 1), 0.3 + 0.1 * (m == 1), 0.06)) top, mouth = cy - r, cy + 1.45 * r ys = [top + (mouth - top) * m / 16 for m in range(17)] outline = [(cx + hw(y, cy, r), y) for y in ys] + [(cx - hw(y, cy, r), y) for y in reversed(ys)] s.append(K("red")) s.append(P(outline)) s.append(K("yellow")) # the gores for f0, f1 in ((-0.75, -0.42), (-0.12, 0.12), (0.42, 0.75)): pts = [(cx + f0 * hw(y, cy, r), y) for y in ys] + [(cx + f1 * hw(y, cy, r), y) for y in reversed(ys)] s.append(P(pts, 0, 0.03)) s.append(K("blue")) # the band bys = [cy - 0.8 + 1.6 * m / 4 for m in range(5)] s.append(P([(cx + hw(y, cy, r) + 0.03, y) for y in bys] + [(cx - hw(y, cy, r) - 0.03, y) for y in reversed(bys)], 0, 0.03)) s.append(K("yellow")) s.append(NUM(cx, cy, 1.25, rot=0.04 * math.sin(i * 0.4))) bx0, bx1 = cx - 0.5, cx + 0.5 # ropes and basket by = mouth + 1.0 s.append(K("blue")) s.append(L([(cx - 0.4 * r, mouth), (bx0, by)], 0.05)) s.append(L([(cx + 0.4 * r, mouth), (bx1, by)], 0.05)) burn = i in (1, 2, 3, 9, 10, 16, 17, 18) if burn: s.append(K("yellow")) fh = 1.3 if i in (2, 10, 17) else 0.9 s.append(P([(cx - 0.28, by - 0.1), (cx, by - 0.1 - fh), (cx + 0.28, by - 0.1), (cx, by + 0.05)])) s.append(K("red")) s.append(P([(cx - 0.12, by - 0.1), (cx, by - 0.1 - fh * 0.55), (cx + 0.12, by - 0.1)])) s.append(K("red")) s.append(P([(bx0, by), (bx1, by), (bx1 - 0.08, by + 0.6), (bx0 + 0.08, by + 0.6)])) s.append(K("yellow")) s.append(L([(bx0 + 0.04, by + 0.2), (bx1 - 0.04, by + 0.2)], 0.05)) return s def lunarlander(i, t): """A lunar lander rides its rocket flame down onto a moonscape by the box, touches down in a puff of dust, and the number springs up under the Earth.""" s = [] s.append(K("yellow")) # far stars for k, (x, y) in enumerate(((-3.2, -5.2), (4.4, -7.3), (3.8, -3.2), (-1.0, -8.3), (2.2, -8.6), (-3.4, -2.6))): if (i + k) % 4: s.append(P(star(x, y, 0.22 if (i + k) % 3 else 0.14, 0.07, 4, 0))) s.append(K("blue")) # the Earth s.append(C(-2.6, -7.1, 0.75)) s.append(K("red")) s.append(P([(-2.95, -7.4), (-2.5, -7.55), (-2.3, -7.1), (-2.7, -6.8)])) s.append(K("yellow")) # the moonscape ground = [(-3.8, 0.4), (-3.8, -0.55), (-2.6, -0.7), (-1.3, -0.55), (0.6, -0.62), (2.4, -0.52), (3.6, -0.75), (5.0, -0.55), (5.0, 0.4)] s.append(P(ground)) s.append(K("blue")) s.append(P(oval(-2.4, -0.3, 0.45, 0.12), 0.05)) s.append(P(oval(3.7, -0.35, 0.35, 0.1), 0.05)) lx = 0.6 yb = lerp(-8.4, -0.62, ease_out(clamp(i / 11))) # the footpads' level if i >= 11: yb = -0.62 + (0.12 if i == 11 else 0.0) z = 1.35 # the lander's size if i < 11: # the descent flame s.append(K("red")) fh = 0.9 + 0.4 * (i % 2) s.append(P([(lx - z * 0.25, yb - z * 0.75), (lx + z * 0.25, yb - z * 0.75), (lx, yb - z * 0.75 + z * fh)])) s.append(K("yellow")) s.append(P([(lx - z * 0.12, yb - z * 0.75), (lx + z * 0.12, yb - z * 0.75), (lx, yb - z * 0.75 + z * fh * 0.6)])) s.append(K("blue")) # legs for side in (-1, 1): s.append(L([(lx + z * side * 0.55, yb - z * 1.1), (lx + z * side * 1.05, yb - z * 0.05)], 0.09)) s.append(L([(lx + z * side * 1.25, yb), (lx + z * side * 0.85, yb)], 0.1)) s.append(K("yellow")) # the gold descent stage s.append(P([(lx - z * 0.75, yb - z * 1.55), (lx + z * 0.75, yb - z * 1.55), (lx + z * 0.85, yb - z * 1.3), (lx + z * 0.75, yb - z * 0.85), (lx - z * 0.75, yb - z * 0.85), (lx - z * 0.85, yb - z * 1.3)])) s.append(K("blue")) # the ascent stage s.append(P([(lx - z * 0.6, yb - z * 1.55), (lx + z * 0.55, yb - z * 1.55), (lx + z * 0.7, yb - z * 2.1), (lx + z * 0.3, yb - z * 2.5), (lx - z * 0.4, yb - z * 2.5), (lx - z * 0.65, yb - z * 2.1)])) s.append(L([(lx + z * 0.3, yb - z * 2.5), (lx + z * 0.5, yb - z * 3.0)], 0.05)) # its antenna s.append(K("yellow")) s.append(P([(lx - z * 0.35, yb - z * 2.2), (lx - z * 0.05, yb - z * 2.2), (lx - z * 0.2, yb - z * 1.9)])) if 11 <= i <= 17: # the dust k = i - 11 s.append(K("red")) for side in (-1, 1): for m in range(3): x = lx + side * (1.4 + k * 0.35 + m * 0.4) s.append(C(x, -0.75 - 0.15 * m - k * 0.04, 0.18 + 0.05 * k, 0.06)) if i >= 13: g = pop_scale(t, 13 / 23, 0.13, 1.35) y = -5.0 - 0.9 * ease_out(clamp((i - 13) / 5)) s.append(K("red")) s.append(NUM(lx + 0.3, y, 1.9 * g, rot=0.08 * math.sin(i * 0.7))) if i % 2: s.append(K("yellow")) s += rays(lx + 0.3, y, 2.6, 3.0, 10, i * 0.1, 0.08) return s def meteorshower(i, t): """Meteors begin to streak down the night sky above the box, then pour, and one great fireball blazes in and bursts into the number.""" s = [] nx, ny = 0.7, -4.6 s.append(K("blue")) for k, (x, y) in enumerate(((-3.0, -8.4), (4.5, -8.0), (-3.4, -1.6), (4.6, -1.2), (-0.8, -9.3), (2.6, -9.6))): s.append(C(x, y, 0.07 + 0.04 * ((i + k) % 2))) s.append(K("yellow")) for k in range(20): # the shower, thickening st = k * 0.95 - (k % 3) * 0.6 u = (i - st) / 4.0 if not 0 <= u <= 1: continue x0 = -2.0 + ((k * 2.3) % 7.5) y0 = -9.8 + (k * 1.7) % 3.0 hx, hy = x0 - 3.2 * u, y0 + 6.5 * u tx, ty = hx + 0.55 * (1.2 + u), hy - 1.1 * (1.2 + u) if i >= 12 and any(abs(px - nx) < 2.9 and abs(py - ny) < 1.6 for px, py in ((hx, hy), (tx, ty), ((hx + tx) / 2, (hy + ty) / 2))): continue if hy > -0.4: continue s.append(L([(tx, ty), (hx, hy)], 0.09)) s.append(C(hx, hy, 0.12)) if 6 <= i < 12: # the fireball u = (i - 6) / 6 hx, hy = lerp(5.2, nx, u), lerp(-10.0, ny, u) s.append(K("red")) s.append(P([(hx - 0.4, hy - 0.2), (hx + 2.0, hy - 3.6), (hx + 0.35, hy + 0.25)])) s.append(K("yellow")) s.append(C(hx, hy, 0.45 + 0.1 * (i % 2))) if i in (12, 13): s.append(K("yellow")) s.append(P(star(nx, ny, 3.6 - (i - 12) * 0.9, 1.3, 12, i))) if i >= 12: g = pop_scale(t, 12 / 23, 0.12, 1.35) s.append(K("red")) s.append(NUM(nx, ny, 2.0 * g, rot=0.06 * math.sin(i))) if i >= 14: s.append(K("yellow")) for k in range(7): a = k * 2 * math.pi / 7 + i * 0.12 if (i + k) % 3: s.append(P(star(nx + 3.0 * math.cos(a), ny + 1.9 * math.sin(a), 0.26, 0.09, 4, a))) return s ANIMS = [ (curtaincall, "red", "ovation"), (marquee, "yellow", "showtime"), (filmleader, "blue", "projector"), (grandpiano, "blue", "arpeggio"), (gong, "yellow", "bwong"), (hotairballoon, "red", "burner"), (lunarlander, "blue", "quindar"), (meteorshower, "yellow", "starfall"), ]