"""Streak level 3: a 66-day streak. Eight 2-second celebrations, each showing the streak number. The whole fairground, the big game, the circus top: the biggest of the fun-fair levels, everything moving at once and the number large. Sounds: level3_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 burst(cx, cy, i, i0, r=1.6, n=10, col="yellow"): """A firework: sparks flying out from (cx, cy) from frame i0, drooping and fading after 7 frames.""" k = i - i0 if k < 0 or k > 7: return [] out = [K(col)] rr = r * ease_out(min(1.0, k / 3)) for m in range(n): a = m * 2 * math.pi / n + i0 x, y = cx + rr * math.cos(a), cy + rr * math.sin(a) + 0.04 * k * k if k < 5: out.append(L([(x, y), (cx + rr * 0.6 * math.cos(a), cy + rr * 0.6 * math.sin(a) + 0.03 * k * k)], 0.08)) else: out.append(C(x, y, 0.08)) return out def confetti(cx, cy, i, i0, n=16, spread=3.4, 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.8 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 figure(x, y, ang, arms, legs, head=0.28, w=0.14, z=1.0): """A stick acrobat: hips at (x, y), body 1 long up from them, turned ang; arms and legs are (angle, angle) pairs measured from straight up the body / straight down it.""" out = [] def at(px, py): return rotate([(x + px * z, y + py * z)], ang, x, y)[0] sh = (0, -1.0) out.append(L([at(0, 0), at(*sh)], w * z)) out.append(C(*at(0, -1.0 - head - 0.05), head * z)) for a in arms: out.append(L([at(*sh), at(0.75 * math.sin(a), -1.0 - 0.75 * math.cos(a))], w * 0.8 * z)) for a in legs: out.append(L([at(0, 0), at(0.9 * math.sin(a), 0.9 * math.cos(a))], w * 0.9 * z)) return out def ferriswheel(i, t): """A big wheel rises over the box and turns, its cars swinging and the lights chasing round; fireworks go up behind it and the number lights up in its hub.""" s = [] up = ease_out(min(1.0, i / 5)) cx, cy, r = 0.9, -4.3 + 3.0 * (1 - up), 3.1 rot = i * 0.11 for k in range(4): # fireworks behind s += burst([-2.6, 4.6, -1.8, 4.0][k], [-7.4, -7.6, -3.0, -2.6][k], i, 8 + 3 * k, 1.5, 10, ["yellow", "red", "blue", "yellow"][k]) s.append(K("blue")) s.append(L([(cx - 2.4, 0.4), (cx, cy), (cx + 2.4, 0.4)], 0.2)) # the A-frame legs s.append(L([(cx - 3.0, 0.4), (cx + 3.0, 0.4)], 0.14)) for k in range(8): # spokes a = rot + k * math.pi / 4 s.append(L([(cx, cy), (cx + r * math.cos(a), cy + r * math.sin(a))], 0.06)) s.append(P(ring(cx, cy, r, 24, rot, 0.02), 0.14)) s.append(P(ring(cx, cy, r - 0.35, 24, rot, 0.02), 0.06)) for k in range(8): # the cars, hanging level, swinging a little a = rot + k * math.pi / 4 + math.pi / 8 hx, hy = cx + r * math.cos(a), cy + r * math.sin(a) sw = 0.18 * math.sin(i * 0.9 + k) col = ["red", "yellow", "red", "blue"][k % 4] if k % 4 != 3 else "yellow" s.append(K(col)) car = [(hx - 0.42, hy + 0.3), (hx + 0.42, hy + 0.3), (hx + 0.32, hy + 0.85), (hx - 0.32, hy + 0.85)] s.append(P(rotate(car, sw, hx, hy))) s.append(L(rotate([(hx, hy), (hx, hy + 0.3)], sw, hx, hy), 0.06)) if i >= 6: # the lights chasing round the rim for k in range(16): a = rot + k * math.pi / 8 on = (k + i) % 3 == 0 s.append(K("yellow" if on else "red")) s.append(C(cx + r * math.cos(a), cy + r * math.sin(a), 0.16 if on else 0.08)) if i >= 9: g = pop_scale(t, 9 / 23, 0.14, 1.25) s.append(K("yellow")) s.append(P(ring(cx, cy, 1.95 * min(1.0, g), 18, -rot, 0.03))) s.append(K("red")) s.append(P(ring(cx, cy, 1.95 * min(1.0, g), 18, -rot, 0.03), 0.1)) s.append(NUM(cx, cy + 0.03, 1.55 * g, rot=0.05 * math.sin(i * 1.2))) else: s.append(K("yellow")) s.append(C(cx, cy, 0.4)) return s def coaster_path(): """The roller coaster's track as a list of points: a lift hill, the drop, a loop, the run out.""" pts = [] for k in range(9): # the lift hill u = k / 8 pts.append((-4.4 + 1.8 * u, 0.0 - 6.0 * u)) for k in range(1, 13): # over the top and down u = k / 12 pts.append((-2.6 + 3.6 * u, -6.0 + 6.0 * (1 - math.cos(u * math.pi)) / 2 - 0.4 * math.sin(u * math.pi))) lx, ly, lr = 2.2, -2.3, 2.3 for k in range(1, 25): # the loop a = math.pi / 2 - k * 2 * math.pi / 24 pts.append((lx + lr * math.cos(a) + 0.5 * k / 24, ly + lr * math.sin(a))) for k in range(1, 7): pts.append((lx + 0.5 + k * 0.6, 0.0)) return pts def along(pts, s): """(x, y, angle) at arc length s along pts.""" for k in range(len(pts) - 1): (x0, y0), (x1, y1) = pts[k], pts[k + 1] d = math.hypot(x1 - x0, y1 - y0) if s <= d or k == len(pts) - 2: f = min(1.0, s / d) return x0 + (x1 - x0) * f, y0 + (y1 - y0) * f, math.atan2(y1 - y0, x1 - x0) s -= d return pts[-1][0], pts[-1][1], 0.0 def rollercoaster(i, t): """A roller coaster: the cars clank up the lift hill, plunge, whip round the loop with arms in the air, and the number bursts out in the middle of the loop with fireworks.""" s = [] pts = coaster_path() s.append(K("blue")) for k in range(0, 21, 2): # the trestles x, y = pts[k] if y < -0.3: s.append(L([(x, y), (x, 0.4)], 0.06, 0.02)) s.append(L([(-5.0, 0.4), (6.5, 0.4)], 0.1)) s.append(K("red")) s.append(L(pts, 0.16, 0.02)) lift = 6.3 if i <= 6: d = 1.2 + (lift - 1.2) * i / 6 elif i <= 16: u = (i - 6) / 10 d = lift + 27.0 * (0.55 * u + 0.45 * u * u) else: d = lift + 27.0 + 3.0 * ease_out(min(1.0, (i - 16) / 7)) for c in range(3): # three cars, nose to tail x, y, a = along(pts, max(0.0, d - c * 0.95)) car = rotate([(x - 0.42, y - 0.1), (x + 0.42, y - 0.1), (x + 0.38, y - 0.62), (x - 0.38, y - 0.62)], a, x, y) s.append(K(["yellow", "blue", "yellow"][c])) s.append(P(car)) s.append(K("red")) hx, hy = rotate([(x, y - 0.85)], a, x, y)[0] s.append(C(hx, hy, 0.18)) if 7 <= i <= 17: # arms up! s.append(L(rotate([(x - 0.15, y - 0.75), (x - 0.35, y - 1.35)], a, x, y), 0.07)) s.append(L(rotate([(x + 0.15, y - 0.75), (x + 0.35, y - 1.35)], a, x, y), 0.07)) if 7 <= i <= 12: # speed lines x, y, a = along(pts, d - 2.4) s.append(K("blue")) for q in (-0.35, 0.35): s.append(L(rotate([(x - 0.6, y - 0.35 + q), (x + 0.3, y - 0.35 + q)], a, x, y), 0.05)) for k in range(3): s += burst([-1.2, 5.2, 3.6][k], [-7.0, -6.2, -7.6][k], i, 13 + 2 * k, 1.4, 10, ["yellow", "blue", "red"][k]) if i >= 13: g = pop_scale(t, 13 / 23, 0.12, 1.3) s.append(K("yellow")) s += rays(2.45, -2.3, 2.75, 3.2 + 0.2 * (i % 2), 14, i * 0.15, 0.09) s.append(K("blue")) s.append(NUM(2.45, -2.3, 1.6 * g, rot=0.06 * math.sin(i * 1.3))) return s def trapeze(i, t): """High above the box, a flyer swings out on the trapeze, lets go, somersaults three times through the air and is caught by the catcher; a spotlight snaps on and the number blazes up in it.""" s = [] lp, rp, py, rl = (-2.4, -8.6), (3.6, -8.6), -8.6, 2.3 z = 1.25 th_l = 0.75 * math.sin(i / 6 * math.pi / 2) if i <= 12 else 0.75 * math.cos((i - 6) * 0.5) th_r = -0.7 * math.cos((i - 13) * math.pi / 10) * (math.exp(-(i - 13) * 0.13) if i > 13 else 1.0) for (px, _), th in ((lp, th_l), (rp, th_r)): bx, by = px + rl * math.sin(th), py + rl * math.cos(th) s.append(K("blue")) s.append(L([(px - 0.5, py), (bx - 0.5 * math.cos(th), by + 0.5 * math.sin(th))], 0.05)) s.append(L([(px + 0.5, py), (bx + 0.5 * math.cos(th), by - 0.5 * math.sin(th))], 0.05)) s.append(K("yellow")) s.append(L([(bx - 0.6 * math.cos(th), by + 0.6 * math.sin(th)), (bx + 0.6 * math.cos(th), by - 0.6 * math.sin(th))], 0.15)) s.append(K("blue")) s.append(L([(-3.8, py), (5.0, py)], 0.12)) if i >= 13: # the spotlight pool and the number g = pop_scale(t, 13 / 23, 0.12, 1.3) nx, ny = -1.1, -2.9 s.append(K("yellow")) s.append(P(oval(nx, ny, 2.9 * min(1.0, g), 1.55 * min(1.0, g), 16))) s += rays(nx, ny, 3.1, 3.5 + 0.2 * (i % 2), 14, i * 0.2, 0.08) s.append(K("red")) s.append(NUM(nx, ny, 1.85 * g, rot=0.06 * math.sin(i * 1.3))) s += confetti(nx, ny - 1.8, i, 13, 14, 2.8, 4) # the catcher hangs by the knees from the right bar, arms reaching down rbx, rby = rp[0] + rl * math.sin(th_r), py + rl * math.cos(th_r) hip = rotate([(rbx, rby + 0.85 * z)], th_r, rbx, rby)[0] s.append(K("blue")) s += figure(hip[0], hip[1], math.pi + th_r, (-0.12, 0.12), (-0.2, 0.2), 0.28, 0.14, z) hx, hy = rotate([(hip[0], hip[1] + 1.75 * z)], th_r, hip[0], hip[1])[0] # the catcher's hands lbx, lby = lp[0] + rl * math.sin(th_l), py + rl * math.cos(th_l) s.append(K("red")) if i <= 6: # the flyer hangs from the left bar hp = rotate([(lbx, lby + 1.75 * z)], th_l, lbx, lby)[0] s += figure(hp[0], hp[1], th_l, (-0.1, 0.1), (-0.25 * (i % 2), 0.25), 0.28, 0.14, z) elif i < 13: # flying, tucked, turning over u = (i - 6) / 7 x = lbx + (hx - lbx) * u y = (lby + 1.2) + (hy + 1.2 - lby - 1.2) * u - 2.4 * u * (1 - u) ang = u * 3 * 2 * math.pi s.append(C(*rotate([(x, y - 0.7)], ang, x, y)[0], 0.35)) s.append(P(rotate(oval(x, y, 0.45, 0.6, 10), ang, x, y))) s.append(L(rotate([(x - 0.35, y - 0.1), (x + 0.45, y + 0.4), (x + 0.1, y + 0.75)], ang, x, y), 0.15)) s.append(K("yellow")) for q in range(2): a2 = ang - 0.6 - q * 0.5 s.append(L([(x + 1.0 * math.cos(a2), y + 1.0 * math.sin(a2)), (x + 1.3 * math.cos(a2 - 0.3), y + 1.3 * math.sin(a2 - 0.3))], 0.06)) else: # caught: hangs from the catcher's hands hp = rotate([(hx, hy + 1.75 * z)], th_r, hx, hy)[0] s += figure(hp[0], hp[1], th_r, (-0.12, 0.12), (-0.15, 0.2), 0.28, 0.14, z) return s def finishline(i, t): """A sprinter tears along to the finish line by the box and bursts through the tape, arms up; the chequered flag waves, the cameras flash and the number goes up in lights.""" s = [] fx = 2.4 # the finish line s.append(K("blue")) s.append(L([(-5.0, 0.4), (6.5, 0.4)], 0.1)) for k in range(4): # lane lines rushing past x = -4.6 + ((k * 3.0 - i * 0.9) % 12.0) s.append(L([(x, 0.6), (x + 1.0, 0.6)], 0.06)) for px in (fx - 0.1, fx + 3.3): # tape posts s.append(L([(px, 0.4), (px, -2.6)], 0.12)) hit = 9 if i < hit: rx = -3.8 + (fx - 0.1 + 3.8) * i / hit else: rx = fx - 0.1 + 0.45 * (i - hit) * math.exp(-(i - hit) * 0.15) s.append(K("red")) if i < hit: s.append(L([(fx - 0.1, -2.1), (fx + 3.3, -2.1)], 0.08)) else: # the tape's broken ends flying back k = i - hit for side, px in ((-1, fx - 0.1), (1, fx + 3.3)): pts = [(px, -2.1)] for m in range(1, 7): ln = 1.7 * m / 6 pts.append((px - side * ln * math.cos(0.5 + 0.25 * k * 0.1), -2.1 + ln * 0.5 * min(1.0, k / 3) + 0.15 * math.sin(m + i))) s.append(L(pts, 0.08)) stride = math.sin(i * 1.6) # the runner s.append(K("blue")) if i < hit: s += figure(rx, -0.95, 0.25, (1.2 * stride, -1.2 * stride), (0.8 * stride, -0.8 * stride), 0.3, 0.18, 1.45) else: s += figure(rx, -0.95, -0.05, (-0.5 + 0.1 * math.sin(i), 0.5 - 0.1 * math.sin(i)), (0.25, -0.25), 0.3, 0.18, 1.45) # the chequered flag, waving s.append(K("blue")) s.append(L([(-3.1, 0.4), (-3.1, -6.2)], 0.12)) for r in range(3): for c in range(4): def wv(x): return 0.25 * math.sin((x + 3.1) * 1.6 - i * 1.4) x0, x1 = -3.1 + c * 0.55, -3.1 + (c + 1) * 0.55 y0, y1 = -6.2 + r * 0.5, -6.2 + (r + 1) * 0.5 s.append(K("blue" if (r + c) % 2 == 0 else "yellow")) s.append(P([(x0, y0 + wv(x0)), (x1, y0 + wv(x1)), (x1, y1 + wv(x1)), (x0, y1 + wv(x0))], 0, 0.02)) if i >= hit: g = pop_scale(t, hit / 23, 0.14, 1.3) s.append(K("yellow")) for k in range(5): # camera flashes along the track if (i + k * 2) % 4 == 0: s.append(P(star(-4.0 + k * 2.4, -0.3 - (k % 2) * 0.5, 0.6, 0.2, 8, i))) s += rays(2.1, -4.9, 2.6, 3.1 + 0.2 * (i % 2), 14, 0.2, 0.09) s.append(K("red")) s.append(NUM(2.1, -4.9, 2.0 * g, rot=-0.06 + 0.06 * math.sin(i * 1.2))) s += confetti(2.1, -6.3, i, hit, 18, 3.6, 5) return s def horse(x, y, z, flip, gallop): """A carousel horse centred at (x, y), z big, facing right (flip = -1: left).""" pts = [(-0.9, -0.1), (0.5, -0.15), (0.75, -0.65), (0.95, -0.95), (1.25, -0.8), (1.05, -0.45), (0.85, 0.15), (0.6, 0.35), (-0.7, 0.35), (-1.0, 0.0), (-1.3, 0.25), (-1.15, -0.15)] body = [(x + flip * px * z, y + py * z) for px, py in pts] legs = [] for lx, sw in ((-0.55, gallop), (-0.35, -gallop), (0.4, -gallop), (0.6, gallop)): legs.append([(x + flip * lx * z, y + 0.3 * z), (x + flip * (lx + 0.35 * sw) * z, y + 0.85 * z)]) return body, legs def carousel(i, t): """A carousel turns over the box, painted horses rising and falling on their poles under a striped, scalloped canopy; the bulbs chase round and the number rises up to crown its top.""" s = [] cx, top, floor = 0.9, -4.6, -0.3 hw = 3.4 s.append(K("blue")) s.append(L([(cx, floor), (cx, top)], 0.2)) # the centre pole s.append(P(oval(cx, floor + 0.2, hw + 0.3, 0.45, 16))) # the platform horses = [] for k in range(4): ph = i * 0.2 + k * math.pi / 2 x = cx + hw * 0.8 * math.sin(ph) depth = math.cos(ph) horses.append((depth, k, x, ph)) for depth, k, x, ph in sorted(horses): z = 0.8 + 0.2 * depth bob = 0.45 * math.sin(i * 0.9 + k * 1.7) y = -1.8 + bob s.append(K("yellow")) s.append(L([(x, top + 0.2), (x, floor)], 0.06)) col = ["red", "blue", "yellow", "red"][k] if depth > -0.2 else "blue" if col == "yellow": col = "red" flip = 1 if math.cos(ph) > 0 else -1 body, legs = horse(x, y, z, flip, 0.4 * math.sin(i * 0.9 + k)) s.append(K(col)) s.append(P(body)) for lg in legs: s.append(L(lg, 0.11 * z)) s.append(K("yellow")) s.append(L([(x + flip * 0.75 * z, y - 0.6 * z), (x + flip * 0.95 * z, y - 0.95 * z)], 0.1 * z)) # the mane n = 10 # the canopy: a striped cone, scalloped hem for k in range(n): x0 = cx - hw - 0.3 + k * (2 * hw + 0.6) / n x1 = x0 + (2 * hw + 0.6) / n s.append(K("red" if k % 2 == 0 else "yellow")) s.append(P([(x0, top), (x1, top), (cx + (x1 - cx) * 0.05, top - 1.9), (cx + (x0 - cx) * 0.05, top - 1.9)], 0, 0.02)) s.append(P([(x0, top), (x1, top), ((x0 + x1) / 2, top + 0.45)], 0, 0.02)) s.append(K("blue")) s.append(L([(cx - hw - 0.3, top), (cx + hw + 0.3, top)], 0.12)) for k in range(9): # the bulbs on the hem on = (k + i) % 3 == 0 s.append(K("yellow" if on else "blue")) s.append(C(cx - hw + k * hw / 4, top + 0.1, 0.17 if on else 0.09)) s.append(K("blue")) s.append(L([(cx, top - 1.9), (cx, top - 2.4)], 0.08)) if i >= 10: g = pop_scale(t, 10 / 23, 0.14, 1.3) y = top - 2.4 - 1.2 * ease_out(min(1.0, (i - 10) / 4)) s.append(K("yellow")) s += rays(cx, y, 2.4, 2.8 + 0.2 * (i % 2), 12, i * 0.2, 0.09) s.append(K("red")) s.append(NUM(cx, y, 1.9 * g, rot=0.05 * math.sin(i * 1.1))) s += burst(cx - 3.4, top - 2.5, i, 12, 1.3, 9, "blue") s += burst(cx + 3.6, top - 2.8, i, 14, 1.3, 9, "yellow") s += burst(cx - 3.0, top - 4.2, i, 16, 1.2, 9, "red") else: s.append(K("red")) s.append(P([(cx, top - 2.4), (cx + 0.7, top - 2.2), (cx, top - 2.0)])) # a pennant till then return s def fieldgoal(i, t): """A football on its tee by the box is booted end over end, high and long, straight through the uprights; the stadium erupts in fireworks and the number blazes between the posts.""" s = [] gx, bar, top = 2.6, -3.2, -8.0 # the goalposts hw = 2.35 s.append(K("yellow")) s.append(L([(gx, 0.4), (gx, bar)], 0.2)) s.append(L([(gx - hw, top), (gx - hw, bar), (gx + hw, bar), (gx + hw, top)], 0.2)) for side in (-1, 1): # their little flags fx = gx + side * hw s.append(K("red")) wv = 0.2 * math.sin(i * 1.5 + side) s.append(P([(fx, top), (fx + 0.9, top + 0.15 + wv), (fx, top + 0.5)], 0, 0.03)) for k in range(5): s += burst([-2.5, 6.6, -1.6, 6.0, 2.6][k], [-6.8, -6.6, -3.2, -2.6, -9.2][k], i, 10 + 2 * k, 1.5, 11, ["red", "blue", "yellow", "red", "blue"][k]) if i < 3: # the kicker's boot swings in s.append(K("blue")) a = [-2.4, -1.6, -0.6][i] s.append(L([(-1.4, -2.2), (-1.4 + 1.8 * math.cos(a + 1.2), -2.2 + 1.8 * math.sin(a + 1.2))], 0.24)) if i == 3: s.append(K("yellow")) s.append(P(star(-0.2, -0.8, 1.0, 0.4, 8, 0.3))) # the ball, end over end if i < 3: bx, by, ang = -0.2, -0.75, -1.2 else: u = min(1.0, (i - 3) / 8) bx = -0.2 + (gx + 0.2 + 0.2) * u by = -0.75 + (bar - 3.2 + 0.75) * u - 4.0 * u * (1 - u) ang = (i - 3) * 1.1 if i > 11: k = i - 11 bx, by = gx + 0.4 + 0.5 * k, bar - 3.2 + 0.3 * k + 0.12 * k * k ang = (i - 3) * 0.9 if by < 0.0: s.append(K("red")) s.append(P(oval(bx, by, 0.55, 0.34, 12, ang))) s.append(K("yellow")) s.append(L(rotate([(bx - 0.25, by), (bx + 0.25, by)], ang, bx, by), 0.05)) if i < 3: s.append(K("blue")) s.append(P([(-0.5, -0.4), (0.1, -0.4), (-0.05, -0.55), (-0.35, -0.55)])) # the tee if 4 <= i <= 10: s.append(K("blue")) for q in range(3): s.append(C(bx - (q + 1) * 0.55, by + (q + 1) * 0.45 - (q + 1) ** 2 * 0.05, 0.1, 0.05)) if i >= 10: g = pop_scale(t, 10 / 23, 0.14, 1.3) s.append(K("blue")) s.append(NUM(gx, -5.4, 1.75 * g, rot=0.05 * math.sin(i * 1.4))) if i % 2 == 0: s.append(K("yellow")) s += rays(gx, bar - 0.2, 0.3, 0.9, 6, -math.pi / 2 - 1.3, 0.08) return s def juggler(i, t): """A clown on a unicycle by the box juggles clubs and balls faster and faster, flings the lot sky-high, and catches the number overhead while the balls whirl round it like stars.""" s = [] wx = 0.6 + 0.35 * math.sin(i * 0.5) # the unicycle rocks to and fro wy, wr = -0.3, 0.65 s.append(K("blue")) s.append(P(ring(wx, wy, wr, 14, 0, 0.02), 0.14)) for k in range(3): a = k * math.pi / 3 + (wx - 0.6) / wr s.append(L([(wx + wr * math.cos(a), wy + wr * math.sin(a)), (wx - wr * math.cos(a), wy - wr * math.sin(a))], 0.05)) s.append(L([(wx, wy), (wx, wy - 1.4)], 0.12)) s.append(K("red")) s.append(P([(wx - 0.5, wy - 1.35), (wx + 0.5, wy - 1.35), (wx + 0.4, wy - 1.6), (wx - 0.4, wy - 1.6)])) # seat hipx, hipy = wx, wy - 1.6 up = i >= 14 s.append(K("yellow")) s.append(P([(hipx - 0.55, hipy), (hipx + 0.55, hipy), (hipx + 0.4, hipy - 1.5), (hipx - 0.4, hipy - 1.5)])) # baggy suit s.append(K("red")) for q in range(3): s.append(C(hipx, hipy - 0.35 - q * 0.4, 0.09)) s.append(K("yellow")) s.append(L([(hipx - 0.25, hipy), (wx - 0.25, wy - 0.25)], 0.12)) s.append(L([(hipx + 0.25, hipy), (wx + 0.25, wy + 0.25)], 0.12)) hx, hy = hipx, hipy - 1.95 s.append(C(hx, hy, 0.42)) s.append(K("red")) s.append(C(hx + 0.05, hy + 0.05, 0.12)) # the red nose s.append(P([(hx - 0.32, hy - 0.3), (hx + 0.32, hy - 0.3), (hx + 0.1, hy - 1.05)])) # the hat s.append(K("blue")) s.append(C(hx + 0.1, hy - 1.1, 0.13)) shl, shr = (hipx - 0.45, hipy - 1.35), (hipx + 0.45, hipy - 1.35) if not up: # hands juggling at waist height lh = (hipx - 1.0, hipy - 0.9 + 0.2 * math.sin(i * 2.2)) rh = (hipx + 1.0, hipy - 0.9 - 0.2 * math.sin(i * 2.2)) else: lh, rh = (hipx - 0.6, hipy - 3.3), (hipx + 0.6, hipy - 3.3) s.append(K("yellow")) s.append(L([shl, lh], 0.12)) s.append(L([shr, rh], 0.12)) jx, jy = hipx, hipy - 1.6 # the cascade's centre n = 5 speed = 0.55 + 0.04 * i for m in range(n): col = ["red", "blue", "red", "blue", "red"][m] if not up: ph = (i * speed + m / n * 2 * math.pi) % (2 * math.pi) ox = 1.3 * math.cos(ph) oy = -1.6 * abs(math.sin(ph)) * (1.6 if m % 2 else 1.3) - 0.6 x, y = jx + ox, jy + oy else: k = i - 14 if k < 4: # flung up and out a = -math.pi / 2 + (m - 2) * 0.55 d = 1.2 + k * 1.0 x, y = jx + d * math.cos(a) * 1.2, jy - 2.0 + d * math.sin(a) else: # whirling round the number a = (k - 4) * 0.6 + m * 2 * math.pi / n x, y = hx + 2.6 * math.cos(a), hy - 3.6 + 1.6 * math.sin(a) s.append(K(col)) if m % 2: s.append(C(x, y, 0.24)) else: # a club, spinning ca = i * 1.3 + m s.append(P(rotate([(x - 0.12, y + 0.4), (x + 0.12, y + 0.4), (x + 0.2, y - 0.25), (x, y - 0.45), (x - 0.2, y - 0.25)], ca, x, y))) if up: k = i - 14 g = pop_scale(t, 15 / 23, 0.12, 1.3) y = hy - 3.6 - 2.0 * (1 - ease_out(min(1.0, k / 3))) * 0 s.append(K("yellow")) if k < 3: s.append(P(star(hx, hy - 3.6, 2.4 - 0.5 * k, 1.0, 12, i))) s += rays(hx, hy - 3.6, 2.9, 3.3, 14, i * 0.2, 0.08) s.append(K("red")) if i >= 15: s.append(NUM(hx, y, 1.9 * g, rot=0.06 * math.sin(i * 1.4))) return s def dunktank(i, t): """A clown sits on the plank over a dunk tank by the box; a ball smacks the target, SPLOOSH, he drops in, a towering splash throws up the number, and he bobs up grinning.""" s = [] tx, tw, tt = 2.4, 1.9, -2.6 # the tank: centre, half width, its rim hit, drop = 5, 7 s.append(K("blue")) s.append(L([(tx - tw, tt), (tx - tw, 0.4), (tx + tw, 0.4), (tx + tw, tt)], 0.16)) lvl = tt + 0.7 - (0.25 if i >= drop else 0.0) s.append(P([(tx - tw + 0.1, 0.35)] + [(tx - tw + 0.1 + (2 * tw - 0.2) * k / 8, lvl + 0.12 * math.sin(k * 1.6 + i * 1.3) * (2.5 if drop <= i <= drop + 6 else 1)) for k in range(9)] + [(tx + tw - 0.1, 0.35)], 0, 0.03)) s.append(K("red")) # the cage and the plank s.append(L([(tx - tw, tt), (tx - tw, -5.8), (tx + tw, -5.8), (tx + tw, tt)], 0.07)) s.append(L([(tx - tw + 0.95, -5.8), (tx - tw + 0.95, tt)], 0.04)) s.append(L([(tx + tw - 0.95, -5.8), (tx + tw - 0.95, tt)], 0.04)) pl = 0.0 if i < hit else min(1.2, (i - hit) * 0.6) s.append(K("yellow")) s.append(L([(tx + tw, -3.6), (tx + tw - 2.6 * math.cos(pl), -3.6 + 2.6 * math.sin(pl))], 0.18)) s.append(L([(tx - tw, -3.6), (tx - tw - 1.2, -3.6), (tx - tw - 1.2, -4.6)], 0.08)) # the target's arm s.append(K("red")) s.append(C(tx - tw - 1.2, -5.1 + (0.12 if i in (hit, hit + 1) else 0), 0.55)) s.append(K("yellow")) s.append(C(tx - tw - 1.2, -5.1 + (0.12 if i in (hit, hit + 1) else 0), 0.3)) s.append(K("red")) s.append(C(tx - tw - 1.2, -5.1 + (0.12 if i in (hit, hit + 1) else 0), 0.12)) if i < hit: # the ball u = i / hit bx, by = -3.4 + (tx - tw - 1.2 + 3.4) * u, -1.0 + (-5.1 + 1.0) * u - 1.2 * u * (1 - u) s.append(K("blue")) s.append(C(bx, by, 0.3)) s.append(L([(bx - 0.6, by + 0.4), (bx - 1.2, by + 0.75)], 0.05)) elif i <= hit + 1: s.append(K("yellow")) s.append(P(star(tx - tw - 1.2, -5.1, 1.1, 0.45, 9, i))) # the clown if i < drop: cx, cy, sit = tx + 0.4, -3.75, True if i in (hit + 1,): cy -= 0.15 elif i < drop + 3: cx, cy, sit = tx + 0.3, -3.75 + (i - drop + 1) * 1.1, True else: cx, cy, sit = tx + 0.2, lvl - 0.1 + 0.2 * math.sin(i * 0.9), False s.append(K("blue")) if sit or i < drop + 3: s.append(P([(cx - 0.4, cy), (cx + 0.4, cy), (cx + 0.3, cy - 1.0), (cx - 0.3, cy - 1.0)])) s.append(L([(cx - 0.3, cy), (cx - 0.9, cy + 0.1), (cx - 1.0, cy + 0.7)], 0.13)) s.append(K("yellow")) s.append(C(cx, cy - 1.35, 0.38)) s.append(K("red")) s.append(C(cx + 0.05, cy - 1.32, 0.11)) arms = [(cx - 0.3, cy - 0.85), (cx - 0.9, cy - 1.7 if i >= drop else cy - 0.5)] s.append(L(arms, 0.1)) s.append(L([(cx + 0.3, cy - 0.85), (cx + 0.9, cy - 1.7 if i >= drop else cy - 0.5)], 0.1)) else: # bobbing up, grinning, waving if cy - 0.4 < 0.4: s.append(K("yellow")) s.append(C(cx, cy - 0.35, 0.38)) s.append(K("red")) s.append(C(cx + 0.05, cy - 0.32, 0.11)) s.append(L([(cx - 0.2, cy - 0.15), (cx, cy - 0.08), (cx + 0.2, cy - 0.15)], 0.05)) s.append(K("yellow")) s.append(L([(cx + 0.35, cy - 0.1), (cx + 0.8, cy - 0.8 + 0.2 * math.sin(i * 2))], 0.1)) if i >= drop + 2: # the great splash k = i - drop - 2 s.append(K("blue")) for m in range(12): a = -math.pi / 2 + (m - 5.5) * 0.17 v = 2.2 + 1.2 * ((m * 7) % 5) / 4 u = k * 0.5 x = tx + v * math.cos(a) * u * 1.2 y = lvl - 0.2 + v * math.sin(a) * u * 1.4 + 0.18 * u * u * 1.4 if -9.0 < y < lvl and abs(x - tx) < 4.5 and k < 9: s.append(C(x, y, 0.2 if m % 2 else 0.14)) g = pop_scale(t, (drop + 2) / 23, 0.14, 1.3) ny = lvl - 1.4 - 3.5 * ease_out(min(1.0, k / 4)) if k < 6: s.append(K("blue")) s.append(P([(tx - 0.6, lvl), (tx + 0.6, lvl), (tx + 0.35, ny + 0.9), (tx - 0.35, ny + 0.9)], 0, 0.06)) s.append(K("red")) s.append(NUM(tx, ny, 1.9 * g, rot=0.08 * math.sin(i * 1.2))) s += confetti(tx, ny - 1.0, i, drop + 5, 12, 3.0, 6) return s ANIMS = [ (ferriswheel, "blue", "skyride"), (rollercoaster, "red", "clackety"), (trapeze, "yellow", "hupla"), (finishline, "red", "photofinish"), (carousel, "red", "calliope"), (fieldgoal, "yellow", "airhorn"), (juggler, "yellow", "tossup"), (dunktank, "blue", "kersplash"), ]