"""Streak level 2: a 42-day streak. Eight 2-second celebrations, each showing the streak number. Fairground, sport, party food: busier than level 1, more going on at once and a bigger finish. Sounds: level2_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 confetti(cx, cy, i, i0, n=14, spread=3.2, seed=0): """Paper bits bursting from (cx, cy) at frame i0, then fluttering down in all three colours.""" out = [] k = i - i0 if k < 0: return out for m in range(n): a = -math.pi / 2 + ((m * 0.618 + seed * 0.37) % 1.0 - 0.5) * 2.6 v = spread * (0.55 + 0.45 * ((m * 0.37 + seed) % 1.0)) u = 1 - math.exp(-k * 0.35) x = cx + v * math.cos(a) * u * 1.3 + 0.2 * math.sin(k * 0.9 + m) y = cy + v * math.sin(a) * u + 0.035 * k * k out.append(K(["red", "blue", "yellow"][m % 3])) out.append(P(rotate([(x - 0.17, y - 0.1), (x + 0.17, y - 0.1), (x + 0.17, y + 0.1), (x - 0.17, y + 0.1)], k * 0.7 + m, x, y), 0, 0.02)) return out def shootinggallery(i, t): """A fairground shooting gallery opens over the box: tin ducks glide along, ping, ping, PING, three go down, and the prize board flips up with the number as the bulbs chase.""" s = [] x0, x1, top, bot = -3.3, 4.7, -6.6, -0.5 s.append(K("blue")) s.append(P([(x0, bot), (x0 + 0.3, bot), (x0 + 0.3, top), (x0, top)])) # posts s.append(P([(x1 - 0.3, bot), (x1, bot), (x1, top), (x1 - 0.3, top)])) s.append(P([(x0 - 0.2, bot), (x1 + 0.2, bot), (x1 + 0.2, bot - 0.45), (x0 - 0.2, bot - 0.45)])) # the counter n = 8 # the striped awning, scalloped wd = (x1 - x0 + 0.6) / n for k in range(n): ax = x0 - 0.3 + k * wd s.append(K("red" if k % 2 == 0 else "yellow")) s.append(P([(ax, top - 0.7), (ax + wd, top - 0.7), (ax + wd, top + 0.1), (ax + wd * 0.5, top + 0.45), (ax, top + 0.1)], 0, 0.03)) for k in range(9): # bulbs under the awning on = i >= 14 and (k + i) % 2 == 0 s.append(K("yellow" if on else "blue")) s.append(C(x0 + 0.2 + k * (x1 - x0 - 0.4) / 8, top + 0.75, 0.17 if on else 0.1)) ry = -2.0 # the ducks' rail s.append(K("blue")) s.append(L([(x0 + 0.3, ry + 0.1), (x1 - 0.3, ry + 0.1)], 0.08)) hits = {1: 4, 3: 8, 2: 12} span = x1 - x0 - 1.0 for k in range(4): x = x0 + 0.5 + ((k * span / 4 + i * 0.13) % span) h = hits.get(k) down = h is not None and i >= h s.append(K("yellow")) if not down: body = [(x - 0.55, ry), (x + 0.45, ry), (x + 0.6, ry - 0.35), (x + 0.2, ry - 0.55), (x - 0.4, ry - 0.5), (x - 0.7, ry - 0.75)] s.append(P(body, 0, 0.03)) s.append(C(x + 0.3, ry - 0.85, 0.27, 0, 0.03)) s.append(K("red")) s.append(P([(x + 0.52, ry - 0.92), (x + 0.85, ry - 0.82), (x + 0.52, ry - 0.75)], 0, 0.02)) s.append(K("blue")) s.append(C(x + 0.36, ry - 0.9, 0.06, 0, 0.01)) else: k2 = i - h # knocked flat, swinging on its hinge sw = 0.25 * math.exp(-k2 * 0.4) * math.sin(k2 * 2) s.append(P(rotate([(x - 0.6, ry), (x + 0.6, ry), (x + 0.6, ry + 0.25), (x - 0.6, ry + 0.25)], sw, x, ry), 0, 0.03)) if k2 < 2: s.append(K("red")) s.append(P(star(x + 0.3, ry - 0.8, 0.9 - 0.3 * k2, 0.35, 8, i))) if h is not None and h - 2 <= i < h: # the sights on it s.append(K("red")) s.append(C(x + 0.1, ry - 0.5, 0.75, 0.07)) s.append(L([(x + 0.1, ry - 1.4), (x + 0.1, ry + 0.4)], 0.05)) s.append(L([(x - 0.8, ry - 0.5), (x + 1.0, ry - 0.5)], 0.05)) if i >= 13: # the prize board flips up on its hinge f = min(1.0, (i - 13) / 2) cx, cy, bw, bh = 0.7, -4.2, 2.3, 1.15 sc = f if i < 15 else (1.08 if i == 15 else 1.0) s.append(K("red")) s.append(P([(cx - bw, cy + bh), (cx + bw, cy + bh), (cx + bw, cy + bh - 2 * bh * sc), (cx - bw, cy + bh - 2 * bh * sc)], 0, 0.03)) s.append(K("yellow")) s.append(P([(cx - bw, cy + bh), (cx + bw, cy + bh), (cx + bw, cy + bh - 2 * bh * sc), (cx - bw, cy + bh - 2 * bh * sc)], 0.1, 0.03)) if i >= 15: s.append(NUM(cx, cy + 0.03, 1.55, rot=0.05 * math.sin(i * 1.3))) if 15 <= i <= 20 and i % 2: s += rays(cx, cy, 2.7, 3.2, 12, 0.1, 0.08) s += confetti(cx, cy - 1.6, i, 15, 12, 2.4, 1) return s def pinball(i, t): """A pinball table stands over the box: the ball is plunged, cracks off the bumpers, the flipper sends it back up, and MULTIBALL: three balls ricochet as the number lights up in the middle.""" s = [] x0, x1, top, bot = -2.4, 3.4, -7.8, 0.3 s.append(K("blue")) s.append(L([(x0, bot), (x0, top + 1.0), (x0 + 0.6, top + 0.2), (x0 + 1.6, top), (x1 - 1.6, top), (x1 - 0.6, top + 0.2), (x1, top + 1.0), (x1, bot)], 0.16, 0.03)) s.append(L([(x1 - 0.6, bot), (x1 - 0.6, top + 2.0)], 0.07, 0.03)) # the plunger lane bumpers = [(-0.9, -6.1), (1.6, -6.1), (0.35, -4.9)] hits = {5: 0, 7: 1, 9: 2} multi = i >= 12 for k, (bx, by) in enumerate(bumpers): lit = hits.get(i) == k or hits.get(i - 1) == k or (multi and (i + k) % 3 == 0) r = 0.65 if lit else 0.52 s.append(K("yellow" if lit else "red")) s.append(P(ring(bx, by, r, 10, 0, 0.03))) s.append(K("red" if lit else "yellow")) s.append(C(bx, by, r * 0.45)) if lit: s.append(K("yellow")) s += rays(bx, by, r + 0.15, r + 0.55, 8, i * 0.3, 0.07) # flippers lf = 1 if i in (11, 12) else 0 rf = 1 if i in (14, 17, 20) else 0 s.append(K("yellow")) s.append(L([(-1.6, -0.9), (-0.3, -0.5 - 0.9 * lf)], 0.28, 0.03)) s.append(L([(2.4, -0.9), (1.1, -0.5 - 0.9 * rf)], 0.28, 0.03)) s.append(K("blue")) pull = [0.0, 0.3, 0.6, 0.0][i] if i < 4 else 0.0 s.append(P([(x1 - 0.48, bot - 0.1 + pull), (x1 - 0.12, bot - 0.1 + pull), (x1 - 0.12, bot - 0.9 + pull), (x1 - 0.48, bot - 0.9 + pull)])) path = {0: (3.1, -1.3), 1: (3.1, -1.0), 2: (3.1, -0.7), 3: (3.1, -3.6), 4: (2.6, -7.2), 5: (-0.1, -6.75), 6: (0.4, -7.0), 7: (0.95, -6.45), 8: (1.4, -5.2), 9: (0.9, -4.25), 10: (-0.2, -2.3), 11: (-0.55, -1.0)} balls = [] if i in path: balls.append(path[i]) if multi: # three balls bouncing about the top for m in range(3): ph = (i - 12) * (0.9 + 0.17 * m) + m * 2.1 balls.append((0.5 + 2.2 * math.sin(ph * 1.3 + m), -5.6 + 1.3 * math.sin(ph * 2.1 + m * 0.7))) s.append(K("blue")) for bx, by in balls: s.append(C(bx, by, 0.3)) if i in (4, 10): prev = path[i - 1] s.append(L([prev, path[i]], 0.06)) if i >= 9: # the number lights up mid-table g = pop_scale(t, 9 / 23, 0.12, 1.3) s.append(K("blue" if i % 2 else "red")) s.append(P(star(0.5, -2.7, 2.6 * min(1.0, g), 2.0 * min(1.0, g), 16, i * 0.1), 0, 0.03)) s.append(K("yellow")) s.append(NUM(0.5, -2.7, 1.55 * g, rot=0.05 * math.sin(i * 1.7))) return s def candyfloss(i, t): """A candyfloss tub whirls on the box; the stick twirls and a great pink cloud spins up on it, then it's held up high, huge and fluffy, with the number in the floss and sugar sparkling.""" s = [] s.append(K("blue")) s.append(P([(-2.3, -1.6), (2.3, -1.6), (1.7, 0.2), (-1.7, 0.2)])) # the tub s.append(K("yellow")) s.append(L([(-2.3, -1.6), (2.3, -1.6)], 0.14)) for k in range(5): # whirl marks on the tub x = -1.6 + k * 0.8 + ((i * 0.27) % 0.8) s.append(L([(x, -1.1), (x + 0.35, -0.95)], 0.07)) spin = i < 13 if spin: r = 0.35 + 1.4 * ease_out(i / 12) sx = 0.45 * math.sin(i * 1.4) top = -2.2 - r * 0.8 s.append(K("yellow")) s.append(L([(sx * 0.4, 0.0), (sx, top)], 0.12)) s.append(K("red")) s.append(P(ring(sx, top, r, 14, i * 0.5, 0.08 + 0.04 * r))) for k in range(5): # strands whipping off the tub a = i * 1.1 + k * 1.26 pts = [(1.4 * math.cos(a + m * 0.35) * (1 - m * 0.12), -1.75 - m * 0.25 - 0.18 * math.sin(a + m * 0.35)) for m in range(5)] s.append(L(pts, 0.05)) else: k = i - 13 u = ease_out(min(1.0, k / 3)) cx, cy = 0.6, -2.9 - 1.6 * u rr = 2.2 + 0.25 * u + (0.25 if k == 1 else 0.0) s.append(K("yellow")) s.append(L([(cx - 0.2, cy + 3.6), (cx, cy)], 0.14)) s.append(K("red")) puffs = [(math.cos(a), math.sin(a)) for a in [m * 2 * math.pi / 9 + 0.3 for m in range(9)]] for m, (px, py) in enumerate(puffs): # a cloud of puffs round a big middle s.append(C(cx + px * rr * 0.62, cy + py * rr * 0.5, rr * 0.42 + 0.06 * math.sin(i + m))) s.append(P(oval(cx, cy, rr * 0.95, rr * 0.72, 14))) g = pop_scale(t, 13 / 23, 0.14, 1.25) s.append(K("yellow")) s.append(NUM(cx, cy + 0.05, 1.6 * g, rot=0.07 * math.sin(i * 1.1))) for m in range(8): # sugar sparkles a = m * 0.785 + i * 0.35 d = rr + 0.6 + 0.3 * ((m + i) % 2) s.append(K(["blue", "yellow"][m % 2])) s.append(P(star(cx + d * 1.05 * math.cos(a), cy + d * 0.85 * math.sin(a), 0.3, 0.11, 4, i * 0.4))) return s def penalty(i, t): """A penalty kick: the ball sits on the spot by the box, the keeper dives the wrong way, the shot rockets into the top corner, the net bulges, and the number bursts out with confetti.""" s = [] gx0, gx1, gt, gb = -2.0, 4.6, -5.4, -0.3 # the goal bulge = 0.0 if 9 <= i <= 14: bulge = [0.9, 1.2, 0.8, 0.5, 0.3, 0.15][i - 9] cxn, cyn = gx1 - 1.3, gt + 1.1 # where the shot goes in s.append(K("blue")) # the net, pushed out round the ball for k in range(9): x = gx0 + k * (gx1 - gx0) / 8 pts = [] for m in range(7): y = gt + m * (gb - gt) / 6 d = math.hypot(x - cxn, y - cyn) push = bulge * math.exp(-d * d / 2.5) pts.append((x + push * 0.4, y - push * 0.5)) s.append(L(pts, 0.04, 0.02)) for m in range(7): y = gt + m * (gb - gt) / 6 pts = [] for k in range(9): x = gx0 + k * (gx1 - gx0) / 8 d = math.hypot(x - cxn, y - cyn) push = bulge * math.exp(-d * d / 2.5) pts.append((x + push * 0.4, y - push * 0.5)) s.append(L(pts, 0.04, 0.02)) s.append(K("red")) s.append(L([(gx0, gb), (gx0, gt), (gx1, gt), (gx1, gb)], 0.22, 0.03)) # the posts and bar # the keeper: stands, then dives left if i < 6: kx, ky, ka = 1.3 + 0.12 * math.sin(i * 1.8), -1.8, 0.0 else: u = ease_out(min(1.0, (i - 6) / 4)) kx, ky, ka = 1.3 - 2.0 * u, -1.8 - 0.9 * math.sin(u * math.pi) + 0.6 * u, -1.35 * u s.append(K("yellow")) body = rotate([(kx - 0.35, ky + 0.6), (kx + 0.35, ky + 0.6), (kx + 0.3, ky - 0.7), (kx - 0.3, ky - 0.7)], ka, kx, ky) s.append(P(body)) s.append(C(*rotate([(kx, ky - 1.05)], ka, kx, ky)[0], 0.32)) arms = rotate([(kx - 1.0, ky - 1.3), (kx - 0.3, ky - 0.55), (kx + 0.3, ky - 0.55), (kx + 1.0, ky - 1.3)], ka, kx, ky) s.append(L(arms, 0.16)) s.append(L(rotate([(kx - 0.45, ky + 1.5), (kx - 0.2, ky + 0.6), (kx + 0.2, ky + 0.6), (kx + 0.45, ky + 1.5)], ka, kx, ky), 0.16)) s.append(K("red")) for hx, hy in (arms[0], arms[-1]): s.append(C(hx, hy, 0.17)) # the ball if i < 5: bx, by = -0.2, -0.75 elif i <= 9: u = (i - 4) / 5 bx, by = -0.2 + (cxn + 0.3 - -0.2) * u, -0.75 + (cyn - 0.5 - -0.75) * u - 1.0 * u * (1 - u) else: k = i - 10 bx, by = cxn + 0.4 - 0.08 * k, min(gb - 0.4, cyn - 0.5 + 0.12 * k * k) s.append(K("blue")) s.append(C(bx, by, 0.4)) s.append(K("yellow")) s.append(P(ring(bx, by, 0.16, 5, i, 0.01))) if 5 <= i <= 8: s.append(K("blue")) for q in range(3): s.append(L([(bx - 0.6 - 0.5 * q, by + 0.3 - 0.25 * q + 0.4), (bx - 1.1 - 0.5 * q, by + 0.55 - 0.25 * q + 0.4)], 0.06)) if i == 4: # the kick s.append(K("red")) s += rays(-0.2, -0.75, 0.55, 1.0, 6, math.pi * 0.6, 0.08) if i >= 10: g = pop_scale(t, 10 / 23, 0.14, 1.35) y = -6.2 - 0.5 * ease_out(min(1.0, (i - 10) / 4)) s += confetti(1.3, -5.6, i, 10, 16, 3.4, 2) s.append(K("red")) s.append(NUM(1.3, y, 1.9 * g, rot=-0.08 + 0.08 * math.sin(i * 1.2))) if i % 2 == 0 and i < 20: s.append(K("yellow")) s += rays(1.3, y, 2.4, 2.9, 12, 0.2, 0.09) return s def bumpercars(i, t): """Two dodgem cars zoom in from either side, poles sparking on the ceiling grid, crash head-on over the box, bounce apart, and the number jumps up out of the bump in a shower of sparks.""" s = [] gy = -6.4 # the ceiling grid s.append(K("blue")) s.append(L([(-4.2, gy), (5.6, gy)], 0.08)) for k in range(10): x = -4.0 + k * 1.05 s.append(L([(x, gy), (x + 0.5, gy - 0.4), (x + 1.05, gy)], 0.05)) hit = 8 if i < hit: d = 2.4 * (1 - ease_out(i / hit)) lx, rx = -1.15 - d, 2.35 + d tilt = 0.0 else: k = i - hit d = 1.5 * (1 - math.exp(-k * 0.45)) lx, rx = -1.15 - d, 2.35 + d tilt = 0.18 * math.exp(-k * 0.4) * math.sin(k * 1.8) for side, x, col in ((-1, lx, "red"), (1, rx, "blue")): y = -0.9 + 0.08 * math.sin(i * 2.0 + side) tl = -side * tilt def at(pts): return rotate(pts, tl, x, y) s.append(K(col)) s.append(P(at([(x - 1.5, y), (x + 1.5, y), (x + 1.6, y - 0.5), (x + 1.2, y - 0.85), (x - 1.2, y - 0.85), (x - 1.6, y - 0.5)]))) bx = x - side * 0.85 # the seat back, away from the crash s.append(P(at([(bx - 0.35, y - 0.8), (bx + 0.35, y - 0.8), (bx + 0.3, y - 2.0), (bx - 0.3, y - 2.0)]))) s.append(K("yellow")) s.append(L(at([(x - 1.75, y + 0.05), (x + 1.75, y + 0.05)]), 0.34)) # the rubber bumper s.append(K("blue" if col == "red" else "red")) hx, hy = at([(x - side * 0.15, y - 1.7)])[0] s.append(C(hx, hy, 0.36)) # the driver s.append(L(at([(x - side * 0.15, y - 1.35), (x + side * 0.6, y - 1.15)]), 0.14)) s.append(K("yellow")) s.append(L(at([(x + side * 0.75, y - 0.85), (x + side * 0.65, y - 1.2)]), 0.08)) s.append(C(*at([(x + side * 0.62, y - 1.25)])[0], 0.22, 0.08)) px, py = at([(x - side * 1.35, y - 0.85)])[0] s.append(K(col)) s.append(L([(px, py), (px - 0.2 * side, gy)], 0.08)) # the pole if (i + (side > 0)) % 3 == 0 or i == hit: s.append(K("yellow")) s.append(P(star(px - 0.2 * side, gy + 0.05, 0.6, 0.22, 6, i))) if i in (hit, hit + 1): s.append(K("yellow")) s.append(P(star(0.6, -1.0, 2.0 - 0.5 * (i - hit), 0.8, 11, i))) if i >= hit: g = pop_scale(t, hit / 23, 0.14, 1.35) k = i - hit y = -2.9 - 1.6 * ease_out(min(1.0, k / 4)) + (0.0 if k < 6 else 0.12 * math.sin(k * 1.4)) s.append(K("red")) s.append(NUM(0.6, y, 1.85 * g, rot=0.12 * math.sin(i * 1.3))) s.append(K("yellow")) for m in range(10): # sparks fountain from the crash a = -math.pi / 2 + (m - 4.5) * 0.32 u = (k + (m % 3) * 0.7) * 0.5 if u < 4.5: sx, sy = 0.6 + u * 1.25 * math.cos(a), -1.2 + u * 1.25 * math.sin(a) + 0.12 * u * u s.append(L([(sx, sy), (sx - 0.3 * math.cos(a), sy - 0.3 * math.sin(a))], 0.08)) return s def lionhoop(i, t): """A circus lion crouches on its drum, bounds through a flaming hoop to the other drum and roars, and the number blazes in the middle of the ring of fire.""" s = [] hx, hy, hr = 0.9, -3.6, 1.65 # the hoop flare = 1.0 + (0.35 if 13 <= i <= 16 else 0.0) for side, dx in ((-1, -3.0), (1, 4.8)): # the two drums s.append(K("red")) s.append(P([(dx - 0.8, 0.3), (dx + 0.8, 0.3), (dx + 0.8, -1.0), (dx - 0.8, -1.0)])) s.append(K("yellow")) s.append(L([(dx - 0.8, -0.6), (dx - 0.4, -0.1), (dx, -0.6), (dx + 0.4, -0.1), (dx + 0.8, -0.6)], 0.09)) s.append(P(oval(dx, -1.0, 0.8, 0.2, 10))) s.append(K("blue")) s.append(L([(hx, hy + hr), (hx, 0.3)], 0.14)) # the hoop's stand s.append(L([(hx - 0.7, 0.3), (hx + 0.7, 0.3)], 0.14)) behind = [] front = [] for k in range(14): # flames all round a = k * 2 * math.pi / 14 + i * 0.15 fl = (0.45 + 0.25 * ((k + i) % 3) / 2) * flare base = [(hx + (hr - 0.05) * math.cos(a - 0.17), hy + (hr - 0.05) * math.sin(a - 0.17)), (hx + (hr - 0.05) * math.cos(a + 0.17), hy + (hr - 0.05) * math.sin(a + 0.17))] tip = (hx + (hr + fl) * math.cos(a + 0.12), hy + (hr + fl) * math.sin(a + 0.12) - 0.15) (behind if math.sin(a) < 0 else front).append((k, base, tip)) for k, base, tip in behind + front: s.append(K("red" if k % 2 else "yellow")) s.append(P([base[0], tip, base[1]], 0, 0.03)) s.append(K("blue")) s.append(C(hx, hy, hr, 0.18)) # the lion: crouch, leap through, land and rear up if i < 4: x, y, ang, crouch = -3.0, -1.0, 0.0, 0.15 * i leap = False elif i <= 11: u = (i - 4) / 7 x = -3.0 + (4.8 + 3.0) * u y = -1.0 - 5.25 * u * (1 - u) ang = -0.5 * (1 - 2 * u) crouch, leap = 0.0, True else: x, y, ang, crouch, leap = 4.8, -1.0, (-0.35 if 13 <= i <= 17 else 0.0), 0.0, False z = 1.15 def at(px, py): return rotate([(x + px * z, y + py * z)], ang, x, y)[0] s.append(K("yellow")) s.append(P([at(px, py) for px, py in oval(0, -0.75 + crouch, 1.0, 0.45, 12)])) # body legs = ([(-0.6, -0.5), (-1.3, -0.3)], [(-0.3, -0.5), (-1.0, -0.2)], [(0.5, -0.6), (1.3, -0.8)], [(0.7, -0.6), (1.5, -0.6)]) if leap \ else ([(-0.7, -0.5), (-0.75, 0.0)], [(-0.4, -0.5), (-0.4, 0.0)], [(0.5, -0.5), (0.5, 0.0)], [(0.75, -0.5), (0.8, 0.0)]) for a, b in legs: s.append(L([at(*a), at(*b)], 0.2)) tw = 0.3 * math.sin(i * 1.2) s.append(L([at(-0.95, -0.85 + crouch), at(-1.5, -1.2 + tw), at(-1.7, -1.6 + tw)], 0.09)) # tail s.append(K("red")) s.append(C(*at(-1.75, -1.7 + tw), 0.18)) hx2, hy2 = 1.05, -1.25 + crouch s.append(P([at(hx2 + 0.62 * math.cos(a), hy2 + 0.62 * math.sin(a)) if m % 2 == 0 else at(hx2 + 0.4 * math.cos(a), hy2 + 0.4 * math.sin(a)) for m, a in enumerate([q * math.pi / 8 for q in range(16)])])) # mane s.append(K("yellow")) s.append(C(*at(hx2 + 0.05, hy2), 0.34)) s.append(K("blue")) s.append(C(*at(hx2 + 0.15, hy2 - 0.1), 0.06)) if 13 <= i <= 18: # the roar s.append(K("red")) s.append(P([at(hx2 + 0.2, hy2 + 0.05), at(hx2 + 0.45, hy2 + 0.0), at(hx2 + 0.4, hy2 + 0.25)])) s.append(K("blue")) s += [L([at(hx2 + 0.8 + 0.3 * q, hy2 - 0.4 + 0.4 * q - 0.2), at(hx2 + 1.2 + 0.3 * q, hy2 - 0.55 + 0.4 * q - 0.2)], 0.07) for q in range(3)] if i >= 9: # the number, blazing in the hoop g = pop_scale(t, 9 / 23, 0.14, 1.25) s.append(K("red")) s.append(NUM(hx, hy + 0.05, 1.3 * g, rot=0.06 * math.sin(i * 1.5))) return s def tiercake(i, t): """A party cake builds itself on the box tier by tier, bump, bump, bump, gets its icing and sparkler candles, which light up fizzing, the number piped big across the bottom tier.""" s = [] tiers = [(2.7, 1.75, 0), (1.9, 1.3, 3), (1.15, 1.05, 6)] # half width, height, frame it lands y = 0.3 tops = [] for k, (w, h, land) in enumerate(tiers): if i < land: break f = i - land drop = [3.0, 1.2, 0.0, -0.25, 0.0][f] if f < 5 else 0.0 sq = 0.86 if f == 2 else 1.0 by = y + drop * 0 - 0.0 yy = by - (drop if f < 2 else 0.0) s.append(K("red" if k != 1 else "blue")) s.append(P([(-w, yy), (w, yy), (w, yy - h * sq), (-w, yy - h * sq)], 0, 0.03)) s.append(K("yellow")) # the icing drips drips = [(-w + (2 * w) * q / 8, yy - h * sq + (0.32 if q % 2 else 0.12)) for q in range(9)] s.append(P([(-w - 0.05, yy - h * sq - 0.1), (w + 0.05, yy - h * sq - 0.1)] + list(reversed(drips)), 0, 0.03)) if k == 0: s.append(K("yellow")) s.append(L([(-w, yy - 0.15), (w, yy - 0.15)], 0.1)) tops.append(yy - h * sq) y = yy - h * sq if len(tops) == 3: top = tops[2] lit = i >= 12 for m in range(3): # the sparkler candles cx = -0.6 + m * 0.6 s.append(K(["blue", "red", "blue"][m])) s.append(P([(cx - 0.11, top), (cx + 0.11, top), (cx + 0.11, top - 0.85), (cx - 0.11, top - 0.85)])) if lit: fz = 0.75 + 0.25 * ((i + m) % 2) s.append(K("yellow")) s.append(P(star(cx, top - 1.1, fz * 0.7, 0.18, 7, i * 0.9 + m))) s.append(K("red")) for q in range(4): a = (i * 1.7 + m * 2 + q * 1.57) % (2 * math.pi) d = 0.8 + 0.6 * ((i + q) % 3) s.append(C(cx + d * math.cos(a), top - 1.1 + d * math.sin(a) * 0.8, 0.06)) if 11 <= i <= 12: s.append(K("yellow")) s.append(P(star(0, top - 1.1, 1.6, 0.6, 10, i))) if i >= 9: # the number piped on the bottom tier g = pop_scale(t, 9 / 23, 0.12, 1.25) s.append(K("yellow")) s.append(NUM(0, 0.3 - 0.9, 1.25 * g, w=0.24 * g, rot=0.03 * math.sin(i))) if i >= 14: s += confetti(0, -5.0, i, 14, 14, 3.4, 3) return s def pancakes(i, t): """A pan by the box flips pancakes, one, two, three, onto a stack; the last flip sends the number spinning sky-high to land on top, and syrup runs down the stack.""" s = [] flips = [0, 4, 8] # each pancake's 4-frame flight starts here nf = 12 # the number's flip tx, ty = 2.4, 0.4 # the plate px, py = -2.3, -1.1 # the pan sh, pw = 0.42, 1.5 # a pancake's thickness, half width s.append(K("blue")) s.append(P([(tx - 2.1, ty), (tx + 2.1, ty), (tx + 1.7, ty - 0.3), (tx - 1.7, ty - 0.3)])) toss = any(f <= i <= f + 1 for f in flips + [nf]) pa = -0.45 if toss else 0.0 # the pan kicks up with each toss pan = [(px - 1.35, py), (px + 1.35, py), (px + 1.15, py + 0.45), (px - 1.15, py + 0.45)] s.append(P(rotate(pan, pa, px + 1.35, py))) s.append(L(rotate([(px - 1.35, py + 0.15), (px - 3.0, py + 0.45)], pa, px + 1.35, py), 0.22)) landed = sum(1 for f in flips if i >= f + 4) base = ty - 0.3 for k in range(landed): # the stack y = base - k * sh - (0.12 if k == landed - 1 and i == flips[k] + 4 else 0.0) s.append(K("yellow")) s.append(P(oval(tx, y - sh / 2, pw - 0.05 * k, sh / 2 + 0.03, 14))) s.append(K("red")) s.append(L([(tx - pw + 0.2, y - sh * 0.35), (tx + pw - 0.2, y - sh * 0.35)], 0.05)) top = base - landed * sh flying = False for n, f in enumerate(flips): # a pancake in flight, flipping over u = (i - f) / 4 if 0 <= u < 1: flying = True x = px + (tx - px) * u yl = base - n * sh - sh / 2 y = (py - 0.3) + (yl - (py - 0.3)) * u - 4.5 * u * (1 - u) ry = 0.2 + 0.6 * abs(math.sin(u * math.pi)) s.append(K("yellow")) s.append(P(oval(x, y, pw - 0.1, ry, 14, 0.3 * math.sin(u * math.pi * 2)))) if not flying and i < nf: # the next one cooking in the pan s.append(K("yellow")) s.append(P(rotate(oval(px, py - 0.1, 1.1, 0.18, 12), pa, px + 1.35, py))) if i >= nf: # the number's own flip u = min(1.0, (i - nf) / 5) h = 1.95 land = top - h / 2 - 0.1 x = px + (tx - px) * u y = (py - 0.6) + (land - (py - 0.6)) * u - 7.5 * u * (1 - u) if i == nf + 6: y += 0.18 s.append(K("red")) s.append(NUM(x, y, (0.9 + 1.05 * u) if u < 1 else h * pop_scale(t, (nf + 5) / 23, 0.08, 1.2) / 1.0, rot=(1 - u) * -2 * math.pi)) if i >= nf + 5: k = i - nf - 5 s.append(K("red")) # syrup running down the stack for q in range(5): dx = tx - pw + 0.2 + q * (2 * pw - 0.4) / 4 ln = min(1.0, k / 4) * (0.35 + 0.35 * (q % 2)) * (landed * sh) / 1.2 s.append(L([(dx, top + 0.05), (dx + 0.02, top + 0.05 + ln)], 0.14)) s.append(L([(tx - pw + 0.1, top + 0.05), (tx + pw - 0.1, top + 0.05)], 0.14)) if k < 5: s.append(K("yellow")) s += rays(tx, land, 2.1, 2.6 + 0.2 * (i % 2), 12, i * 0.2, 0.09) s.append(K("blue")) for q in range(3): # steam sx = tx - 1.0 + q * 1.0 s.append(L([(sx + 0.15 * math.sin(i * 0.7 + q + m), land - 1.3 - m * 0.35) for m in range(4)], 0.06)) return s ANIMS = [ (shootinggallery, "yellow", "plinkety"), (pinball, "red", "bumpers"), (candyfloss, "red", "spindle"), (penalty, "blue", "crowdroar"), (bumpercars, "blue", "dodgem"), (lionhoop, "yellow", "rawr"), (tiercake, "red", "fizzle"), (pancakes, "blue", "sizzle"), ]