538 lines
26 KiB
Python
538 lines
26 KiB
Python
"""Streak level 1: a 21-day streak. Eight 2-second celebrations, each showing the streak number.
|
|
|
|
Fairground games, sports, party treats and toys, a notch bigger than level 0. Sounds:
|
|
level1_sounds.py, same names as below.
|
|
"""
|
|
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 clamp(v, lo=0.0, hi=1.0):
|
|
return max(lo, min(hi, v))
|
|
|
|
|
|
def highstriker(i, t):
|
|
"""A fairground high striker by the box: a mallet winds up and slams the pad, the puck shoots up the tower, rings the bell, and the number pops out as the lights chase."""
|
|
s = []
|
|
tx, top, bot = 1.9, -6.2, -0.25
|
|
s.append(P([(tx - 0.3, bot), (tx + 0.3, bot), (tx + 0.2, top), (tx - 0.2, top)])) # the tower
|
|
s.append(P([(tx - 1.4, bot - 0.05), (tx + 0.6, bot - 0.05), (tx + 0.6, bot + 0.4), (tx - 1.4, bot + 0.4)]))
|
|
s.append(K("yellow"))
|
|
for k in range(8): # the scale marks
|
|
y = bot - 0.8 - k * 0.65
|
|
s.append(L([(tx - 0.13, y), (tx + 0.13, y)], 0.07))
|
|
s.append(P([(tx - 1.25, bot - 0.05), (tx - 0.35, bot - 0.05), (tx - 0.4, bot - 0.3), (tx - 1.2, bot - 0.3)])) # pad
|
|
# the puck: still, then flung up the tower, then sliding back down
|
|
if i < 7:
|
|
py = bot - 0.45
|
|
elif i <= 11:
|
|
py = bot - 0.45 + (top + 0.4 - bot + 0.45) * ease_out((i - 7) / 4)
|
|
elif i < 17:
|
|
py = top + 0.4
|
|
else:
|
|
py = top + 0.4 + (bot - 0.45 - top - 0.4) * min(1.0, ((i - 17) / 6) ** 2)
|
|
s.append(K("blue"))
|
|
s.append(P(ring(tx, py, 0.3, 8, 0, 0.02)))
|
|
if 8 <= i <= 10: # speed lines under it
|
|
s.append(L([(tx - 0.45, py + 0.5), (tx - 0.45, py + 1.6)], 0.06))
|
|
s.append(L([(tx + 0.45, py + 0.5), (tx + 0.45, py + 1.6)], 0.06))
|
|
rt = i - 11 # the bell, ringing
|
|
tilt = 0.4 * math.sin(rt * 2.0) * math.exp(-rt * 0.2) if rt >= 0 else 0.0
|
|
bx, by = tx, top - 0.05
|
|
s.append(K("yellow"))
|
|
s.append(P(rotate([(bx - 0.65, by), (bx + 0.65, by), (bx + 0.5, by - 0.3), (bx + 0.4, by - 0.65),
|
|
(bx, by - 0.85), (bx - 0.4, by - 0.65), (bx - 0.5, by - 0.3)], tilt, bx, by - 0.9)))
|
|
if rt >= 0 and rt < 8:
|
|
s.append(K("red"))
|
|
s += rays(bx, by - 0.4, 1.0, 1.5 + 0.25 * (i % 2), 9, i * 0.3, 0.09)
|
|
# the mallet
|
|
if i < 6:
|
|
a = -0.6 - 1.5 * ease_out(i / 5)
|
|
elif i == 6:
|
|
a = -0.5
|
|
elif i <= 8:
|
|
a = 0.44
|
|
else:
|
|
a = 0.44 - 0.6 * ease_out(min(1.0, (i - 8) / 6))
|
|
px, py0 = -1.0, -1.45
|
|
hx, hy = px + 2.2 * math.cos(a), py0 + 2.2 * math.sin(a)
|
|
s.append(K("blue"))
|
|
s.append(L([(px - 0.25 * math.cos(a), py0 - 0.25 * math.sin(a)), (hx, hy)], 0.16))
|
|
na, nb = -math.sin(a), math.cos(a)
|
|
ca, sa = math.cos(a), math.sin(a)
|
|
s.append(P([(hx + 0.55 * na - 0.3 * ca, hy + 0.55 * nb - 0.3 * sa), (hx + 0.55 * na + 0.3 * ca, hy + 0.55 * nb + 0.3 * sa),
|
|
(hx - 0.55 * na + 0.3 * ca, hy - 0.55 * nb + 0.3 * sa), (hx - 0.55 * na - 0.3 * ca, hy - 0.55 * nb - 0.3 * sa)]))
|
|
if i == 6: # the swing's blur
|
|
s.append(L([(px + 2.4 * math.cos(b), py0 + 2.4 * math.sin(b)) for b in (-1.9, -1.3, -0.7, -0.1, 0.4)], 0.07))
|
|
if i in (7, 8):
|
|
s.append(K("yellow"))
|
|
s.append(P(star(tx - 0.8, bot - 0.1, 1.1 - (i - 7) * 0.3, 0.45, 8, i)))
|
|
if i >= 11: # the lights chase up the tower
|
|
for k in range(7):
|
|
s.append(K(["red", "yellow", "blue"][(k + i) % 3] if (k + i) % 2 else "yellow"))
|
|
s.append(C(tx + 0.55, bot - 0.6 - k * 0.8, 0.17 if (k + i) % 2 else 0.11))
|
|
g = pop_scale(t, 11 / 23, 0.12, 1.3)
|
|
s.append(K("red"))
|
|
s.append(NUM(-1.0, -4.9, 1.6 * g, rot=-0.08 + 0.08 * math.sin(i * 1.1)))
|
|
return s
|
|
|
|
|
|
def slamdunk(i, t):
|
|
"""A basketball bounces up out of the box, arcs high and drops through the hoop with a swish; the backboard lights up with the number while the ball bounces away."""
|
|
s = []
|
|
bx0, bx1, by0, by1 = 0.8, 4.4, -7.1, -4.7 # the backboard
|
|
s.append(L([(bx1, (by0 + by1) / 2), (5.0, (by0 + by1) / 2), (5.0, 0.4)], 0.18)) # its post
|
|
s.append(K("yellow"))
|
|
s.append(P([(bx0, by0), (bx1, by0), (bx1, by1), (bx0, by1)], 0, 0.03))
|
|
s.append(K("blue"))
|
|
s.append(P([(bx0, by0), (bx1, by0), (bx1, by1), (bx0, by1)], 0.14, 0.03))
|
|
rx, ry = 2.6, -4.45 # the rim's centre
|
|
# the ball's path
|
|
if i <= 9:
|
|
u = i / 9
|
|
x = -0.4 + (rx - -0.4) * u
|
|
y = -0.9 + (ry - 0.1 + 0.9) * u - 12.0 * u * (1 - u)
|
|
elif i <= 11:
|
|
x, y = rx, [ry + 0.9, ry + 1.9][i - 10]
|
|
else:
|
|
k = i - 12
|
|
ys = [-1.4, -0.5, -1.5, -1.9, -1.5, -0.5, -1.0, -1.15, -0.95, -0.5, -0.6, -0.5]
|
|
x, y = rx + 0.25 * (k + 1), ys[min(k, len(ys) - 1)]
|
|
scored = i >= 10
|
|
if scored:
|
|
g = pop_scale(t, 10 / 23, 0.12, 1.3)
|
|
s.append(K("red"))
|
|
s.append(NUM((bx0 + bx1) / 2, (by0 + by1) / 2 + 0.05, 1.4 * g, rot=0.06 * math.sin(i * 1.3)))
|
|
if i % 2 == 0 and i < 20:
|
|
s.append(K("yellow"))
|
|
s += [L([(bx0 - 0.25, by0 - 0.25 - k * 0.0), (bx0 - 0.7, by0 - 0.7)], 0.09) for k in range(1)]
|
|
s.append(L([(bx1 + 0.25, by0 - 0.25), (bx1 + 0.7, by0 - 0.7)], 0.09))
|
|
s.append(L([(bx0 - 0.3, (by0 + by1) / 2), (bx0 - 0.9, (by0 + by1) / 2)], 0.09))
|
|
s.append(L([((bx0 + bx1) / 2, by0 - 0.3), ((bx0 + bx1) / 2, by0 - 0.9)], 0.09))
|
|
else:
|
|
s.append(K("red"))
|
|
s.append(P([(rx - 0.5, by1 - 0.3), (rx + 0.5, by1 - 0.3), (rx + 0.5, by1 - 1.1), (rx - 0.5, by1 - 1.1)], 0.08, 0.03))
|
|
in_net = i in (10, 11)
|
|
ball_behind = in_net
|
|
def ball():
|
|
out = [K("red"), C(x, y, 0.5)]
|
|
a = i * 0.7
|
|
out.append(K("blue"))
|
|
out.append(L([(x + 0.5 * math.cos(a), y + 0.5 * math.sin(a)), (x - 0.5 * math.cos(a), y - 0.5 * math.sin(a))], 0.06))
|
|
out.append(L([(x + 0.5 * math.cos(a + 1.57), y + 0.5 * math.sin(a + 1.57)),
|
|
(x + 0.15 * math.cos(a), y + 0.15 * math.sin(a)),
|
|
(x - 0.5 * math.cos(a + 1.57), y - 0.5 * math.sin(a + 1.57))], 0.06))
|
|
return out
|
|
if ball_behind:
|
|
s += ball()
|
|
# the net: stretched while the ball is in it
|
|
drop = 1.15 + (0.45 if in_net else 0.0) + (0.15 if i == 12 else 0.0)
|
|
nw = 0.38 if not in_net else 0.3
|
|
s.append(K("blue"))
|
|
top_pts = [(rx - 0.75 + 0.3 * k, ry) for k in range(6)]
|
|
bot_pts = [(rx - nw + 2 * nw * k / 5, ry + drop + 0.06 * math.sin(i * 2 + k)) for k in range(6)]
|
|
for k in range(6):
|
|
s.append(L([top_pts[k], bot_pts[k]], 0.05))
|
|
zig = []
|
|
for k in range(6):
|
|
zig.append(bot_pts[k] if k % 2 else ((top_pts[k][0] + bot_pts[k][0]) / 2, ry + drop / 2))
|
|
s.append(L(zig, 0.05))
|
|
s.append(K("red"))
|
|
s.append(L([(rx - 0.8, ry), (rx + 0.8, ry), (bx1 - 0.1, ry - 0.05)], 0.15))
|
|
if in_net:
|
|
s.append(K("yellow"))
|
|
s += rays(rx, ry + 0.6, 1.1, 1.6, 6, 0.3, 0.09)
|
|
if not ball_behind:
|
|
s += ball()
|
|
return s
|
|
|
|
|
|
def strike(i, t):
|
|
"""A bowling ball rolls out of the box down a lane into ten pins: STRIKE, the pins fly every which way and the number bursts up where they stood."""
|
|
s = []
|
|
c = 1.2 # the pins' centre line
|
|
s.append(K("red"))
|
|
s.append(L([(-1.6, 0.7), (c - 1.2, -3.3)], 0.08)) # the lane's edges
|
|
s.append(L([(3.2, 0.7), (c + 1.2, -3.3)], 0.08))
|
|
rows = [(-4.9, [-1.5, -0.5, 0.5, 1.5], 0.85), (-4.45, [-1, 0, 1], 0.9), (-4.0, [-0.5, 0.5], 0.95), (-3.55, [0], 1.0)]
|
|
k = 0
|
|
for y, xs, z in rows:
|
|
for xo in xs:
|
|
px, py = c + xo * 0.62, y
|
|
sc = z * 1.3
|
|
if i < 8:
|
|
ang = 0.0
|
|
else:
|
|
u = i - 8
|
|
vx = xo * 0.5 + (0.35 if k % 2 else -0.35)
|
|
vy = -0.75 - 0.15 * (k % 4)
|
|
px, py = px + vx * u, py + vy * u + 0.075 * u * u
|
|
ang = u * (0.5 + 0.12 * k) * (1 if xo + 0.1 * k >= 0.5 else -1)
|
|
pin = [(-0.1, 0), (0.1, 0), (0.17, -0.35), (0.07, -0.6), (0.12, -0.85), (0, -1.0), (-0.12, -0.85),
|
|
(-0.07, -0.6), (-0.17, -0.35)]
|
|
pts = rotate([(px + x * sc, py + y_ * sc) for x, y_ in pin], ang, px, py - 0.5 * sc)
|
|
s.append(K("yellow"))
|
|
s.append(P(pts, 0, 0.03))
|
|
s.append(K("red"))
|
|
s.append(L(rotate([(px - 0.08 * sc, py - 0.63 * sc), (px + 0.08 * sc, py - 0.63 * sc)], ang, px, py - 0.5 * sc), 0.07))
|
|
k += 1
|
|
if i <= 8: # the ball, rolling away
|
|
u = i / 8
|
|
bx, by, r = -0.1 + (c - -0.1) * u, -0.2 + (-3.2 + 0.2) * (0.6 * ease_out(u) + 0.4 * u), 0.9 - 0.45 * u
|
|
s.append(K("blue"))
|
|
s.append(C(bx, by, r))
|
|
s.append(K("yellow"))
|
|
for q in range(3):
|
|
a = i * 1.1 + q * 0.6
|
|
s.append(C(bx + r * 0.45 * math.cos(a), by + r * 0.45 * math.sin(a) - r * 0.1, r * 0.13))
|
|
if i < 7:
|
|
s.append(K("blue"))
|
|
s.append(L([(bx - r - 0.2, by + r * 0.7), (bx - r - 0.6, by + r * 1.3)], 0.06))
|
|
s.append(L([(bx + r + 0.2, by + r * 0.7), (bx + r + 0.6, by + r * 1.3)], 0.06))
|
|
if 8 <= i <= 10:
|
|
s.append(K("yellow"))
|
|
s.append(P(star(c, -4.2, 2.3 - (i - 8) * 0.4, 0.9, 12, i)))
|
|
if i >= 9:
|
|
g = pop_scale(t, 9 / 23, 0.12, 1.35)
|
|
s.append(K("blue"))
|
|
s.append(NUM(c, -4.4, 1.75 * g, rot=-0.1 + 0.06 * math.sin(i)))
|
|
if i >= 12 and i % 2:
|
|
s.append(K("red"))
|
|
s += rays(c, -4.4, 2.6, 3.0, 12, i * 0.1, 0.08)
|
|
return s
|
|
|
|
|
|
def gumball(i, t):
|
|
"""A gumball machine sits on the box; its crank clicks round, a big capsule rolls out of the chute, wobbles, and pops open with the number springing out."""
|
|
s = []
|
|
mx, gy, gr = -1.5, -3.4, 1.35 # the globe
|
|
jig = 0.06 if i < 9 and i % 2 else 0.0
|
|
s.append(P([(mx - 1.1, 0.2), (mx + 1.1, 0.2), (mx + 0.8, -1.9), (mx - 0.8, -1.9)])) # the stand
|
|
s.append(P([(mx - 0.4, gy - gr - 0.25), (mx + 0.4, gy - gr - 0.25), (mx + 0.3, gy - gr + 0.1), (mx - 0.3, gy - gr + 0.1)]))
|
|
s.append(K("blue"))
|
|
s.append(C(mx, gy, gr, 0.1))
|
|
s.append(L([(mx - 0.75, gy - 0.6), (mx - 0.45, gy - 0.95)], 0.07))
|
|
gums = [(-0.6, 0.6), (0.0, 0.75), (0.6, 0.6), (-0.85, 0.05), (-0.3, 0.2), (0.3, 0.15), (0.85, 0.1),
|
|
(-0.5, -0.35), (0.1, -0.3), (0.6, -0.4), (-0.05, 0.75 - 1.6)]
|
|
for k, (gx, gyo) in enumerate(gums):
|
|
s.append(K(["red", "yellow", "blue"][k % 3]))
|
|
s.append(C(mx + gx + (jig if k % 2 else -jig), gy + gyo, 0.27))
|
|
s.append(K("yellow")) # the crank turns in clicks
|
|
cx, cy = mx, -1.05
|
|
s.append(C(cx, cy, 0.38))
|
|
a = -math.pi / 2 + (math.pi / 2) * min(i // 2, 4)
|
|
s.append(K("blue"))
|
|
s.append(L([(cx, cy), (cx + 0.55 * math.cos(a), cy + 0.55 * math.sin(a))], 0.13))
|
|
s.append(K("yellow"))
|
|
s.append(P([(mx + 0.75, -0.4), (mx + 1.35, -0.1), (mx + 1.35, 0.2), (mx + 0.75, 0.0)])) # the chute
|
|
if i >= 8:
|
|
k = i - 8
|
|
if k < 6: # the capsule rolls out and grows
|
|
u = ease_out(k / 5)
|
|
x, r = mx + 1.4 + (3.0 - mx - 1.4) * u, 0.3 + 0.6 * u
|
|
y, rot, opn = -r + 0.1, k * 1.2, 0.0
|
|
else:
|
|
x, r = 3.0, 0.9
|
|
y = -r + 0.1
|
|
rot = 0.25 * math.sin((k - 6) * 2.5) if k < 8 else 0.0
|
|
opn = 0.0 if k < 8 else ease_out(min(1.0, (k - 8) / 4))
|
|
s.append(K("blue"))
|
|
s.append(P([(x + r * math.cos(rot + b), y + r * math.sin(rot + b)) for b in [m * math.pi / 7 for m in range(8)]]))
|
|
kk = max(0, k - 8)
|
|
lid_y = y - 1.3 * kk + 0.12 * kk * kk
|
|
lid_x = x + 0.7 * kk
|
|
s.append(K("red"))
|
|
s.append(P(rotate([(x + r * math.cos(rot - b), y + r * math.sin(rot - b)) for b in [m * math.pi / 7 for m in range(8)]],
|
|
opn * 1.6, x, y), 0, 0.05) if opn == 0 else
|
|
P(rotate([(lid_x + r * math.cos(-b), lid_y + r * math.sin(-b)) for b in [m * math.pi / 7 for m in range(8)]],
|
|
kk * 0.9, lid_x, lid_y)))
|
|
if opn > 0:
|
|
g = pop_scale(t, 16 / 23, 0.12, 1.35)
|
|
if i <= 18:
|
|
s.append(K("yellow"))
|
|
s.append(P(star(x, y - 0.4, 1.7 - 0.25 * (i - 16), 0.7, 10, i)))
|
|
ny = y - 0.6 - 2.1 * ease_out(min(1.0, (k - 8) / 3))
|
|
s.append(K("blue"))
|
|
s.append(L([(x, y), (x - 0.25, y - 0.4), (x + 0.25, y - 0.7), (x - 0.25, y - 1.0), (x, ny + 0.75 * g)], 0.08))
|
|
s.append(K("red"))
|
|
s.append(NUM(x, ny, 1.6 * g, rot=0.12 * math.sin(i * 1.4)))
|
|
return s
|
|
|
|
|
|
def sealion(i, t):
|
|
"""A circus sea lion rises up on its striped stand, flips its ball sky-high, catches the number on its nose instead and balances it, clapping its flippers."""
|
|
s = []
|
|
up = ease_out(min(1.0, t * 4))
|
|
bx, by = -0.4, 0.4 - 1.2 * up # where its tail sits
|
|
s.append(K("red"))
|
|
s.append(P([(bx - 1.3, by + 0.9), (bx + 1.3, by + 0.9), (bx + 1.1, by), (bx - 1.1, by)]))
|
|
s.append(K("yellow"))
|
|
for k in range(4):
|
|
x = bx - 0.9 + k * 0.6
|
|
s.append(P([(x, by + 0.9), (x + 0.25, by + 0.9), (x + 0.32, by), (x + 0.1, by)]))
|
|
nod = 0.12 * math.sin(i * 1.3) if i >= 15 else (-0.25 if i == 5 else 0.0)
|
|
|
|
z = 1.3
|
|
|
|
def at(x, y):
|
|
return rotate([(bx + x * z, by + y * z)], nod * (-y / 3.2), bx, by)[0]
|
|
s.append(K("blue"))
|
|
body = [(-1.0, 0), (0.7, 0), (0.85, -0.6), (0.7, -1.4), (0.5, -2.1), (0.42, -2.55), (0.05, -2.6), (-0.15, -2.1),
|
|
(-0.45, -1.1), (-1.1, -0.45), (-1.6, -0.15)]
|
|
s.append(P([at(x, y) for x, y in body]))
|
|
head = [(0.02, -2.55), (0.0, -2.85), (0.15, -3.05), (0.42, -3.1), (0.7, -3.3), (0.85, -3.28), (0.82, -3.05),
|
|
(0.62, -2.75), (0.45, -2.5)]
|
|
s.append(P([at(x, y) for x, y in head]))
|
|
clap = i >= 15 and i % 2 == 0
|
|
fl = [(0.6, -1.3), (1.4, -1.6), (1.5, -1.35), (0.7, -0.95)] if clap else [(0.6, -1.3), (1.35, -0.9), (1.25, -0.65), (0.6, -0.95)]
|
|
s.append(P([at(x, y) for x, y in fl]))
|
|
s.append(K("yellow"))
|
|
s.append(C(*at(0.3, -2.92), 0.1))
|
|
s.append(L([at(0.75, -3.05), at(1.05, -2.95)], 0.04))
|
|
s.append(L([at(0.72, -2.98), at(0.98, -2.8)], 0.04))
|
|
if clap:
|
|
s += rays(*at(1.55, -1.5), 0.3, 0.7, 5, -1.2, 0.07)
|
|
nx, ny = at(0.8, -3.32) # the nose tip
|
|
if i < 6: # the ball on its nose
|
|
s.append(K("red"))
|
|
s.append(C(nx, ny - 0.5, 0.5))
|
|
s.append(K("yellow"))
|
|
s.append(P([(nx - 0.12, ny - 1.0), (nx + 0.12, ny - 1.0), (nx + 0.12, ny), (nx - 0.12, ny)]))
|
|
elif i < 11: # flipped up, spinning, until it bursts
|
|
k = i - 6
|
|
yy = ny - 0.5 - 1.3 * k + 0.08 * k * k
|
|
s.append(K("red"))
|
|
s.append(C(nx + 0.2 * k, yy, 0.5))
|
|
s.append(K("yellow"))
|
|
s.append(P(rotate([(nx + 0.2 * k - 0.12, yy - 0.5), (nx + 0.2 * k + 0.12, yy - 0.5), (nx + 0.2 * k + 0.12, yy + 0.5),
|
|
(nx + 0.2 * k - 0.12, yy + 0.5)], k * 0.8, nx + 0.2 * k, yy)))
|
|
else:
|
|
k = i - 11
|
|
if k <= 2:
|
|
s.append(K("yellow"))
|
|
s.append(P(star(nx + 1.0, ny - 5.3, 1.5 - 0.3 * k, 0.6, 9, i)))
|
|
u = min(1.0, k / 4)
|
|
h = 1.45
|
|
land = ny - h / 2 - 0.15
|
|
y = (ny - 5.3) + (land - (ny - 5.3)) * u * u
|
|
x = nx + 1.0 * (1 - u)
|
|
rot = (1 - u) * 1.2 + (0.18 * math.sin((k - 4) * 1.4) if u >= 1 else 0)
|
|
if k == 5:
|
|
y += 0.18
|
|
s.append(K("red"))
|
|
s.append(NUM(x, y, h, rot=rot))
|
|
if 4 <= k <= 6:
|
|
s.append(K("yellow"))
|
|
s += rays(nx, ny - 0.1, 0.25, 0.55, 4, 0.3, 0.07)
|
|
if k >= 4:
|
|
s.append(K("yellow"))
|
|
for m in range(4):
|
|
a = m * 1.6 + i * 0.4
|
|
s.append(P(star(nx + 2.4 * math.cos(a) * 1.1, land + 0.6 * math.sin(a) - 0.2, 0.25, 0.1, 5, i * 0.3)))
|
|
return s
|
|
|
|
|
|
def slinky(i, t):
|
|
"""A slinky walks itself down a staircase of toy blocks, end over end, lands by the box, and boings up tall to fling the number high."""
|
|
s = []
|
|
bs = 1.3 # a block's size
|
|
cols = [(-3.6, 3), (-2.3, 2), (-1.0, 1)]
|
|
for c, (x, n) in enumerate(cols): # the blocks
|
|
for m in range(n):
|
|
col = ["red", "blue", "yellow"][(c + m) % 3]
|
|
y0 = 0.5 - m * bs
|
|
s.append(K(col))
|
|
s.append(P([(x - bs / 2, y0), (x + bs / 2, y0), (x + bs / 2, y0 - bs + 0.04), (x - bs / 2, y0 - bs + 0.04)], 0, 0.03))
|
|
s.append(K("yellow" if col != "yellow" else "red"))
|
|
s.append(P([(x - bs / 2 + 0.2, y0 - 0.2), (x + bs / 2 - 0.2, y0 - 0.2), (x + bs / 2 - 0.2, y0 - bs + 0.24),
|
|
(x - bs / 2 + 0.2, y0 - bs + 0.24)], 0.06, 0.03))
|
|
steps = [(-3.6, 0.5 - 3 * bs), (-2.3, 0.5 - 2 * bs), (-1.0, 0.5 - bs), (1.5, 0.5)]
|
|
fw = 0.6 # the slinky's half width
|
|
|
|
def coil(pts, turns):
|
|
"""A spring drawn along the path pts: a tight zigzag across it, turns loops long."""
|
|
n = len(pts)
|
|
out = []
|
|
ns = int(turns * 10)
|
|
for k in range(ns):
|
|
u = k / (ns - 1)
|
|
f = u * (n - 1)
|
|
m = min(n - 2, int(f))
|
|
fr = f - m
|
|
x = pts[m][0] + (pts[m + 1][0] - pts[m][0]) * fr
|
|
y = pts[m][1] + (pts[m + 1][1] - pts[m][1]) * fr
|
|
dx, dy = pts[m + 1][0] - pts[m][0], pts[m + 1][1] - pts[m][1]
|
|
d = math.hypot(dx, dy) or 1
|
|
w = fw * math.sin(2 * math.pi * turns * u)
|
|
out.append((x - dy / d * w + 0.12 * dx / d * math.cos(2 * math.pi * turns * u),
|
|
y + dx / d * w + 0.12 * dy / d * math.cos(2 * math.pi * turns * u)))
|
|
return L(out, 0.08, 0.02)
|
|
|
|
def arch(p0, p2, lift, n=14):
|
|
mx = (p0[0] + p2[0]) / 2
|
|
my = min(p0[1], p2[1]) - lift
|
|
return [((1 - u) ** 2 * p0[0] + 2 * u * (1 - u) * mx + u * u * p2[0],
|
|
(1 - u) ** 2 * p0[1] + 2 * u * (1 - u) * my + u * u * p2[1]) for u in [k / (n - 1) for k in range(n)]]
|
|
s.append(K("blue"))
|
|
if i < 15: # walking: the back end flips over to the next step
|
|
st, ph = i // 5, (i % 5) / 4
|
|
a, b = steps[st], steps[st + 1]
|
|
ang = math.pi * ph # the moving end's swing, back over front
|
|
fx = a[0] + (b[0] - a[0]) * (1 - math.cos(ang)) / 2
|
|
fy = min(a[1], b[1]) - 1.6 * math.sin(ang) + (b[1] - a[1]) * ph * ph * (1 if b[1] > a[1] else 0)
|
|
if ph == 0:
|
|
fx, fy = a[0], a[1]
|
|
p0, p2 = (a[0], a[1] - 0.15), (fx, fy - 0.15)
|
|
if ph == 0: # a squat stack sitting on the step
|
|
s.append(coil([(a[0], a[1] - 0.05), (a[0], a[1] - 0.85)], 5))
|
|
else:
|
|
s.append(coil(arch(p0, p2, 0.8 + 0.9 * math.sin(ang)), 12))
|
|
else: # landed: it boings up tall and springs back
|
|
x, y = steps[3]
|
|
hts = [0.8, 0.5, 2.6, 3.6, 3.0, 2.0, 1.2, 1.6, 1.3, 0.9, 1.1, 0.9]
|
|
h = hts[min(i - 15, len(hts) - 1)]
|
|
s.append(coil([(x, y - 0.05), (x + 0.1 * math.sin(i), y - 0.05 - h)], 4.5 + 2 * h))
|
|
if i >= 17:
|
|
g = pop_scale(t, 17 / 23, 0.12, 1.3)
|
|
ny = y - 3.0 - 2.0 * ease_out(min(1.0, (i - 17) / 3))
|
|
s.append(K("red"))
|
|
s.append(NUM(x + 0.2, ny, 1.75 * g, rot=0.1 * math.sin(i * 1.3)))
|
|
s.append(K("yellow"))
|
|
for m in range(6):
|
|
a = m * math.pi / 3 + i * 0.2
|
|
r = 2.3 + 0.2 * (i % 2)
|
|
s.append(P(star(x + 0.2 + r * 1.15 * math.cos(a), ny + r * 0.8 * math.sin(a), 0.32, 0.13, 5, i * 0.3)))
|
|
if i in (17, 18):
|
|
s.append(K("yellow"))
|
|
s += rays(x, y - h - 0.3, 0.4, 1.0, 7, -math.pi / 2 - 1.2, 0.08)
|
|
return s
|
|
|
|
|
|
def present(i, t):
|
|
"""A wrapped present sits on the box and hops, once, twice; then its lid blasts off and curly streamers shoot out with the number rising in the middle."""
|
|
s = []
|
|
hop = {4: -0.35, 5: -0.5, 6: -0.2, 8: -0.45, 9: -0.65, 10: -0.25}.get(i, 0.0)
|
|
sq = 0.88 if i in (3, 7, 11) else 1.0
|
|
wob = 0.08 * math.sin(i * 2.1) if i < 12 else 0.0
|
|
w, h = 1.25, 1.9 * sq
|
|
by = -0.45 + hop
|
|
s.append(P(rotate([(-w, by), (w, by), (w, by - h), (-w, by - h)], wob, 0, by)))
|
|
s.append(K("yellow"))
|
|
s.append(P(rotate([(-0.18, by), (0.18, by), (0.18, by - h), (-0.18, by - h)], wob, 0, by)))
|
|
s.append(P(rotate([(-w, by - h * 0.45), (w, by - h * 0.45), (w, by - h * 0.6), (-w, by - h * 0.6)], wob, 0, by)))
|
|
ly = by - h
|
|
if i < 12: # the lid and its bow
|
|
s.append(K("blue"))
|
|
s.append(P(rotate([(-w - 0.15, ly), (w + 0.15, ly), (w + 0.15, ly - 0.5), (-w - 0.15, ly - 0.5)], wob, 0, by)))
|
|
s.append(K("yellow"))
|
|
s.append(P(rotate([(-0.18, ly), (0.18, ly), (0.18, ly - 0.5), (-0.18, ly - 0.5)], wob, 0, by)))
|
|
bt = ly - 0.55
|
|
s.append(P(rotate([(0, bt), (-0.8, bt - 0.55), (-0.75, bt + 0.05)], wob, 0, by)))
|
|
s.append(P(rotate([(0, bt), (0.8, bt - 0.55), (0.75, bt + 0.05)], wob, 0, by)))
|
|
else:
|
|
k = i - 12
|
|
lx, lyy = 0.6 + 0.55 * k, ly - 0.6 - 1.1 * k + 0.08 * k * k
|
|
s.append(K("blue"))
|
|
s.append(P(rotate([(lx - 1.4, lyy), (lx + 1.4, lyy), (lx + 1.4, lyy - 0.5), (lx - 1.4, lyy - 0.5)], 0.5 * k, lx, lyy)))
|
|
if k < 2:
|
|
s.append(K("yellow"))
|
|
s.append(P(star(0, ly - 0.3, 2.0 - 0.4 * k, 0.8, 12, i)))
|
|
for m in range(6): # the streamers, curling out
|
|
side = -1 if m < 3 else 1
|
|
a = -math.pi / 2 + side * (0.55 + 0.32 * (m % 3))
|
|
n = min(9, 2 + k * 2)
|
|
pts = []
|
|
for q in range(n):
|
|
r = 0.4 + q * 0.42
|
|
wig = 0.25 * math.sin(q * 1.4 + i * 0.9 + m)
|
|
pts.append((side * 0.4 + r * math.cos(a) - wig * math.sin(a), ly + r * math.sin(a) + wig * math.cos(a) + q * q * 0.004 * k))
|
|
s.append(K(["red", "blue", "yellow"][m % 3]))
|
|
s.append(L(pts, 0.11))
|
|
g = pop_scale(t, 12 / 23, 0.15, 1.3)
|
|
y = ly - 0.8 - 2.0 * ease_out(min(1.0, k / 4))
|
|
s.append(K("red"))
|
|
s.append(NUM(0, y, 1.75 * g, rot=0.08 * math.sin(i * 1.2)))
|
|
return s
|
|
|
|
|
|
def blowout(i, t):
|
|
"""A party blower toots: its striped paper curl unrolls straight out, rolls half back, then shoots out fully with the number printed along it and its tassel flicking."""
|
|
s = []
|
|
mx, my = -2.8, -2.3 # the mouthpiece
|
|
base = -0.22 # the straight band's angle
|
|
seq = [0, 0, 0.1, 0.35, 0.65, 0.8, 0.6, 0.35, 0.3, 0.55, 0.85, 1.0, 1.05, 1.0]
|
|
u = seq[i] if i < len(seq) else 1.0 + 0.02 * math.sin(i * 1.5)
|
|
n, L_ = 16, 6.0
|
|
ds = L_ / n
|
|
wid = 1.9
|
|
cen = [(mx + 0.4 * math.cos(base), my + 0.4 * math.sin(base))]
|
|
a = base
|
|
for k in range(n):
|
|
f = k / n
|
|
if f > u: # curled part
|
|
a += 0.7 * min(1.0, (f - u) * 6 + 0.4)
|
|
x, y = cen[-1]
|
|
cen.append((x + ds * math.cos(a), y + ds * math.sin(a)))
|
|
for k in range(n): # draw segment by segment, alternating stripes
|
|
x0, y0 = cen[k]
|
|
x1, y1 = cen[k + 1]
|
|
dx, dy = (x1 - x0) / ds, (y1 - y0) / ds
|
|
nx_, ny_ = -dy * wid / 2, dx * wid / 2
|
|
taper = 1.0 - 0.15 * k / n
|
|
nx_, ny_ = nx_ * taper, ny_ * taper
|
|
f = k / n
|
|
striped = (f > u or k < 2 or k >= n - 2) and (k // 1) % 2 == 1
|
|
s.append(K("red" if striped else "yellow"))
|
|
s.append(P([(x0 + nx_, y0 + ny_), (x1 + nx_ * 1.02, y1 + ny_ * 1.02), (x1 - nx_ * 1.02, y1 - ny_ * 1.02), (x0 - nx_, y0 - ny_)], 0, 0.025))
|
|
s.append(K("blue")) # the mouthpiece
|
|
s.append(P(rotate([(mx - 0.9, my - 0.22), (mx + 0.45, my - 0.45), (mx + 0.45, my + 0.45), (mx - 0.9, my + 0.22)], base, mx, my)))
|
|
ex, ey = cen[-1]
|
|
if u > 0.5: # the tassel at the tip
|
|
s.append(K("blue"))
|
|
fl = 0.4 * math.sin(i * 2.2)
|
|
for q in range(3):
|
|
s.append(L([(ex, ey), (ex + 0.6, ey - 0.4 + q * 0.4 + fl)], 0.09))
|
|
if u >= 0.85:
|
|
mid = cen[n // 2 + 1]
|
|
hgt = 1.5 * min(1.0, (u - 0.85) / 0.15 + 0.3)
|
|
s.append(K("blue"))
|
|
s.append(NUM(mid[0], mid[1], hgt, rot=base + 0.04 * math.sin(i)))
|
|
if u > 0.3: # toot lines from the mouthpiece
|
|
s.append(K("red"))
|
|
s += rays(mx - 0.9, my, 0.5, 0.9 + 0.2 * (i % 2), 3, math.pi - 0.5, 0.08)
|
|
if i >= 11:
|
|
s.append(K("red"))
|
|
for m in range(5):
|
|
a2 = m * 1.25 + i * 0.25
|
|
px, py = ex + 0.9 * math.cos(a2), ey + 0.9 * math.sin(a2)
|
|
s.append(P(star(px, py, 0.2, 0.08, 5, i * 0.4)))
|
|
return s
|
|
|
|
|
|
ANIMS = [
|
|
(highstriker, "red", "dingaling"), (slamdunk, "blue", "swoosh"),
|
|
(strike, "yellow", "pinfall"), (gumball, "red", "crankle"),
|
|
(sealion, "blue", "arf"), (slinky, "blue", "slinkety"),
|
|
(present, "red", "unwrap"), (blowout, "yellow", "razz"),
|
|
]
|