v0.23.0: Routine, first public version
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
"""The drawing kit every animation module shares (tools/gen_animations.py and tools/streak_anims/*).
|
||||
|
||||
Coordinates: the origin (0, 0) is the checkbox's centre, one unit is the box's size, y points down
|
||||
(so "up out of the box" is negative y). An animation is a function fn(i, t) -> [shape, ...] called
|
||||
once per frame: i = the frame number, t = i / (frames - 1), 0..1. Every frame reseeds R (frames_of),
|
||||
so the random wobble ("boil") differs frame to frame but the output is the same on every run.
|
||||
|
||||
Shapes (what P, L, C, NUM return; the format of shared/animations.json):
|
||||
["p", w, x0, y0, x1, y1, ...] closed polygon; w = 0 filled, else stroke width
|
||||
["l", w, x0, y0, ...] open polyline, stroke width w (round caps)
|
||||
["c", w, cx, cy, r] circle; w = 0 filled, else stroke width
|
||||
["k", "<colour name>"] the shapes after it use that colour (red / blue / yellow)
|
||||
["n", w, cx, cy, h, rot] THE STREAK NUMBER, filled in by the painter (see NUM below and
|
||||
routine/gui/anim_paint.py DIGITS): its digits as round-capped
|
||||
strokes of width w, h tall, centred on (cx, cy), turned rot radians
|
||||
"""
|
||||
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
|
||||
FPS = 12
|
||||
N = 12
|
||||
COLORS = {"red": "#E8202A", "blue": "#1F5BD6", "yellow": "#FFC400"}
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
R = random.Random() # reseeded per frame: the boil differs frame to frame
|
||||
|
||||
|
||||
def j(v, amt=0.05):
|
||||
return v + R.uniform(-amt, amt)
|
||||
|
||||
|
||||
def P(pts, w=0, boil=0.05):
|
||||
out = ["p", w]
|
||||
for x, y in pts:
|
||||
out += [round(j(x, boil), 2), round(j(y, boil), 2)]
|
||||
return out
|
||||
|
||||
|
||||
def L(pts, w=0.18, boil=0.05):
|
||||
out = ["l", w]
|
||||
for x, y in pts:
|
||||
out += [round(j(x, boil), 2), round(j(y, boil), 2)]
|
||||
return out
|
||||
|
||||
|
||||
def C(x, y, r, w=0, boil=0.05):
|
||||
return ["c", w, round(j(x, boil), 2), round(j(y, boil), 2), round(max(0.02, j(r, boil * 0.6)), 2)]
|
||||
|
||||
|
||||
def ring(cx, cy, r, n=12, rot=0.0, wob=0.06):
|
||||
"""A hand-cut circle: a polygon whose radius wanders."""
|
||||
return [(cx + (r + R.uniform(-wob, wob)) * math.cos(rot + 2 * math.pi * k / n),
|
||||
cy + (r + R.uniform(-wob, wob)) * math.sin(rot + 2 * math.pi * k / n)) for k in range(n)]
|
||||
|
||||
|
||||
def star(cx, cy, r1, r2, n=5, rot=-math.pi / 2):
|
||||
pts = []
|
||||
for k in range(2 * n):
|
||||
r = r1 if k % 2 == 0 else r2
|
||||
a = rot + math.pi * k / n
|
||||
pts.append((cx + r * math.cos(a), cy + r * math.sin(a)))
|
||||
return pts
|
||||
|
||||
|
||||
def rotate(pts, ang, cx=0.0, cy=0.0):
|
||||
c, s = math.cos(ang), math.sin(ang)
|
||||
return [(cx + (x - cx) * c - (y - cy) * s, cy + (x - cx) * s + (y - cy) * c) for x, y in pts]
|
||||
|
||||
|
||||
def ease_out(t):
|
||||
return 1 - (1 - t) ** 2
|
||||
|
||||
|
||||
|
||||
# ── the calm sets' helpers: slower, gentler ──
|
||||
|
||||
CALM_FRAMES = 24
|
||||
CB = 0.025 # a gentler boil than the lively ones
|
||||
|
||||
|
||||
def cp(pts, w=0):
|
||||
return P(pts, w, CB)
|
||||
|
||||
|
||||
def cl(pts, w=0.12):
|
||||
return L(pts, w, CB)
|
||||
|
||||
|
||||
def cc(x, y, r, w=0):
|
||||
return C(x, y, r, w, CB)
|
||||
|
||||
|
||||
def wavy(x0, x1, y, amp, ph, n=10, k=2.0):
|
||||
return [(x0 + (x1 - x0) * m / n, y + amp * math.sin(ph + k * math.pi * m / n)) for m in range(n + 1)]
|
||||
|
||||
|
||||
def inout(t, edge=0.2):
|
||||
"""0 -> 1 over the first edge of the time, 1, then back to 0 over the last edge."""
|
||||
return max(0.0, min(1.0, t / edge, (1 - t) / edge))
|
||||
|
||||
|
||||
def oval(cx, cy, rx, ry, n=14, rot=0.0):
|
||||
return rotate([(cx + rx * math.cos(2 * math.pi * k / n), cy + ry * math.sin(2 * math.pi * k / n))
|
||||
for k in range(n)], rot, cx, cy)
|
||||
|
||||
|
||||
def steam(x, top, i, t, n=3, h=1.4):
|
||||
"""Soft curls of steam rising and thinning."""
|
||||
s = []
|
||||
g = inout(t, 0.3)
|
||||
for k in range(n):
|
||||
bx = x + (k - (n - 1) / 2) * 0.35
|
||||
pts = [(bx + 0.12 * math.sin(i * 0.4 + k + m * 1.2), top - 0.15 - m * h / 5) for m in range(6)]
|
||||
s.append(cl(pts, 0.03 + 0.07 * g))
|
||||
return s
|
||||
|
||||
|
||||
def frames_of(fn, n, seed):
|
||||
"""fn's n frames; R reseeded per frame from seed, so every run gives the same output."""
|
||||
out = []
|
||||
for i in range(n):
|
||||
R.seed(seed * 1000 + i)
|
||||
out.append(fn(i, i / (n - 1)))
|
||||
return out
|
||||
|
||||
|
||||
# ── the streak animations (tools/streak_anims): 2 s, 24 frames, each shows the streak number ──
|
||||
|
||||
STREAK_FRAMES = 24
|
||||
DIGIT_W, DIGIT_ADV = 0.6, 0.82 # a digit's width and advance, in digit heights (as anim_paint)
|
||||
|
||||
|
||||
def num_width(h, digits=2):
|
||||
"""How wide the number is drawn at height h with this many digits (for laying things out round it)."""
|
||||
return h * ((digits - 1) * DIGIT_ADV + DIGIT_W)
|
||||
|
||||
|
||||
def NUM(x, y, h, w=None, rot=0.0, boil=0.05):
|
||||
"""The streak number, h tall, centred on (x, y), turned rot radians. The app fills in the real
|
||||
number (7, 21, ..., 465, ...): lay things out for up to 3 digits (num_width(h, 3)).
|
||||
w = the stroke width (default h * 0.17). It boils like everything else."""
|
||||
w = h * 0.17 if w is None else w
|
||||
return ["n", round(w, 3), round(j(x, boil), 2), round(j(y, boil), 2), round(max(0.05, j(h, boil * 0.5)), 2),
|
||||
round(rot + R.uniform(-boil, boil) * 0.6, 3)]
|
||||
|
||||
|
||||
def K(name):
|
||||
"""Switch colour: the shapes after it are drawn in that primary (red / blue / yellow)."""
|
||||
return ["k", name]
|
||||
@@ -0,0 +1,218 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fill a scratch ROUTINE_HOME with a believable FAKE history, for testing without touching anyone's real data.
|
||||
|
||||
python3 tools/fake_history.py DIR [--days 400] [--seed 1] [--force]
|
||||
ROUTINE_HOME=DIR python3 -m routine
|
||||
|
||||
Writes DIR/schedule.json (its own made-up routine, FAKE_SCHEDULE below: blocks, sub-tasks, a
|
||||
weekend block, weekday-only tasks, calm tasks, a suggestion), DIR/routine.db (DAYS days up to today:
|
||||
ticks, skips, misses, sick days, notes of every length, a play log, long streaks with cheat days
|
||||
used) and DIR/config.json (no sync token: nothing syncs). Today is part done. A few tasks sit one tick short of a streak level today
|
||||
(it prints which), so ticking them by hand plays a streak animation. Deterministic per --seed.
|
||||
Never point it at the real data folder (~/.local/share/routine, ~/Library/Application Support/Routine): it refuses.
|
||||
"""
|
||||
import argparse
|
||||
import datetime as dt
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, ROOT)
|
||||
|
||||
WORDS = ("slept well tired team meeting long walk rain sun garden tomatoes friends dinner pasta phone call bike "
|
||||
"fixed the shelf read a chapter wrote code bug finally inbox zero coffee too much tea quiet day busy "
|
||||
"errands bank post office sore back stretched swam cold water laundry cleaned kitchen idea for a project "
|
||||
"talked with neighbours market bread cheese movie late night early start headache better now").split()
|
||||
FAKE_SCHEDULE = {"rev": 3, "dayStartsAt": 4, "blocks": [
|
||||
{"id": "am", "label": "Morning", "start": 7, "end": 9, "color": "#FFE08A", "items": [
|
||||
{"id": "water", "label": "glass of water"},
|
||||
{"id": "stretch", "label": "stretch", "items": [{"id": "tip", "label": "a few minutes is plenty", "hint": True}]},
|
||||
{"id": "plan", "label": "plan the day", "items": [
|
||||
{"id": "calendar", "label": "look at the calendar"},
|
||||
{"id": "three", "label": "pick three things", "items": [{"id": "small", "label": "one of them small"}]}]},
|
||||
{"id": "cat", "label": "feed the cat"},
|
||||
{"id": "tea", "label": "make tea"},
|
||||
{"id": "weather", "label": "check the weather"},
|
||||
{"id": "windows", "label": "open the windows"}]},
|
||||
{"id": "work", "label": "Work", "start": 9, "end": 17, "color": "#B8DAFF", "items": [
|
||||
{"id": "inbox", "label": "inbox"},
|
||||
{"id": "focus", "label": "focus hour", "items": [{"id": "drawer", "label": "phone in a drawer"}]},
|
||||
{"id": "standup", "label": "stand up and move"},
|
||||
{"id": "break", "label": "lunch break", "items": [{"id": "away", "label": "away from the desk"}]},
|
||||
{"id": "tomorrow", "label": "write tomorrow's list"},
|
||||
{"id": "plants", "label": "water the plants", "days": [1, 4]},
|
||||
{"id": "backup", "label": "back up the laptop", "days": [5]},
|
||||
{"id": "review", "label": "review the week", "days": [5]}]},
|
||||
{"id": "errands", "label": "Errands", "start": 17, "end": 19, "color": "#FFC9A8", "items": [
|
||||
{"id": "post", "label": "post and parcels"},
|
||||
{"id": "shop", "label": "groceries", "days": [2, 5], "items": [{"id": "bags", "label": "bring the bags"}]},
|
||||
{"id": "bins", "label": "bins out", "days": [3]}]},
|
||||
{"id": "weekend", "label": "Weekend", "start": 10, "end": 13, "color": "#B5EBC8", "days": [0, 6], "items": [
|
||||
{"id": "walk", "label": "long walk"},
|
||||
{"id": "friend", "label": "call a friend"}]},
|
||||
{"id": "eve", "label": "Evening", "start": 19, "end": 23, "color": "#D9C2FF", "items": [
|
||||
{"id": "cook", "label": "cook dinner"},
|
||||
{"id": "tidy", "label": "tidy the kitchen"},
|
||||
{"id": "wash", "label": "wash up"},
|
||||
{"id": "clothes", "label": "lay out clothes"},
|
||||
{"id": "floss", "label": "floss"},
|
||||
{"id": "alarm", "label": "set an alarm"},
|
||||
{"id": "charge", "label": "phone on charge, out of reach"},
|
||||
{"id": "lights", "label": "lights low"},
|
||||
{"id": "pages", "label": "a few pages of a book"}]}]}
|
||||
CALM = ["am/windows", "eve/lights", "eve/pages"] # marked calm in the fake schedule
|
||||
SHORT = [("am/water", 7), ("eve/cook", 21), ("work/inbox", 42), ("eve/pages", 7),
|
||||
("am/stretch", 66)] # one tick short of these today
|
||||
RELIABLE = ("am/water", "eve/floss") # done nearly every day
|
||||
LONG = "eve/floss" # a long streak with cheat days used
|
||||
|
||||
|
||||
def sentence(rng):
|
||||
n = rng.randint(4, 14)
|
||||
w = [rng.choice(WORDS) for _ in range(n)]
|
||||
return " ".join(w).capitalize() + rng.choice(".....!?")
|
||||
|
||||
|
||||
def note(rng):
|
||||
r = rng.random()
|
||||
if r < 0.35:
|
||||
return ""
|
||||
if r < 0.7:
|
||||
return sentence(rng)
|
||||
if r < 0.92:
|
||||
return " ".join(sentence(rng) for _ in range(rng.randint(2, 5)))
|
||||
return "\n\n".join(" ".join(sentence(rng) for _ in range(rng.randint(3, 6))) for _ in range(rng.randint(2, 4)))
|
||||
|
||||
|
||||
def fake_schedule():
|
||||
s = json.loads(json.dumps(FAKE_SCHEDULE))
|
||||
for b in s["blocks"]:
|
||||
for it in b["items"]:
|
||||
if b["id"] + "/" + it["id"] in CALM:
|
||||
it["calm"] = True
|
||||
return s
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
||||
ap.add_argument("dir")
|
||||
ap.add_argument("--days", type=int, default=400)
|
||||
ap.add_argument("--seed", type=int, default=1)
|
||||
ap.add_argument("--force", action="store_true", help="replace a fake routine.db already there")
|
||||
a = ap.parse_args()
|
||||
home = os.path.realpath(a.dir)
|
||||
from routine import system
|
||||
env = {k: v for k, v in os.environ.items() if k != "ROUTINE_HOME"}
|
||||
real = {os.path.realpath(f(plat, env)) for plat in ("linux", "darwin") for f in (system.data_dir, system.config_dir)}
|
||||
if home in real:
|
||||
raise SystemExit("refusing: that's the real data folder")
|
||||
os.makedirs(home, exist_ok=True)
|
||||
db = os.path.join(home, "routine.db")
|
||||
if os.path.exists(db):
|
||||
if not a.force:
|
||||
raise SystemExit("%s exists: --force to replace it" % db)
|
||||
os.remove(db)
|
||||
os.environ["ROUTINE_HOME"] = home
|
||||
from routine import model
|
||||
from routine.store import Store
|
||||
|
||||
rng = random.Random(a.seed)
|
||||
sch = fake_schedule()
|
||||
with open(os.path.join(home, "schedule.json"), "w") as f:
|
||||
json.dump(sch, f, indent=2)
|
||||
with open(os.path.join(home, "config.json"), "w") as f:
|
||||
json.dump({"sync_token": "", "sync_url": ""}, f)
|
||||
with open(os.path.join(ROOT, "shared", "animations.json")) as f:
|
||||
anims = json.load(f)
|
||||
names = [x["name"] for x in anims["animations"]]
|
||||
calm_names = [x["name"] for x in anims.get("calm", [])] or names
|
||||
|
||||
today = model.routine_date(sch)
|
||||
first = today - dt.timedelta(days=a.days - 1)
|
||||
days = []
|
||||
reliab = {}
|
||||
short = dict(SHORT)
|
||||
for k in range(a.days):
|
||||
d = first + dt.timedelta(days=k)
|
||||
day = model.new_day(sch, d)
|
||||
sick = rng.random() < 0.04
|
||||
lazy = rng.random() < 0.12 # an off day: more misses
|
||||
is_today = d == today
|
||||
tasks = [it for b in day["blocks"] for it in b["items"] if not it.get("hint")]
|
||||
hour = 7.0
|
||||
for it in tasks:
|
||||
iid = it["id"]
|
||||
if iid not in reliab:
|
||||
reliab[iid] = 0.97 if iid in RELIABLE else rng.uniform(0.45, 0.95)
|
||||
p = reliab[iid] * (0.15 if sick else 0.7 if lazy else 1.0)
|
||||
if is_today:
|
||||
p = p if hour < 12 else 0.0 # today: only the morning so far
|
||||
r = rng.random()
|
||||
s = model.DONE if r < p else model.SKIPPED if r < p + 0.04 else model.PENDING
|
||||
if s == model.PENDING and it["id"].count("/") > 1:
|
||||
parent = it["id"].rpartition("/")[0]
|
||||
if model.state(day, parent) == model.DONE: # ticked along with its parent
|
||||
s = model.DONE
|
||||
if s != model.PENDING:
|
||||
day["states"][iid] = {"s": s, "t": int(dt.datetime(d.year, d.month, d.day, int(hour) % 24).timestamp() * 1000)}
|
||||
hour += 0.25
|
||||
# the play log: one per task ticked by hand (not those ticked along with a parent)
|
||||
n = 0
|
||||
for it in tasks:
|
||||
iid = it["id"]
|
||||
par = iid.rpartition("/")[0]
|
||||
if model.state(day, iid) == model.DONE and not (par.count("/") and model.state(day, par) == model.DONE):
|
||||
lo, hi, set_no, _ = model.anim_set(n, anims["sets"])
|
||||
if it.get("calm"):
|
||||
pick, set_no = rng.choice(calm_names), model.CALM_SET
|
||||
else:
|
||||
pick = rng.choice(names[lo:hi])
|
||||
day.setdefault("plays", []).append({"t": day["states"][iid]["t"], "a": pick, "i": iid, "s": set_no})
|
||||
n += 1
|
||||
if not is_today:
|
||||
day["note"] = {"text": note(rng), "t": 1}
|
||||
days.append(day)
|
||||
|
||||
# streaks one short of a level today: done for the last (level - 1) days the task was on, and
|
||||
# two misses in a row before that (so no cheat day can join it to an older run); pending today
|
||||
for iid, level in short.items():
|
||||
on = [dd for dd in days[:-1] if any(it["id"] == iid for b in dd["blocks"] for it in b["items"])]
|
||||
if len(on) < level + 1:
|
||||
continue
|
||||
for dd in on[-(level - 1):]:
|
||||
dd["states"][iid] = {"s": model.DONE, "t": 1}
|
||||
for dd in on[-(level + 1):-(level - 1)]:
|
||||
dd["states"].pop(iid, None)
|
||||
dd["plays"] = [p for p in dd.get("plays", []) if p["i"] != iid]
|
||||
days[-1]["states"].pop(iid, None)
|
||||
days[-1]["plays"] = [p for p in days[-1].get("plays", []) if p["i"] != iid]
|
||||
# a long streak with cheat days used: LONG done nearly every day, a miss every ~30
|
||||
for m, dd in enumerate(days[:-1]):
|
||||
if any(it["id"] == LONG for b in dd["blocks"] for it in b["items"]):
|
||||
if m % 31 == 17:
|
||||
dd["states"].pop(LONG, None)
|
||||
else:
|
||||
dd["states"][LONG] = {"s": model.DONE, "t": 1}
|
||||
|
||||
store = Store(db)
|
||||
for dd in days:
|
||||
store.put(dd, dirty=False)
|
||||
store.set_meta("first_date", first.isoformat())
|
||||
h = model.history(days, today.isoformat())
|
||||
print("wrote %d fake days (%s .. %s) to %s" % (len(days), first, today, home))
|
||||
for iid, level in short.items():
|
||||
dd = json.loads(json.dumps(days[-1]))
|
||||
model.set_state(dd, iid, model.DONE)
|
||||
n = model.streak_ending(days[:-1] + [dd], iid, today.isoformat())
|
||||
print(" tick %-24s today -> streak %d%s" % (iid, n, " (calm)" if iid in CALM else ""))
|
||||
st = h.items.get(LONG)
|
||||
if st:
|
||||
print(" %s: current %d, longest %d, cheat days used %d" % (
|
||||
LONG, st.current, st.longest, sum(len(r.cheats) for r in st.runs)))
|
||||
print("run: ROUTINE_HOME=%s python3 -m routine" % home)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,941 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Synthesize the check-off sounds into shared/sounds/*.wav (22.05 kHz mono 16-bit, <= 1 s; the star's
|
||||
and the calm set's are 2 s, and the calm ones are written at under half the level).
|
||||
|
||||
Standard library only and deterministic. Each name matches an animation's "sound" in
|
||||
tools/gen_animations.py; the streak animations' sounds live beside them in
|
||||
tools/streak_anims/*_sounds.py (2 s; the calm streak ones written quiet like the calm set's).
|
||||
|
||||
Run: python3 tools/gen_sounds.py everything into shared/sounds
|
||||
python3 tools/gen_sounds.py --level 3 --out DIR only streak level 3's (or calm), into DIR/sounds
|
||||
"""
|
||||
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
|
||||
from sound_kit import (CALM_DUR, OUT, SR, TAU, add_bell, add_noise, add_pluck, add_tone, buf, # noqa: F401
|
||||
cbuf, ease_off, env, pad, soft_bell, write)
|
||||
|
||||
|
||||
# ── the twenty ────────────────────────────────────────────────────────────────
|
||||
|
||||
def plip():
|
||||
b = buf(0.7)
|
||||
for k, f in enumerate((523, 659, 784, 1047)):
|
||||
add_tone(b, k * 0.09, 0.3, f, f * 1.03, 0.35, d=0.08, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def whoosh():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0.0, 1.0, 0.7, a=0.35, d=0.25, lp0=0.03, lp1=0.6)
|
||||
add_tone(b, 0.0, 0.9, 90, 400, 0.15, a=0.3, d=0.3, shape="saw")
|
||||
return b
|
||||
|
||||
|
||||
def chime():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((1318, 1760, 2093)):
|
||||
add_bell(b, k * 0.07, f, 0.22, 0.35)
|
||||
return b
|
||||
|
||||
|
||||
def boing():
|
||||
b = buf(0.8)
|
||||
add_tone(b, 0, 0.75, 140, 520, 0.6, d=0.3, vib=(14, 0.18))
|
||||
return b
|
||||
|
||||
|
||||
def sproing():
|
||||
b = buf(0.9)
|
||||
add_tone(b, 0, 0.85, 900, 180, 0.45, d=0.35, shape="tri", vib=(22, 0.25))
|
||||
add_noise(b, 0, 0.05, 0.3, d=0.02, lp0=0.8)
|
||||
return b
|
||||
|
||||
|
||||
def pop():
|
||||
b = buf(0.5)
|
||||
add_tone(b, 0, 0.12, 900, 120, 0.7, a=0.001, d=0.03)
|
||||
add_noise(b, 0, 0.3, 0.6, a=0.001, d=0.04, lp0=0.9, lp1=0.2, seed=8)
|
||||
return b
|
||||
|
||||
|
||||
def fizzbang():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 0.45, 0.25, a=0.3, d=0.1, lp0=0.4, lp1=0.9, seed=4)
|
||||
add_tone(b, 0, 0.45, 300, 1600, 0.15, a=0.3, d=0.2, shape="saw")
|
||||
add_noise(b, 0.45, 0.55, 0.9, a=0.001, d=0.12, lp0=0.6, lp1=0.05, seed=5)
|
||||
add_tone(b, 0.45, 0.4, 110, 50, 0.6, a=0.001, d=0.1)
|
||||
return b
|
||||
|
||||
|
||||
def tweet():
|
||||
b = buf(0.8)
|
||||
for k in range(3):
|
||||
add_tone(b, 0.05 + k * 0.2, 0.12, 2400, 3600, 0.35, a=0.005, d=0.05, vib=(60, 0.05))
|
||||
add_tone(b, 0.17 + k * 0.2, 0.06, 3600, 2800, 0.25, a=0.002, d=0.03)
|
||||
return b
|
||||
|
||||
|
||||
def kalimba():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((587, 880, 740, 1175)):
|
||||
add_tone(b, k * 0.13, 0.6, f, amp=0.35, a=0.002, d=0.12)
|
||||
add_tone(b, k * 0.13, 0.2, f * 5.9, amp=0.06, a=0.001, d=0.02)
|
||||
return b
|
||||
|
||||
|
||||
def rattle():
|
||||
b = buf(0.9)
|
||||
rng = random.Random(9)
|
||||
for k in range(16):
|
||||
add_noise(b, k * 0.045 + rng.uniform(0, 0.02), 0.04, 0.5 * (1 - k / 18), a=0.001, d=0.008,
|
||||
lp0=rng.uniform(0.3, 0.9), seed=k)
|
||||
return b
|
||||
|
||||
|
||||
def wobble():
|
||||
b = buf(0.9)
|
||||
add_tone(b, 0, 0.85, 220, 300, 0.45, a=0.02, d=0.4, shape="tri", vib=(7, 0.22))
|
||||
return b
|
||||
|
||||
|
||||
def zap():
|
||||
b = buf(0.6)
|
||||
add_tone(b, 0, 0.35, 2400, 90, 0.45, a=0.001, d=0.12, shape="square")
|
||||
add_noise(b, 0, 0.2, 0.3, a=0.001, d=0.05, lp0=0.95, seed=2)
|
||||
return b
|
||||
|
||||
|
||||
def slide():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.95, 400, 1800, 0.45, a=0.03, d=0.6, vib=(6, 0.02))
|
||||
add_noise(b, 0, 0.95, 0.05, a=0.03, d=0.6, lp0=0.3)
|
||||
return b
|
||||
|
||||
|
||||
def thump():
|
||||
b = buf(1.0)
|
||||
for k, s in enumerate((0.0, 0.18, 0.5, 0.68)):
|
||||
add_tone(b, s, 0.2, 120 if k % 2 == 0 else 95, 50, 0.8, a=0.002, d=0.06)
|
||||
return b
|
||||
|
||||
|
||||
def splash():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.15, 500, 1400, 0.3, a=0.005, d=0.06)
|
||||
add_noise(b, 0.7, 0.3, 0.7, a=0.002, d=0.08, lp0=0.8, lp1=0.2, seed=11)
|
||||
add_tone(b, 0.7, 0.2, 700, 300, 0.2, a=0.002, d=0.05)
|
||||
return b
|
||||
|
||||
|
||||
def rise():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((262, 330, 392, 523, 659)):
|
||||
add_tone(b, k * 0.12, 0.5, f, amp=0.25, a=0.01, d=0.25, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def drip():
|
||||
b = buf(0.9)
|
||||
for k, s in enumerate((0.0, 0.25, 0.5)):
|
||||
add_tone(b, s, 0.1, 900 - k * 120, 2200 - k * 200, 0.45, a=0.001, d=0.035)
|
||||
return b
|
||||
|
||||
|
||||
def bloop():
|
||||
b = buf(0.7)
|
||||
add_tone(b, 0, 0.3, 160, 700, 0.6, a=0.005, d=0.1)
|
||||
add_tone(b, 0.3, 0.3, 200, 900, 0.45, a=0.005, d=0.08)
|
||||
return b
|
||||
|
||||
|
||||
def flutter():
|
||||
b = buf(1.0)
|
||||
for k in range(12):
|
||||
add_noise(b, k * 0.075, 0.05, 0.35, a=0.01, d=0.015, lp0=0.15 + 0.03 * (k % 3), seed=20 + k)
|
||||
add_tone(b, 0.1, 0.8, 1400, 1700, 0.08, a=0.1, d=0.5, vib=(13, 0.08))
|
||||
return b
|
||||
|
||||
|
||||
def boo():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.95, 300, 160, 0.35, a=0.15, d=0.5, shape="tri", vib=(5, 0.06))
|
||||
add_tone(b, 0, 0.95, 452, 241, 0.15, a=0.15, d=0.5, vib=(5, 0.06))
|
||||
add_noise(b, 0, 0.95, 0.08, a=0.15, d=0.5, lp0=0.1)
|
||||
return b
|
||||
|
||||
|
||||
# ── set 1 and set 2 ──
|
||||
|
||||
def ribbit():
|
||||
b = buf(0.7)
|
||||
for k in range(2):
|
||||
add_tone(b, k * 0.22, 0.16, 180, 140, 0.5, a=0.005, d=0.08, shape="square", vib=(30, 0.3))
|
||||
return b
|
||||
|
||||
|
||||
def squelch():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 0.9, 0.35, a=0.1, d=0.4, lp0=0.05, lp1=0.2, seed=40)
|
||||
add_tone(b, 0, 0.9, 120, 90, 0.25, a=0.1, d=0.4, vib=(9, 0.3))
|
||||
return b
|
||||
|
||||
|
||||
def mew():
|
||||
b = buf(0.8)
|
||||
add_tone(b, 0, 0.6, 700, 900, 0.4, a=0.04, d=0.25, shape="tri", vib=(6, 0.04))
|
||||
add_tone(b, 0.25, 0.35, 950, 600, 0.3, a=0.01, d=0.15, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def fwump():
|
||||
b = buf(0.7)
|
||||
add_tone(b, 0, 0.15, 300, 900, 0.2, a=0.01, d=0.06)
|
||||
add_noise(b, 0.12, 0.3, 0.8, a=0.002, d=0.07, lp0=0.4, lp1=0.05, seed=41)
|
||||
add_tone(b, 0.12, 0.25, 140, 70, 0.5, a=0.002, d=0.06)
|
||||
return b
|
||||
|
||||
|
||||
def swish():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 0.3, 0.5, a=0.1, d=0.08, lp0=0.1, lp1=0.7, seed=42)
|
||||
add_tone(b, 0.25, 0.5, 600, 1500, 0.2, a=0.05, d=0.2, vib=(4, 0.3))
|
||||
add_noise(b, 0.75, 0.25, 0.4, a=0.05, d=0.08, lp0=0.6, lp1=0.1, seed=43)
|
||||
return b
|
||||
|
||||
|
||||
def breeze():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 1.0, 0.5, a=0.3, d=0.5, lp0=0.04, lp1=0.12, seed=44)
|
||||
for k, f in enumerate((660, 880, 990)):
|
||||
add_tone(b, 0.2 + k * 0.2, 0.4, f, amp=0.12, a=0.02, d=0.15, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def tinkle():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((2637, 3136, 2349, 3520, 2794, 4186)):
|
||||
add_bell(b, k * 0.11, f, 0.12, 0.2)
|
||||
return b
|
||||
|
||||
|
||||
def patter():
|
||||
b = buf(1.0)
|
||||
rng = random.Random(45)
|
||||
for k in range(22):
|
||||
st = rng.uniform(0.15, 0.95)
|
||||
add_tone(b, st, 0.05, rng.uniform(1500, 2600), rng.uniform(800, 1200), 0.18, a=0.001, d=0.012)
|
||||
add_noise(b, 0, 0.2, 0.15, a=0.05, d=0.1, lp0=0.1, seed=46)
|
||||
return b
|
||||
|
||||
|
||||
def lullaby():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((784, 659, 784, 1047)):
|
||||
add_tone(b, k * 0.2, 0.5, f, amp=0.25, a=0.03, d=0.2, vib=(5, 0.01))
|
||||
add_tone(b, k * 0.2, 0.4, f * 2, amp=0.05, a=0.03, d=0.1)
|
||||
return b
|
||||
|
||||
|
||||
def creak():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.6, 90, 160, 0.35, a=0.02, d=0.4, shape="saw", vib=(23, 0.15))
|
||||
for k, f in enumerate((392, 494, 587, 784)):
|
||||
add_tone(b, 0.55 + k * 0.08, 0.3, f, amp=0.15, a=0.005, d=0.08, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def pomp():
|
||||
b = buf(0.7)
|
||||
for k, (f0, f1) in enumerate(((120, 260), (180, 380), (240, 520))):
|
||||
add_tone(b, k * 0.15, 0.15, f0, f1, 0.45, a=0.003, d=0.06)
|
||||
return b
|
||||
|
||||
|
||||
def rumble():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 1.0, 0.9, a=0.05, d=0.45, lp0=0.015, lp1=0.04, seed=47)
|
||||
add_tone(b, 0, 1.0, 55, 40, 0.5, a=0.05, d=0.4)
|
||||
for k in range(4):
|
||||
add_noise(b, 0.3 + k * 0.13, 0.08, 0.35, a=0.001, d=0.03, lp0=0.4, seed=48 + k)
|
||||
return b
|
||||
|
||||
|
||||
def spout():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.4, 70, 110, 0.4, a=0.08, d=0.2, vib=(3, 0.1))
|
||||
add_noise(b, 0.35, 0.65, 0.6, a=0.03, d=0.3, lp0=0.7, lp1=0.2, seed=52)
|
||||
return b
|
||||
|
||||
|
||||
def warble():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.95, 500, 1100, 0.35, a=0.1, d=0.6, vib=(9, 0.12))
|
||||
add_tone(b, 0, 0.95, 1000, 2200, 0.1, a=0.1, d=0.6, vib=(9, 0.12))
|
||||
return b
|
||||
|
||||
|
||||
def clack():
|
||||
b = buf(0.9)
|
||||
for k in range(6):
|
||||
add_noise(b, k * 0.13, 0.03, 0.6, a=0.0005, d=0.006, lp0=0.95, seed=53 + k)
|
||||
add_tone(b, k * 0.13, 0.04, 2200 if k % 2 else 1800, amp=0.3, a=0.0005, d=0.008)
|
||||
return b
|
||||
|
||||
|
||||
def tune():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((523, 659, 587, 784, 698, 880)):
|
||||
add_tone(b, k * 0.13, 0.25, f, amp=0.3, a=0.005, d=0.09, shape="square")
|
||||
return b
|
||||
|
||||
|
||||
def whirr():
|
||||
b = buf(1.0)
|
||||
for k in range(16):
|
||||
add_noise(b, k * 0.055, 0.05, 0.3 + 0.01 * k, a=0.005, d=0.02, lp0=0.2 + k * 0.03, seed=60 + k)
|
||||
add_tone(b, 0, 0.9, 300, 700, 0.1, a=0.1, d=0.5, shape="saw")
|
||||
return b
|
||||
|
||||
|
||||
def blub():
|
||||
b = buf(0.9)
|
||||
for k, s0 in enumerate((0.0, 0.18, 0.4, 0.55)):
|
||||
add_tone(b, s0, 0.09, 400 + k * 90, 1200 + k * 200, 0.4, a=0.002, d=0.03)
|
||||
add_noise(b, 0.75, 0.1, 0.3, a=0.001, d=0.02, lp0=0.9, seed=77)
|
||||
return b
|
||||
|
||||
|
||||
def thunk():
|
||||
b = buf(0.8)
|
||||
add_noise(b, 0, 0.3, 0.25, a=0.05, d=0.06, lp0=0.2, lp1=0.6, seed=78)
|
||||
add_tone(b, 0.3, 0.3, 180, 90, 0.8, a=0.001, d=0.05)
|
||||
add_tone(b, 0.32, 0.45, 330, 330, 0.2, a=0.001, d=0.12, vib=(18, 0.08))
|
||||
return b
|
||||
|
||||
|
||||
def clatter():
|
||||
b = buf(1.0)
|
||||
rng = random.Random(79)
|
||||
for k in range(10):
|
||||
st = 0.05 + k * 0.08 + rng.uniform(-0.02, 0.02)
|
||||
add_noise(b, st, 0.03, 0.5 * (1 - k / 14), a=0.0005, d=0.01, lp0=0.8, seed=80 + k)
|
||||
add_tone(b, st, 0.05, rng.uniform(900, 1400), amp=0.2, a=0.0005, d=0.015)
|
||||
return b
|
||||
|
||||
|
||||
def trickle():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 1.0, 0.25, a=0.2, d=0.6, lp0=0.5, lp1=0.3, seed=90)
|
||||
for k, f in enumerate((1200, 1000, 800)):
|
||||
add_bell(b, 0.1 + k * 0.3, f, 0.1, 0.15)
|
||||
return b
|
||||
|
||||
|
||||
def sparkle():
|
||||
b = buf(1.0)
|
||||
rng = random.Random(91)
|
||||
for k in range(9):
|
||||
add_bell(b, k * 0.09, rng.choice((2093, 2637, 3136, 4186)), 0.1, 0.12)
|
||||
return b
|
||||
|
||||
|
||||
def click():
|
||||
b = buf(0.6)
|
||||
add_noise(b, 0, 0.02, 0.8, a=0.0005, d=0.004, lp0=0.95, seed=92)
|
||||
add_noise(b, 0.12, 0.02, 0.9, a=0.0005, d=0.004, lp0=0.95, seed=93)
|
||||
add_tone(b, 0.15, 0.4, 660, 990, 0.25, a=0.005, d=0.12, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def fanfare():
|
||||
b = buf(1.0)
|
||||
for k, (st, f, dur) in enumerate(((0, 523, 0.12), (0.13, 523, 0.12), (0.26, 523, 0.12), (0.4, 784, 0.55))):
|
||||
add_tone(b, st, dur, f, amp=0.3, a=0.01, d=0.3, shape="saw")
|
||||
add_tone(b, st, dur, f * 1.5, amp=0.1, a=0.01, d=0.3, shape="saw")
|
||||
return b
|
||||
|
||||
|
||||
def regal():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((392, 523, 659)):
|
||||
add_tone(b, k * 0.06, 0.9, f, amp=0.2, a=0.02, d=0.4, shape="tri")
|
||||
add_bell(b, 0.4, 1568, 0.15, 0.3)
|
||||
return b
|
||||
|
||||
|
||||
def shimmer():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((523, 587, 659, 698, 784, 880, 988, 1047)):
|
||||
add_tone(b, k * 0.09, 0.3, f, amp=0.18, a=0.01, d=0.15, vib=(12, 0.01))
|
||||
return b
|
||||
|
||||
|
||||
def howl():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 1.0, 0.6, a=0.2, d=0.5, lp0=0.05, lp1=0.25, seed=94)
|
||||
add_tone(b, 0, 1.0, 300, 500, 0.1, a=0.2, d=0.5, vib=(2, 0.2))
|
||||
return b
|
||||
|
||||
|
||||
def buzz():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.95, 220, 260, 0.3, a=0.03, d=0.6, shape="saw", vib=(7, 0.1))
|
||||
return b
|
||||
|
||||
|
||||
def squeak():
|
||||
b = buf(0.8)
|
||||
for k in range(3):
|
||||
add_tone(b, k * 0.22, 0.08, 3000, 4200, 0.3, a=0.002, d=0.03)
|
||||
return b
|
||||
|
||||
|
||||
def cheep():
|
||||
b = buf(1.0)
|
||||
for k, st in enumerate((0.0, 0.08, 0.16)):
|
||||
add_noise(b, st, 0.02, 0.4, a=0.0005, d=0.005, lp0=0.9, seed=95 + k)
|
||||
for k in range(2):
|
||||
add_tone(b, 0.5 + k * 0.2, 0.1, 2600, 3400, 0.35, a=0.003, d=0.04)
|
||||
return b
|
||||
|
||||
|
||||
def twinkle():
|
||||
"""The star's own sound: a 2-second rising sparkle that blooms into a chord."""
|
||||
b = buf(2.0)
|
||||
notes_ = (523, 659, 784, 1047, 1319, 1568, 2093)
|
||||
for k, f in enumerate(notes_):
|
||||
add_bell(b, k * 0.11, f, 0.18, 0.3)
|
||||
for f in (523, 659, 784, 1047):
|
||||
add_tone(b, 0.9, 1.1, f, amp=0.12, a=0.05, d=0.5, vib=(5, 0.006))
|
||||
rng = random.Random(99)
|
||||
for k in range(10):
|
||||
add_bell(b, 1.1 + k * 0.08, rng.choice((2637, 3136, 3520, 4186)), 0.07, 0.15)
|
||||
return b
|
||||
|
||||
|
||||
# ── set 0, second batch ──
|
||||
|
||||
def popple():
|
||||
b = buf(1.0)
|
||||
rng = random.Random(301)
|
||||
for k in range(7):
|
||||
st = k * 0.09 + rng.uniform(0, 0.03)
|
||||
add_noise(b, st, 0.05, 0.6, a=0.0005, d=0.012, lp0=0.7, seed=310 + k)
|
||||
add_tone(b, st, 0.06, rng.uniform(500, 800), 200, 0.3, a=0.0005, d=0.02)
|
||||
return b
|
||||
|
||||
|
||||
def zipzip():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.35, 300, 1400, 0.35, a=0.005, d=0.2, shape="tri")
|
||||
add_tone(b, 0.45, 0.15, 1400, 1500, 0.2, a=0.005, d=0.08, vib=(30, 0.05))
|
||||
add_tone(b, 0.62, 0.35, 1400, 300, 0.35, a=0.005, d=0.2, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def wubwub():
|
||||
b = buf(1.0)
|
||||
for k in range(3):
|
||||
add_tone(b, k * 0.3, 0.28, 150, 260, 0.45, a=0.06, d=0.12, vib=(5, 0.1))
|
||||
return b
|
||||
|
||||
|
||||
def streak():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.9, 3000, 700, 0.15, a=0.02, d=0.4)
|
||||
add_noise(b, 0, 0.9, 0.4, a=0.02, d=0.35, lp0=0.8, lp1=0.15, seed=320)
|
||||
for k, f in enumerate((1568, 2093)):
|
||||
add_bell(b, 0.05 + k * 0.08, f, 0.12, 0.2)
|
||||
return b
|
||||
|
||||
|
||||
def flap():
|
||||
b = buf(1.0)
|
||||
for k in range(7):
|
||||
add_noise(b, 0.2 + k * 0.1, 0.06, 0.45, a=0.005, d=0.02, lp0=0.25 + 0.05 * (k % 2), seed=330 + k)
|
||||
add_tone(b, 0, 0.25, 200, 600, 0.2, a=0.01, d=0.1)
|
||||
return b
|
||||
|
||||
|
||||
def ding():
|
||||
b = buf(1.0)
|
||||
add_bell(b, 0, 1760, 0.4, 0.45)
|
||||
add_bell(b, 0.12, 2637, 0.18, 0.3)
|
||||
return b
|
||||
|
||||
|
||||
def beepboop():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((880, 660, 990, 520, 1175)):
|
||||
add_tone(b, k * 0.14, 0.11, f, amp=0.28, a=0.002, d=0.08, shape="square")
|
||||
return b
|
||||
|
||||
|
||||
def chop():
|
||||
b = buf(1.0)
|
||||
for k in range(14):
|
||||
add_noise(b, k * 0.068, 0.05, 0.5, a=0.002, d=0.018, lp0=0.12, seed=340 + k)
|
||||
add_tone(b, k * 0.068, 0.05, 90, 70, 0.3, a=0.002, d=0.02)
|
||||
return b
|
||||
|
||||
|
||||
def lapping():
|
||||
b = buf(1.0)
|
||||
for k in range(3):
|
||||
add_noise(b, k * 0.3, 0.35, 0.45, a=0.1, d=0.1, lp0=0.05, lp1=0.25, seed=350 + k)
|
||||
add_tone(b, 0.1, 0.7, 520, 560, 0.08, a=0.1, d=0.4, vib=(3, 0.03))
|
||||
return b
|
||||
|
||||
|
||||
def twirl():
|
||||
b = buf(1.0)
|
||||
for k, f in enumerate((660, 784, 988, 1175, 988, 1175, 1319)):
|
||||
add_tone(b, k * 0.08, 0.25, f, amp=0.22, a=0.005, d=0.08, shape="tri", vib=(14, 0.02))
|
||||
return b
|
||||
|
||||
|
||||
def toot():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 0.25, 0.4, a=0.05, d=0.08, lp0=0.3, seed=360)
|
||||
add_tone(b, 0.3, 0.6, 440, 470, 0.4, a=0.02, d=0.35, shape="saw", vib=(6, 0.03))
|
||||
add_tone(b, 0.3, 0.6, 660, 700, 0.15, a=0.02, d=0.35, shape="saw", vib=(6, 0.03))
|
||||
return b
|
||||
|
||||
|
||||
def orbit():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.95, 330, 340, 0.3, a=0.1, d=0.6, vib=(4, 0.15))
|
||||
add_tone(b, 0, 0.95, 495, 505, 0.12, a=0.1, d=0.6, vib=(4, 0.15))
|
||||
return b
|
||||
|
||||
|
||||
def bonk():
|
||||
b = buf(0.9)
|
||||
for k, st in enumerate((0.15, 0.4, 0.66)):
|
||||
add_tone(b, st, 0.18, 500 + k * 60, 180, 0.55 + k * 0.1, a=0.001, d=0.05)
|
||||
add_noise(b, st, 0.03, 0.4, a=0.0005, d=0.01, lp0=0.6, seed=370 + k)
|
||||
add_bell(b, 0.7, 2349, 0.12, 0.15)
|
||||
return b
|
||||
|
||||
|
||||
def punch():
|
||||
b = buf(0.8)
|
||||
add_tone(b, 0, 0.25, 200, 900, 0.2, a=0.005, d=0.1, shape="tri", vib=(25, 0.2))
|
||||
add_noise(b, 0.25, 0.25, 0.9, a=0.001, d=0.05, lp0=0.5, lp1=0.08, seed=380)
|
||||
add_tone(b, 0.25, 0.25, 130, 60, 0.7, a=0.001, d=0.06)
|
||||
return b
|
||||
|
||||
|
||||
def plod():
|
||||
b = buf(1.0)
|
||||
for k in range(4):
|
||||
add_tone(b, 0.1 + k * 0.22, 0.12, 160 if k % 2 else 130, 90, 0.5, a=0.004, d=0.04, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def hoot():
|
||||
b = buf(1.0)
|
||||
for k, (st, d) in enumerate(((0.0, 0.25), (0.4, 0.45))):
|
||||
add_tone(b, st, d, 400, 360, 0.45, a=0.04, d=0.2, vib=(5, 0.02))
|
||||
add_noise(b, st, d, 0.06, a=0.04, d=0.2, lp0=0.08, seed=390 + k)
|
||||
return b
|
||||
|
||||
|
||||
def plop():
|
||||
b = buf(0.9)
|
||||
for k, st in enumerate((0.1, 0.35, 0.6)):
|
||||
add_tone(b, st, 0.12, 250 + k * 60, 900 + k * 100, 0.5, a=0.002, d=0.04)
|
||||
add_noise(b, st, 0.06, 0.2, a=0.001, d=0.02, lp0=0.3, seed=400 + k)
|
||||
return b
|
||||
|
||||
|
||||
def crackle():
|
||||
b = buf(1.0)
|
||||
rng = random.Random(410)
|
||||
for k in range(40):
|
||||
st = rng.uniform(0, 0.95)
|
||||
add_noise(b, st, 0.01, rng.uniform(0.2, 0.6), a=0.0003, d=0.003, lp0=0.95, seed=411 + k)
|
||||
add_noise(b, 0, 1.0, 0.08, a=0.1, d=0.6, lp0=0.6, seed=460)
|
||||
return b
|
||||
|
||||
|
||||
def dangle():
|
||||
b = buf(1.0)
|
||||
add_tone(b, 0, 0.35, 1400, 300, 0.3, a=0.005, d=0.2, shape="tri")
|
||||
add_tone(b, 0.35, 0.3, 300, 420, 0.3, a=0.005, d=0.12, vib=(16, 0.12))
|
||||
add_tone(b, 0.7, 0.3, 300, 1300, 0.3, a=0.005, d=0.15, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def floaty():
|
||||
b = buf(1.0)
|
||||
add_noise(b, 0, 0.12, 0.5, a=0.002, d=0.04, lp0=0.5, seed=470)
|
||||
for k, f in enumerate((784, 740, 659, 587, 523)):
|
||||
add_tone(b, 0.15 + k * 0.16, 0.35, f, amp=0.2, a=0.02, d=0.15, vib=(5, 0.02))
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [plip, whoosh, chime, boing, sproing, pop, fizzbang, tweet, kalimba, rattle,
|
||||
wobble, zap, slide, thump, splash, rise, drip, bloop, flutter, boo,
|
||||
ribbit, squelch, mew, fwump, swish, breeze, tinkle, patter, lullaby, creak,
|
||||
pomp, rumble, spout, warble, clack, tune, whirr, blub, thunk, clatter,
|
||||
trickle, sparkle, click, fanfare, regal, shimmer, howl, buzz, squeak, cheep,
|
||||
twinkle,
|
||||
popple, zipzip, wubwub, streak, flap, ding, beepboop, chop, lapping, twirl,
|
||||
toot, orbit, bonk, punch, plod, hoot, plop, crackle, dangle, floaty]
|
||||
|
||||
|
||||
# ── the calm set (added 2026-11-07): 2 s each, soft attacks, no bangs, written quieter ──
|
||||
|
||||
def hush():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.5, a=0.9, d=0.7, lp0=0.03, lp1=0.06, seed=1001)
|
||||
return b
|
||||
|
||||
|
||||
def paddle():
|
||||
b = cbuf()
|
||||
for k, st in enumerate((0.1, 1.0)):
|
||||
add_noise(b, st, 0.7, 0.4, a=0.15, d=0.2, lp0=0.08, lp1=0.03, seed=1010 + k)
|
||||
add_tone(b, st + 0.1, 0.6, 180, 150, 0.08, a=0.1, d=0.25)
|
||||
return b
|
||||
|
||||
|
||||
def unspool():
|
||||
b = cbuf()
|
||||
for k, f in enumerate((392, 349, 330, 294, 262)):
|
||||
add_tone(b, 0.05 + k * 0.35, 0.8, f, amp=0.18, a=0.03, d=0.25, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def glow():
|
||||
b = cbuf()
|
||||
pad(b, 0, 2.0, 220, 0.2, a=0.7, d=0.9)
|
||||
pad(b, 0.3, 1.7, 330, 0.12, a=0.6, d=0.8)
|
||||
return b
|
||||
|
||||
|
||||
def rustle():
|
||||
b = cbuf()
|
||||
for k in range(5):
|
||||
add_noise(b, k * 0.35, 0.6, 0.25, a=0.2, d=0.2, lp0=0.25, lp1=0.12, seed=1030 + k)
|
||||
return b
|
||||
|
||||
|
||||
def babble():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.3, a=0.4, d=1.0, lp0=0.1, seed=1040)
|
||||
rng = random.Random(1041)
|
||||
for k in range(10):
|
||||
st = rng.uniform(0.1, 1.7)
|
||||
f = rng.uniform(500, 900)
|
||||
add_tone(b, st, 0.08, f, f * 1.4, 0.06, a=0.01, d=0.03)
|
||||
return b
|
||||
|
||||
|
||||
def purr():
|
||||
b = cbuf()
|
||||
for k in range(int(2.0 * 25)):
|
||||
add_noise(b, k / 25, 0.03, 0.25 * (0.6 + 0.4 * math.sin(k * 0.25)), a=0.01, d=0.015, lp0=0.04, seed=1050 + k)
|
||||
add_tone(b, 0, 2.0, 55, amp=0.12, a=0.5, d=1.0)
|
||||
return b
|
||||
|
||||
|
||||
def nibble():
|
||||
b = cbuf()
|
||||
for k in range(9):
|
||||
add_noise(b, 0.6 + k * 0.11 + (0.3 if k > 4 else 0), 0.02, 0.2, a=0.001, d=0.006, lp0=0.4, seed=1060 + k)
|
||||
add_noise(b, 0, 0.5, 0.12, a=0.1, d=0.15, lp0=0.2, seed=1070)
|
||||
return b
|
||||
|
||||
|
||||
def coo():
|
||||
b = cbuf()
|
||||
for st, f0, f1, dur in ((0.1, 330, 300, 0.5), (0.75, 300, 280, 0.35), (1.15, 330, 290, 0.7)):
|
||||
add_tone(b, st, dur, f0, f1, 0.2, a=0.08, d=0.3, vib=(6, 0.01))
|
||||
return b
|
||||
|
||||
|
||||
def warmth():
|
||||
b = cbuf()
|
||||
for k, f in enumerate((262, 330, 392)):
|
||||
pad(b, k * 0.15, 2.0 - k * 0.15, f, 0.12, a=0.6, d=0.9)
|
||||
return b
|
||||
|
||||
|
||||
def waft():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.25, a=0.8, d=0.6, lp0=0.15, lp1=0.05, seed=1080)
|
||||
pad(b, 0.4, 1.6, 880, 0.04, a=0.5, d=0.5)
|
||||
return b
|
||||
|
||||
|
||||
def steep():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 0.8, 0.2, a=0.2, d=0.3, lp0=0.2, lp1=0.08, seed=1090)
|
||||
soft_bell(b, 0.7, 523, 0.12, 0.6)
|
||||
return b
|
||||
|
||||
|
||||
def flicker():
|
||||
b = cbuf()
|
||||
pad(b, 0, 2.0, 196, 0.12, a=0.6, d=1.0)
|
||||
rng = random.Random(1100)
|
||||
for k in range(8):
|
||||
add_noise(b, rng.uniform(0.2, 1.8), 0.015, 0.12, a=0.001, d=0.005, lp0=0.3, seed=1101 + k)
|
||||
return b
|
||||
|
||||
|
||||
def drift():
|
||||
b = cbuf()
|
||||
add_tone(b, 0.0, 0.9, 587, 523, 0.15, a=0.15, d=0.4, shape="tri")
|
||||
add_tone(b, 0.8, 1.2, 523, 440, 0.15, a=0.2, d=0.5, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
def sprinkle():
|
||||
b = cbuf()
|
||||
rng = random.Random(1110)
|
||||
for k in range(14):
|
||||
st = 0.3 + k * 0.1 + rng.uniform(-0.03, 0.03)
|
||||
f = rng.uniform(1200, 1900)
|
||||
add_tone(b, st, 0.1, f, f * 0.8, 0.05, a=0.002, d=0.03)
|
||||
add_noise(b, 0.3, 1.5, 0.1, a=0.3, d=0.6, lp0=0.3, seed=1111)
|
||||
return b
|
||||
|
||||
|
||||
def crickets():
|
||||
b = cbuf()
|
||||
for k in range(6):
|
||||
st = 0.1 + k * 0.32
|
||||
for m in range(3):
|
||||
add_tone(b, st + m * 0.04, 0.03, 4200, amp=0.04, a=0.005, d=0.01)
|
||||
pad(b, 0, 2.0, 247, 0.06, a=0.7, d=1.0)
|
||||
return b
|
||||
|
||||
|
||||
def airy():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.2, a=0.6, d=0.7, lp0=0.4, lp1=0.2, seed=1120)
|
||||
soft_bell(b, 0.5, 1047, 0.06, 0.6)
|
||||
return b
|
||||
|
||||
|
||||
def still():
|
||||
b = cbuf()
|
||||
pad(b, 0, 2.0, 220, 0.18, a=0.5, d=1.2)
|
||||
pad(b, 0.6, 1.4, 330, 0.08, a=0.4, d=0.8)
|
||||
return b
|
||||
|
||||
|
||||
def sway():
|
||||
b = cbuf()
|
||||
pad(b, 0, 2.0, 174, 0.18, a=0.6, d=1.0, vib=(0.8, 0.02))
|
||||
pad(b, 0, 2.0, 261, 0.08, a=0.8, d=1.0, vib=(0.6, 0.02))
|
||||
return b
|
||||
|
||||
|
||||
def tingle():
|
||||
b = cbuf()
|
||||
for k, f in enumerate((784, 659, 880, 587)):
|
||||
soft_bell(b, 0.1 + k * 0.38, f, 0.1, 0.5)
|
||||
return b
|
||||
|
||||
|
||||
def airflow():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.35, a=1.0, d=0.6, lp0=0.02, lp1=0.08, seed=1130)
|
||||
return b
|
||||
|
||||
|
||||
def drone():
|
||||
b = cbuf()
|
||||
for f in (110, 110.6, 165, 165.9):
|
||||
pad(b, 0, 2.0, f, 0.1, a=0.7, d=1.0)
|
||||
return b
|
||||
|
||||
|
||||
def surf():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.4, a=0.8, d=0.5, lp0=0.04, lp1=0.15, seed=1140)
|
||||
add_noise(b, 0.9, 1.1, 0.15, a=0.1, d=0.5, lp0=0.4, lp1=0.1, seed=1141)
|
||||
return b
|
||||
|
||||
|
||||
def foghorn():
|
||||
b = cbuf()
|
||||
pad(b, 0.05, 1.9, 98, 0.25, a=0.5, d=0.8, shape="tri")
|
||||
pad(b, 0.05, 1.9, 147, 0.08, a=0.6, d=0.7)
|
||||
return b
|
||||
|
||||
|
||||
def flit():
|
||||
b = cbuf()
|
||||
for k in range(12):
|
||||
add_noise(b, 0.2 + k * 0.13, 0.06, 0.12, a=0.01, d=0.03, lp0=0.12, seed=1150 + k)
|
||||
return b
|
||||
|
||||
|
||||
def inhale():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 1.0, 0.3, a=0.8, d=0.1, lp0=0.05, lp1=0.15, seed=1160)
|
||||
add_noise(b, 1.0, 1.0, 0.3, a=0.05, d=0.4, lp0=0.12, lp1=0.04, seed=1161)
|
||||
return b
|
||||
|
||||
|
||||
def sand():
|
||||
b = cbuf()
|
||||
for k in range(5):
|
||||
add_noise(b, k * 0.38, 0.33, 0.25, a=0.08, d=0.15, lp0=0.5, lp1=0.3, seed=1170 + k)
|
||||
return b
|
||||
|
||||
|
||||
def stack():
|
||||
b = cbuf()
|
||||
for k, st in enumerate((0.2, 0.6, 1.0, 1.4)):
|
||||
add_tone(b, st, 0.2, 220 + k * 30, 200 + k * 30, 0.2, a=0.003, d=0.05, shape="tri")
|
||||
add_noise(b, st, 0.05, 0.08, a=0.001, d=0.02, lp0=0.15, seed=1180 + k)
|
||||
return b
|
||||
|
||||
|
||||
def dew():
|
||||
b = cbuf()
|
||||
add_tone(b, 0.3, 0.3, 700, 1100, 0.12, a=0.005, d=0.08)
|
||||
pad(b, 0.3, 1.7, 349, 0.1, a=0.4, d=0.8)
|
||||
return b
|
||||
|
||||
|
||||
def yawn():
|
||||
b = cbuf()
|
||||
add_tone(b, 0.1, 1.8, 330, 165, 0.2, a=0.4, d=0.8, shape="tri", vib=(4, 0.01))
|
||||
return b
|
||||
|
||||
|
||||
def glide():
|
||||
b = cbuf()
|
||||
add_tone(b, 0, 2.0, 262, 294, 0.15, a=0.5, d=1.0, vib=(1.5, 0.01))
|
||||
add_noise(b, 0, 2.0, 0.1, a=0.6, d=0.8, lp0=0.06, seed=1190)
|
||||
return b
|
||||
|
||||
|
||||
def celesta():
|
||||
b = cbuf()
|
||||
for k, f in enumerate((1047, 1319, 1568, 1319, 1760)):
|
||||
soft_bell(b, 0.1 + k * 0.32, f, 0.07, 0.4)
|
||||
return b
|
||||
|
||||
|
||||
def ooze():
|
||||
b = cbuf()
|
||||
add_tone(b, 0, 1.9, 196, 147, 0.18, a=0.4, d=0.9)
|
||||
add_tone(b, 1.5, 0.4, 300, 200, 0.05, a=0.02, d=0.1)
|
||||
return b
|
||||
|
||||
|
||||
def stitch():
|
||||
b = cbuf()
|
||||
for k in range(8):
|
||||
add_noise(b, 0.15 + k * 0.22, 0.04, 0.12, a=0.002, d=0.012, lp0=0.35, seed=1200 + k)
|
||||
add_tone(b, 0.15 + k * 0.22, 0.05, 900, amp=0.02, a=0.002, d=0.015)
|
||||
return b
|
||||
|
||||
|
||||
def page():
|
||||
b = cbuf()
|
||||
add_noise(b, 0.4, 0.9, 0.3, a=0.35, d=0.2, lp0=0.15, lp1=0.5, seed=1210)
|
||||
return b
|
||||
|
||||
|
||||
def embers():
|
||||
b = cbuf()
|
||||
add_noise(b, 0, 2.0, 0.2, a=0.5, d=1.0, lp0=0.04, seed=1220)
|
||||
rng = random.Random(1221)
|
||||
for k in range(10):
|
||||
add_noise(b, rng.uniform(0.1, 1.9), 0.01, rng.uniform(0.08, 0.18), a=0.0005, d=0.004, lp0=0.6, seed=1222 + k)
|
||||
return b
|
||||
|
||||
|
||||
def hum():
|
||||
b = cbuf()
|
||||
for f, a in ((262, 0.2), (264.5, 0.2), (705, 0.06), (708, 0.06)):
|
||||
add_tone(b, 0.05, 1.95, f, amp=a, a=0.3, d=1.2)
|
||||
return b
|
||||
|
||||
|
||||
def nestle():
|
||||
b = cbuf()
|
||||
for k in range(4):
|
||||
add_noise(b, 0.1 + k * 0.25, 0.2, 0.15, a=0.03, d=0.08, lp0=0.3, seed=1240 + k)
|
||||
pad(b, 0.8, 1.2, 294, 0.1, a=0.3, d=0.6)
|
||||
return b
|
||||
|
||||
|
||||
def seep():
|
||||
b = cbuf()
|
||||
add_tone(b, 0.15, 0.1, 900, 600, 0.06, a=0.005, d=0.04)
|
||||
pad(b, 0.25, 1.75, 165, 0.18, a=0.6, d=1.0, vib=(0.7, 0.02))
|
||||
return b
|
||||
|
||||
|
||||
def rocker():
|
||||
b = cbuf()
|
||||
for k, st in enumerate((0.0, 0.7, 1.35)):
|
||||
add_tone(b, st, 0.5, 140, 120, 0.12 * (1 - k * 0.25), a=0.12, d=0.2, shape="tri", vib=(9, 0.04))
|
||||
return b
|
||||
|
||||
|
||||
CALM_SOUNDS = [hush, paddle, unspool, glow, rustle, babble, purr, nibble, coo, warmth,
|
||||
waft, steep, flicker, drift, sprinkle, crickets, airy, still, sway, tingle,
|
||||
airflow, drone, surf, foghorn, flit, inhale, sand, stack, dew, yawn,
|
||||
glide, celesta, ooze, stitch, page, embers, hum, nestle, seep, rocker]
|
||||
|
||||
|
||||
def streak_sounds(strict=True, only=None):
|
||||
"""{key: [fn]} from tools/streak_anims/*_sounds.py (key = level number or "calm")."""
|
||||
import streak_anims
|
||||
return {k: list(m.SOUNDS) for k, m in streak_anims.load("_sounds", strict, only).items()}
|
||||
|
||||
|
||||
def write_streak(key, fns, out):
|
||||
for fn in fns:
|
||||
if key == "calm": # as quiet as the calm set's
|
||||
write(fn.__name__, ease_off(fn()), 0.3, out)
|
||||
else:
|
||||
write(fn.__name__, ease_off(fn(), 0.15), 0.7, out)
|
||||
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
ap = argparse.ArgumentParser(description="Synthesize the check-off sounds")
|
||||
ap.add_argument("--level", help="only this streak level's sounds (0-7, or calm)")
|
||||
ap.add_argument("--out", help="write into OUT/sounds/ instead of shared/sounds (always use it with --level)")
|
||||
a = ap.parse_args()
|
||||
only = None if a.level is None else ("calm" if a.level == "calm" else int(a.level))
|
||||
if only is not None and not a.out:
|
||||
raise SystemExit("--level writes only some sounds: give --out DIR (a scratch folder)")
|
||||
streak = streak_sounds(strict=only is None, only=only)
|
||||
names = [fn.__name__ for fn in SOUNDS + CALM_SOUNDS] + [fn.__name__ for k in streak for fn in streak[k]]
|
||||
dup = sorted({n for n in names if names.count(n) > 1})
|
||||
if dup:
|
||||
raise SystemExit("not unique: %s" % dup)
|
||||
out = os.path.join(a.out, "sounds") if a.out else OUT
|
||||
os.makedirs(out, exist_ok=True)
|
||||
if only is not None:
|
||||
write_streak(only, streak.get(only, []), out)
|
||||
print(f"wrote {len(streak.get(only, []))} streak sounds ({a.level}) to {out}")
|
||||
return
|
||||
for fn in SOUNDS:
|
||||
write(fn.__name__, fn(), out=out)
|
||||
for fn in CALM_SOUNDS: # quieter: they're for early mornings and late nights
|
||||
write(fn.__name__, ease_off(fn()), 0.3, out)
|
||||
for k in streak:
|
||||
write_streak(k, streak[k], out)
|
||||
print(f"wrote {len(SOUNDS)} sounds + {len(CALM_SOUNDS)} calm ones + "
|
||||
f"{sum(len(v) for v in streak.values())} streak ones to {out}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
"""shared/icon.svg → shared/icon.icns, the macOS app icon (runs anywhere Qt does: no Mac needed).
|
||||
|
||||
python3 tools/make_icns.py [--out shared/icon.icns]
|
||||
|
||||
Re-run after changing icon.svg. A Mac icon sits on a 1024 canvas with the artwork about 824 px
|
||||
across (Apple's grid), so it lines up with its neighbours in the Dock; the PNGs inside are the
|
||||
standard sizes macOS 10.7+ reads (ic07 … ic14). The .icns format is a list of (type, length, PNG).
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, ROOT)
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
from routine.qt.QtCore import QBuffer, QByteArray, QIODevice, QRectF, Qt # noqa: E402
|
||||
from routine.qt.QtGui import QGuiApplication, QIcon, QImage, QPainter # noqa: E402
|
||||
|
||||
# type → pixel size (ic11..ic14 are the @2x of 16, 32, 128, 256)
|
||||
TYPES = [(b"ic11", 32), (b"ic12", 64), (b"ic07", 128), (b"ic13", 256), (b"ic08", 256), (b"ic14", 512),
|
||||
(b"ic09", 512), (b"ic10", 1024)]
|
||||
ARTWORK = 824 / 1024
|
||||
|
||||
|
||||
def render(svg, px):
|
||||
img = QImage(px, px, QImage.Format.Format_ARGB32)
|
||||
img.fill(Qt.GlobalColor.transparent)
|
||||
p = QPainter(img)
|
||||
p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
p.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
|
||||
side = px * ARTWORK
|
||||
pm = QIcon(svg).pixmap(int(round(side)), int(round(side)))
|
||||
if pm.isNull():
|
||||
raise SystemExit("Qt couldn't draw %s (no SVG support in this Qt?)" % svg)
|
||||
p.drawPixmap(QRectF((px - side) / 2, (px - side) / 2, side, side), pm, QRectF(pm.rect()))
|
||||
p.end()
|
||||
data = QByteArray()
|
||||
buf = QBuffer(data)
|
||||
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||
img.save(buf, "PNG")
|
||||
buf.close()
|
||||
return bytes(data)
|
||||
|
||||
|
||||
def icns(entries):
|
||||
body = b"".join(t + struct.pack(">I", len(png) + 8) + png for t, png in entries)
|
||||
return b"icns" + struct.pack(">I", len(body) + 8) + body
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
||||
ap.add_argument("--svg", default=os.path.join(ROOT, "shared", "icon.svg"))
|
||||
ap.add_argument("--out", default=os.path.join(ROOT, "shared", "icon.icns"))
|
||||
a = ap.parse_args()
|
||||
app = QGuiApplication(sys.argv) # noqa: F841 — Qt needs one to draw
|
||||
cache = {}
|
||||
entries = []
|
||||
for t, px in TYPES:
|
||||
if px not in cache:
|
||||
cache[px] = render(a.svg, px)
|
||||
entries.append((t, cache[px]))
|
||||
with open(a.out, "wb") as f:
|
||||
f.write(icns(entries))
|
||||
print("wrote %s (%d bytes)" % (a.out, os.path.getsize(a.out)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Render animations.json to contact sheets: one row per animation, one column per frame.
|
||||
|
||||
python3 tools/preview_animations.py OUTDIR [--dark] [--only name,name] [--json PATH]
|
||||
[--streak K|calm] [--number N] [--every]
|
||||
writes OUTDIR/sheet00.png, ... (10 animations each), calm00.png, ... (every other frame), star.png,
|
||||
and streakK.png per streak level + streak_calm.png (every other frame; --every: all 24, in two rows),
|
||||
each with its "<n> days!" caption under it (from the frame its number first shows), fitted into the cell as the app fits it on screen.
|
||||
--json: read this animations.json (default shared/animations.json), e.g. one made with
|
||||
tools/gen_animations.py --level K --out DIR.
|
||||
--streak K|calm: only that streak level's sheet. --number N: the streak number drawn (default the
|
||||
level's own; calm: 21). Try --number 465 for the widest it gets.
|
||||
"""
|
||||
import json, os, sys
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from routine.qt.QtGui import QColor, QGuiApplication, QImage, QPainter, QPen
|
||||
from routine.gui.anim_paint import bounds, caption_h, caption_place, caption_start, fit, paint_caption, paint_frame
|
||||
|
||||
|
||||
def arg(name, default=None):
|
||||
return sys.argv[sys.argv.index(name) + 1] if name in sys.argv else default
|
||||
|
||||
|
||||
app = QGuiApplication(sys.argv)
|
||||
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
data = json.load(open(arg("--json", os.path.join(root, "shared", "animations.json"))))
|
||||
out = sys.argv[1]
|
||||
os.makedirs(out, exist_ok=True)
|
||||
only = arg("--only").split(",") if "--only" in sys.argv else None
|
||||
streak_only = arg("--streak")
|
||||
bg = QColor(48, 48, 48) if "--dark" in sys.argv else QColor(239, 239, 239)
|
||||
U, CW, CH = 14, 150, 150
|
||||
|
||||
|
||||
def sheet(anims, path, cols=12, number=None, cw=None, ch=None):
|
||||
CW, CH = cw or globals()["CW"], ch or globals()["CH"]
|
||||
img = QImage(CW * cols + 110, CH * len(anims), QImage.Format.Format_RGB32)
|
||||
img.fill(bg)
|
||||
p = QPainter(img)
|
||||
for r, a in enumerate(anims):
|
||||
p.setPen(QColor("#888"))
|
||||
p.drawText(6, r * CH + 20, a["name"])
|
||||
cap = None
|
||||
if number is not None: # the caption, and the whole of it fitted in the cell
|
||||
ch = a.get("_caption_h") or caption_h(a)
|
||||
cap = caption_place(bounds(a, number), number, False, ch)
|
||||
ub = cap[2]
|
||||
u = min(U, (CW - 8) / (ub[2] - ub[0]), (CH - 8) / (ub[3] - ub[1]))
|
||||
first = a.get("_first", 0)
|
||||
for c, fr in enumerate(a["frames"][:cols]):
|
||||
ox, oy = 110 + c * CW, r * CH
|
||||
p.setClipping(False)
|
||||
p.setPen(QColor("#bbb")); p.drawRect(ox, oy, CW - 1, CH - 1)
|
||||
p.setClipRect(ox, oy, CW, CH)
|
||||
bx, by = ox + CW // 3, oy + CH - 40
|
||||
if cap is None:
|
||||
p.setPen(QPen(QColor("#666"), 1)); p.drawRect(int(bx - U / 2), int(by - U / 2), U, U)
|
||||
paint_frame(p, fr, data["colors"][a["color"]], bx, by, U, data["colors"], number)
|
||||
continue
|
||||
bx = ox + fit(bx - ox, ub[0] * u, ub[2] * u, CW, 4)
|
||||
by = oy + fit(by - oy, ub[1] * u, ub[3] * u, CH, 4)
|
||||
p.setPen(QPen(QColor("#666"), 1)); p.drawRect(int(bx - u / 2), int(by - u / 2), int(u), int(u))
|
||||
paint_frame(p, fr, data["colors"][a["color"]], bx, by, u, data["colors"], number)
|
||||
paint_caption(p, number, data["colors"][a["color"]], bx, by, u, cap[:2], first + c * a.get("_step", 1), ch,
|
||||
a.get("_caption_start", 0))
|
||||
p.end()
|
||||
img.save(path)
|
||||
print("saved", path)
|
||||
|
||||
|
||||
def streak_sheet(anims, path, number):
|
||||
if "--every" in sys.argv:
|
||||
rows = []
|
||||
for a in anims:
|
||||
c = {"_caption_h": caption_h(a), "_caption_start": caption_start(a)}
|
||||
rows += [dict(a, frames=a["frames"][:12], **c),
|
||||
dict(a, name=a["name"] + " 13-24", frames=a["frames"][12:], _first=12, **c)]
|
||||
else:
|
||||
rows = [dict(a, frames=a["frames"][::2], _step=2, _caption_h=caption_h(a), _caption_start=caption_start(a))
|
||||
for a in anims]
|
||||
sheet(rows, path, number=number, cw=170, ch=200) # streak ones are bigger
|
||||
|
||||
|
||||
if streak_only is None:
|
||||
anims = [a for a in data["animations"] if not only or a["name"] in only]
|
||||
for k in range(0, len(anims), 10):
|
||||
sheet(anims[k:k + 10], os.path.join(out, "sheet%02d.png" % (k // 10)))
|
||||
calm = [a for a in data.get("calm", []) if not only or a["name"] in only]
|
||||
for k in range(0, len(calm), 10):
|
||||
sheet([dict(a, frames=a["frames"][::2]) for a in calm[k:k + 10]], os.path.join(out, "calm%02d.png" % (k // 10)))
|
||||
if "star" in data and not only:
|
||||
st = data["star"]
|
||||
sheet([dict(st, frames=st["frames"][:12]), dict(st, name="star 13-24", frames=st["frames"][12:])],
|
||||
os.path.join(out, "star.png"))
|
||||
|
||||
streak = data.get("streak") or {}
|
||||
for k, anims in enumerate(streak.get("sets", [])):
|
||||
anims = [a for a in anims if not only or a["name"] in only]
|
||||
if anims and streak_only in (None, str(k)):
|
||||
streak_sheet(anims, os.path.join(out, "streak%d.png" % k), int(arg("--number", streak["levels"][k])))
|
||||
calm = [a for a in streak.get("calm", []) if not only or a["name"] in only]
|
||||
if calm and streak_only in (None, "calm"):
|
||||
streak_sheet(calm, os.path.join(out, "streak_calm.png"), int(arg("--number", 21)))
|
||||
@@ -0,0 +1,136 @@
|
||||
"""The synth kit every sound module shares (tools/gen_sounds.py and tools/streak_anims/*_sounds.py).
|
||||
|
||||
22.05 kHz mono; a sound is a list of floats (buf), mixed into by the add_* helpers, then written
|
||||
normalised by write(). Standard library only, deterministic (seed every random source).
|
||||
"""
|
||||
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
import struct
|
||||
import wave
|
||||
|
||||
SR = 22050
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
OUT = os.path.join(ROOT, "shared", "sounds")
|
||||
TAU = 2 * math.pi
|
||||
|
||||
|
||||
def buf(dur):
|
||||
return [0.0] * int(SR * dur)
|
||||
|
||||
|
||||
def env(t, a, d):
|
||||
"""Attack a seconds, then exponential decay with time constant d."""
|
||||
return (t / a if t < a else math.exp(-(t - a) / d)) if a > 0 else math.exp(-t / d)
|
||||
|
||||
|
||||
def add_tone(b, start, dur, f0, f1=None, amp=0.5, a=0.005, d=0.15, shape="sine", vib=(0, 0)):
|
||||
"""A tone gliding f0 -> f1 (exponentially), with optional vibrato (rate Hz, depth ratio)."""
|
||||
f1 = f1 or f0
|
||||
ph = 0.0
|
||||
n0 = int(start * SR)
|
||||
for k in range(int(dur * SR)):
|
||||
if n0 + k >= len(b):
|
||||
break
|
||||
t = k / SR
|
||||
f = f0 * (f1 / f0) ** (t / dur)
|
||||
if vib[0]:
|
||||
f *= 1 + vib[1] * math.sin(TAU * vib[0] * t)
|
||||
ph += TAU * f / SR
|
||||
if shape == "sine":
|
||||
v = math.sin(ph)
|
||||
elif shape == "tri":
|
||||
v = 2 / math.pi * math.asin(math.sin(ph))
|
||||
elif shape == "square":
|
||||
v = 0.6 if math.sin(ph) >= 0 else -0.6
|
||||
else: # saw
|
||||
v = ((ph / TAU) % 1.0) * 2 - 1
|
||||
fade = min(1.0, (dur - t) / 0.01) # no click at the end
|
||||
b[n0 + k] += v * amp * env(t, a, d) * fade
|
||||
|
||||
|
||||
def add_noise(b, start, dur, amp=0.4, a=0.002, d=0.1, lp0=0.5, lp1=None, seed=1):
|
||||
"""Noise through a one-pole lowpass whose coefficient sweeps lp0 -> lp1 (0..1, 1 = open)."""
|
||||
rng = random.Random(seed)
|
||||
lp1 = lp0 if lp1 is None else lp1
|
||||
y = 0.0
|
||||
n0 = int(start * SR)
|
||||
for k in range(int(dur * SR)):
|
||||
if n0 + k >= len(b):
|
||||
break
|
||||
t = k / SR
|
||||
c = lp0 + (lp1 - lp0) * (t / dur)
|
||||
y += c * (rng.uniform(-1, 1) - y)
|
||||
fade = min(1.0, (dur - t) / 0.01)
|
||||
b[n0 + k] += y * amp * env(t, a, d) * fade * 2
|
||||
|
||||
|
||||
def add_pluck(b, start, freq, dur=0.6, amp=0.5, seed=3, damp=0.996):
|
||||
"""Karplus-Strong plucked string."""
|
||||
rng = random.Random(seed)
|
||||
n = max(2, int(SR / freq))
|
||||
line = [rng.uniform(-1, 1) for _ in range(n)]
|
||||
n0 = int(start * SR)
|
||||
for k in range(int(dur * SR)):
|
||||
if n0 + k >= len(b):
|
||||
break
|
||||
v = line[k % n]
|
||||
line[k % n] = damp * 0.5 * (v + line[(k + 1) % n])
|
||||
b[n0 + k] += v * amp
|
||||
|
||||
|
||||
def add_bell(b, start, f, amp=0.35, d=0.4):
|
||||
for ratio, a in ((1, 1.0), (2.76, 0.5), (5.4, 0.25), (8.93, 0.12)):
|
||||
add_tone(b, start, min(1.0 - start, d * 2.5), f * ratio, amp=amp * a, a=0.002, d=d / ratio ** 0.5)
|
||||
|
||||
|
||||
CALM_DUR = 2.0
|
||||
|
||||
|
||||
def cbuf():
|
||||
return buf(CALM_DUR)
|
||||
|
||||
|
||||
def pad(b, start, dur, f, amp=0.2, a=0.4, d=0.8, vib=(0, 0), shape="sine"):
|
||||
add_tone(b, start, dur, f, amp=amp, a=a, d=d, vib=vib, shape=shape)
|
||||
|
||||
|
||||
def soft_bell(b, start, f, amp=0.15, d=0.8):
|
||||
for ratio, a in ((1, 1.0), (2.0, 0.3), (3.01, 0.12)):
|
||||
add_tone(b, start, min(CALM_DUR - start, d * 3), f * ratio, amp=amp * a, a=0.01, d=d / ratio ** 0.5)
|
||||
|
||||
|
||||
def ease_off(b, secs=0.5):
|
||||
"""Fade the last secs out, so a long, soft sound never stops dead."""
|
||||
n = int(secs * SR)
|
||||
for k in range(n):
|
||||
b[len(b) - n + k] *= (1 - k / n) ** 2
|
||||
return b
|
||||
|
||||
|
||||
def write(name, b, level=0.7, out=None):
|
||||
"""b normalised to level (0..1 of full scale) as <out or shared/sounds>/<name>.wav."""
|
||||
peak = max(1e-6, max(abs(v) for v in b))
|
||||
g = level / peak
|
||||
with wave.open(os.path.join(out or OUT, name + ".wav"), "wb") as w:
|
||||
w.setnchannels(1)
|
||||
w.setsampwidth(2)
|
||||
w.setframerate(SR)
|
||||
w.writeframes(b"".join(struct.pack("<h", int(max(-1, min(1, v * g)) * 32767)) for v in b))
|
||||
|
||||
|
||||
# ── for the streak sounds: 2 s, lively ──
|
||||
|
||||
STREAK_DUR = 2.0
|
||||
|
||||
|
||||
def sbuf(dur=STREAK_DUR):
|
||||
return buf(dur)
|
||||
|
||||
|
||||
def bell(b, start, f, amp=0.3, d=0.4):
|
||||
"""add_bell for any length of sound (add_bell stops at 1 s)."""
|
||||
for ratio, a in ((1, 1.0), (2.76, 0.5), (5.4, 0.25), (8.93, 0.12)):
|
||||
add_tone(b, start, max(0.01, min(len(b) / SR - start, d * 2.5)), f * ratio, amp=amp * a, a=0.002,
|
||||
d=d / ratio ** 0.5)
|
||||
@@ -0,0 +1,55 @@
|
||||
"""The streak animations: one module per streak level, plus one for the calm ones.
|
||||
|
||||
A task ticked by hand whose streak reaches a level (routine/model.py STREAK_LEVELS: 7, 21, 42, 66,
|
||||
100, 150, 254, 365, then every 100 past 365 counts as the top level again) plays one of that
|
||||
level's animations instead of its set's; a task marked calm plays one of the calm streak ones.
|
||||
|
||||
level0.py .. level7.py ANIMS = [(fn, colour, sound), ...]: 8 animations for that level
|
||||
calm.py ANIMS = [...]: 4 calm streak animations (any level, calm tasks)
|
||||
level0_sounds.py .. SOUNDS = [fn, ...]: each fn() -> a buf (tools/sound_kit.py); its
|
||||
calm_sounds.py __name__ is the sound's name, the one ANIMS gives (without .wav)
|
||||
|
||||
A level whose module doesn't exist yet is simply left empty: the app falls back to the nearest
|
||||
lower level that has animations. Each module only imports the kits (from anim_kit import ... /
|
||||
from sound_kit import ...), never another level, so work on different levels never touches the
|
||||
same file. Every animation is 24 frames (anim_kit.STREAK_FRAMES, 2 s at 12 fps), shows the
|
||||
streak number (anim_kit.NUM) and has a sound of its own; every name and sound is unique across
|
||||
everything (tools/gen_animations.py refuses duplicates).
|
||||
|
||||
python3 tools/gen_animations.py --level 0 --out DIR just this level, into DIR (not shared/)
|
||||
python3 tools/gen_sounds.py --level 0 --out DIR its sounds into DIR/sounds/
|
||||
python3 tools/preview_animations.py DIR/sheets --json DIR/animations.json --streak 0
|
||||
"""
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
NAMES = ["level%d" % k for k in range(8)] + ["calm"]
|
||||
|
||||
|
||||
def key_of(name):
|
||||
""""level3" -> 3, "calm" -> "calm"."""
|
||||
return "calm" if name == "calm" else int(name[5:])
|
||||
|
||||
|
||||
def load(kind="", strict=True, only=None):
|
||||
"""{key: module} for every streak module that exists (key = level number or "calm");
|
||||
kind "" = the animation modules, "_sounds" = the sound ones. strict: an import error stops
|
||||
everything; otherwise a module other than only that fails is skipped with a warning."""
|
||||
out = {}
|
||||
for name in NAMES:
|
||||
try:
|
||||
mod = importlib.import_module("streak_anims." + name + kind)
|
||||
except ModuleNotFoundError as e:
|
||||
if e.name == "streak_anims." + name + kind:
|
||||
continue # not written yet
|
||||
if strict or key_of(name) == only:
|
||||
raise
|
||||
print("warning: skipping %s%s: %s" % (name, kind, e), file=sys.stderr)
|
||||
continue
|
||||
except Exception as e: # noqa: BLE001 - someone else's module mid-edit
|
||||
if strict or key_of(name) == only:
|
||||
raise
|
||||
print("warning: skipping %s%s: %r" % (name, kind, e), file=sys.stderr)
|
||||
continue
|
||||
out[key_of(name)] = mod
|
||||
return out
|
||||
@@ -0,0 +1,112 @@
|
||||
"""Calm streak animations: for calm tasks, at any streak level. 2 s, slow, small and quiet, like the
|
||||
calm set (gentle boil CB, thin strokes, things easing in and out), each showing the streak number.
|
||||
Sounds: calm_sounds.py (written quiet, like the calm set's).
|
||||
"""
|
||||
import math
|
||||
|
||||
from anim_kit import CB, NUM, K, cc, cl, cp, ease_out, inout, oval, rotate
|
||||
|
||||
|
||||
def snowglobe(i, t):
|
||||
"""A snow globe sits on the box with the number inside; its flakes swirl slowly round and settle at the bottom."""
|
||||
s = []
|
||||
cx, cy, r = 0.0, -2.1, 1.45
|
||||
s.append(cp([(-1.0, -0.25), (1.0, -0.25), (0.8, -0.75), (-0.8, -0.75)])) # the base
|
||||
s.append(cc(cx, cy, r, 0.08))
|
||||
s.append(cl([(cx - 0.9, cy - 0.75), (cx - 0.55, cy - 1.05)], 0.06)) # a glint on the glass
|
||||
s.append(K("red"))
|
||||
s.append(NUM(cx, cy - 0.1, 1.05, boil=CB))
|
||||
s.append(K("blue"))
|
||||
settle = ease_out(min(1.0, t * 1.25))
|
||||
for k in range(11):
|
||||
a = k * 2.4 + t * 2.2 * (1 - settle)
|
||||
rr = 0.35 + (k % 4) * 0.25
|
||||
x0, y0 = cx + rr * math.cos(a), cy + rr * math.sin(a) * 0.8
|
||||
x1 = cx - 1.0 + k * 0.2
|
||||
y1 = cy + r - 0.22 - 0.06 * (k % 2) - 0.25 * (1 - abs(x1 - cx) / 1.2) * 0.4
|
||||
x, y = x0 + (x1 - x0) * settle, y0 + (y1 - y0) * settle
|
||||
s.append(cc(x, y, 0.06 + 0.02 * (k % 2)))
|
||||
return s
|
||||
|
||||
|
||||
def slate(i, t):
|
||||
"""A little framed slate rises by the box; a stick of chalk taps the number onto it, then rests on the ledge in a puff of dust."""
|
||||
s = []
|
||||
up = ease_out(min(1.0, t * 3))
|
||||
y0 = -0.9 - 0.9 * up
|
||||
x0, x1, top = -1.6, 1.6, y0 - 2.4
|
||||
s.append(cl([(x0, y0), (x1, y0), (x1, top), (x0, top), (x0, y0)], 0.16))
|
||||
s.append(cl([(x0 - 0.2, y0 + 0.12), (x1 + 0.2, y0 + 0.12)], 0.1)) # the ledge
|
||||
if i >= 8:
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(0, (y0 + top) / 2, 1.25, boil=CB))
|
||||
s.append(K("red"))
|
||||
if i < 18: # the chalk, writing
|
||||
u = max(0.0, (t - 0.25) / 0.5)
|
||||
cx = -0.7 + 1.4 * min(1.0, u) + 0.1 * math.sin(i * 1.4)
|
||||
cy = (y0 + top) / 2 - 0.4 + 0.5 * math.sin(i * 0.9)
|
||||
s.append(cl(rotate([(cx, cy), (cx + 0.5, cy - 0.35)], 0.0), 0.14))
|
||||
else: # put down on the ledge
|
||||
s.append(cl([(0.9, y0 - 0.05), (1.4, y0 - 0.05)], 0.14))
|
||||
g = inout((t - 0.75) / 0.25, 0.5)
|
||||
for k in range(3):
|
||||
s.append(cc(1.1 + (k - 1) * 0.25, y0 - 0.25 - k * 0.1 - (i - 18) * 0.05, 0.05 + 0.04 * g))
|
||||
return s
|
||||
|
||||
|
||||
def sundial(i, t):
|
||||
"""A sundial by the box with the number on its face; the sun crosses the sky slowly and the gnomon's shadow sweeps round beneath it."""
|
||||
s = []
|
||||
cx, cy = 0.0, -1.0
|
||||
s.append(cp(oval(cx, cy, 1.9, 0.6, 18))) # the dial, seen a little from above
|
||||
s.append(K("blue"))
|
||||
for k in range(7): # hour marks
|
||||
a = math.pi + k * math.pi / 6
|
||||
s.append(cl([(cx + 1.55 * math.cos(a), cy + 0.48 * math.sin(a)), (cx + 1.75 * math.cos(a), cy + 0.55 * math.sin(a))], 0.05))
|
||||
s.append(K("yellow"))
|
||||
s.append(cp([(cx - 0.05, cy), (cx + 0.05, cy), (cx + 0.05, cy - 1.0)])) # the gnomon
|
||||
sa = math.pi * (1.05 + 0.9 * t) # the sun's path across the sky
|
||||
sx, sy = cx + 3.2 * math.cos(sa), cy - 0.6 + 2.6 * math.sin(sa)
|
||||
s.append(cc(sx, sy, 0.38))
|
||||
for k in range(8):
|
||||
a = k * math.pi / 4 + t * 0.6
|
||||
s.append(cl([(sx + 0.55 * math.cos(a), sy + 0.55 * math.sin(a)), (sx + 0.75 * math.cos(a), sy + 0.75 * math.sin(a))], 0.05))
|
||||
s.append(K("blue"))
|
||||
ha = sa + math.pi # the shadow points away from the sun
|
||||
s.append(cl([(cx, cy), (cx + 1.35 * math.cos(ha), cy + 0.42 * math.sin(ha) * -1)], 0.1))
|
||||
s.append(K("red"))
|
||||
s.append(NUM(cx, cy - 2.2, 1.2, boil=CB))
|
||||
return s
|
||||
|
||||
|
||||
def abacus(i, t):
|
||||
"""A small abacus stands by the box; beads slide across one by one, unhurried, and the number settles in above it."""
|
||||
s = []
|
||||
x0, x1, y0, y1 = -1.8, 1.8, -0.4, -2.4
|
||||
s.append(cl([(x0, y0), (x0, y1)], 0.14))
|
||||
s.append(cl([(x1, y0), (x1, y1)], 0.14))
|
||||
s.append(cl([(x0 - 0.2, y1), (x1 + 0.2, y1)], 0.14))
|
||||
s.append(cl([(x0 - 0.2, y0), (x1 + 0.2, y0)], 0.14))
|
||||
rows = 3
|
||||
for r in range(rows):
|
||||
y = y1 + (r + 1) * (y0 - y1) / (rows + 1)
|
||||
s.append(cl([(x0, y), (x1, y)], 0.04))
|
||||
for b in range(4):
|
||||
start = (r * 4 + b) / 12 * 0.75 # one bead after another
|
||||
u = ease_out(max(0.0, min(1.0, (t - start) / 0.18)))
|
||||
bx = x0 + 0.3 + b * 0.38 + u * (x1 - x0 - 0.6 - 3 * 0.38 - 0.0) * 1.0
|
||||
bx = min(bx, x1 - 0.3 - (3 - b) * 0.38)
|
||||
s.append(K("yellow" if r == 1 else "red"))
|
||||
s.append(cp(oval(bx, y, 0.17, 0.2, 10)))
|
||||
s.append(K("blue"))
|
||||
g = inout(t, 0.0001) * ease_out(min(1.0, max(0.0, (t - 0.45) / 0.3)))
|
||||
if g > 0:
|
||||
s.append(NUM(0, y1 - 1.0 - 0.3 * g, 0.6 + 0.7 * g, boil=CB))
|
||||
s.append(K("red"))
|
||||
return s
|
||||
|
||||
|
||||
ANIMS = [
|
||||
(snowglobe, "blue", "settle"), (slate, "red", "chalk"),
|
||||
(sundial, "yellow", "noon"), (abacus, "red", "beads"),
|
||||
]
|
||||
@@ -0,0 +1,48 @@
|
||||
"""The calm streak animations' sounds (calm.py): 2 s, soft attacks, no bangs; gen_sounds.py writes
|
||||
them quiet (like the calm set's) and eases off their ends. Seeds 2900-2999."""
|
||||
import random
|
||||
|
||||
from sound_kit import add_noise, add_tone, pad, sbuf, soft_bell
|
||||
|
||||
|
||||
def settle():
|
||||
"""A slow sprinkle of tiny high bells, drifting down."""
|
||||
b = sbuf()
|
||||
rng = random.Random(2900)
|
||||
for k in range(9):
|
||||
soft_bell(b, 0.1 + k * 0.17 + rng.uniform(0, 0.05), 1760 - k * 90, 0.06, 0.5)
|
||||
pad(b, 0.0, 2.0, 440, 0.06, a=0.8, d=0.9)
|
||||
return b
|
||||
|
||||
|
||||
def chalk():
|
||||
"""Soft chalky taps and scratches, then a quiet warm note."""
|
||||
b = sbuf()
|
||||
for k in range(7):
|
||||
add_noise(b, 0.45 + k * 0.13, 0.08, 0.18, a=0.005, d=0.03, lp0=0.55, lp1=0.4, seed=2910 + k)
|
||||
add_noise(b, 1.45, 0.25, 0.08, a=0.05, d=0.1, lp0=0.2, seed=2918)
|
||||
soft_bell(b, 1.5, 392, 0.12, 0.6)
|
||||
return b
|
||||
|
||||
|
||||
def noon():
|
||||
"""A warm chord swelling slowly, with one soft bell at its height."""
|
||||
b = sbuf()
|
||||
for k, f in enumerate((196, 247, 294)):
|
||||
pad(b, k * 0.2, 2.0 - k * 0.2, f, 0.1, a=0.7, d=1.0)
|
||||
soft_bell(b, 1.0, 784, 0.1, 0.7)
|
||||
return b
|
||||
|
||||
|
||||
def beads():
|
||||
"""Wooden beads clicking softly along their rods, one by one, then a gentle chime."""
|
||||
b = sbuf()
|
||||
for k in range(12):
|
||||
st = 0.05 + k * 0.105
|
||||
add_tone(b, st, 0.06, 520 + (k % 4) * 40, 470, 0.12, a=0.002, d=0.02, shape="tri")
|
||||
add_noise(b, st, 0.02, 0.05, a=0.001, d=0.008, lp0=0.3, seed=2920 + k)
|
||||
soft_bell(b, 1.35, 659, 0.1, 0.6)
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [settle, chalk, noon, beads]
|
||||
@@ -0,0 +1,358 @@
|
||||
"""Streak level 0: a 7-day streak. Eight 2-second celebrations, each showing the streak number.
|
||||
|
||||
The worked example for the other levels: fn(i, t) -> shapes, i = frame 0..23, t = 0..1; NUM(...)
|
||||
is where the number goes (the app fills it in: 7 here, but lay out for up to 3 digits, since the
|
||||
top level is reused for 465, 565, ...). K(colour) switches colour for the shapes after it, so the
|
||||
number can stand out from what it sits on. Sounds: level0_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 megaphone(i, t):
|
||||
"""A megaphone pops up out of the box and blares: sound waves pulse out and the number bursts from its mouth, bigger with every pulse."""
|
||||
s = []
|
||||
up = ease_out(min(1.0, t * 4))
|
||||
kick = 0.22 if i % 6 in (3, 4) and i >= 3 else 0.0 # recoils on each blare
|
||||
ang = -0.6 # pointing up and to the right
|
||||
ax, ay = -0.9 - kick * math.cos(ang), -0.6 - 1.2 * up - kick * math.sin(ang) # the narrow end
|
||||
ca, sa = math.cos(ang), math.sin(ang)
|
||||
|
||||
def at(x, y):
|
||||
return (ax + x * ca - y * sa, ay + x * sa + y * ca)
|
||||
s.append(P([at(-0.3, -0.3), at(0.1, -0.33), at(2.3, -1.15), at(2.3, 1.15), at(0.1, 0.33), at(-0.3, 0.3)]))
|
||||
s.append(P([at(0.4, 0.3), at(0.75, 0.32), at(0.7, 1.1), at(0.35, 1.1)])) # the handle
|
||||
s.append(K("red"))
|
||||
s.append(P([at(2.3, -1.2), at(2.55, -1.3), at(2.55, 1.3), at(2.3, 1.2)])) # the mouth's rim
|
||||
mx, my = at(2.7, 0)
|
||||
if i >= 3:
|
||||
s.append(K("yellow"))
|
||||
for k in range(3): # the waves, each pulse a little further
|
||||
age = ((i - 3) % 6) + k * 2
|
||||
r = 0.6 + age * 0.4
|
||||
if r < 3.2:
|
||||
arc = [(mx + r * math.cos(ang + a), my + r * math.sin(ang + a)) for a in (-0.75, -0.4, 0, 0.4, 0.75)]
|
||||
s.append(L(arc, 0.16 - age * 0.01))
|
||||
g = pop_scale(t, 3 / 23, 0.15, 1.35) * (1 + 0.14 * (i % 6 in (3, 4)))
|
||||
d = 1.4 + 1.4 * min(1.0, (i - 3) / 6)
|
||||
s.append(K("red"))
|
||||
s.append(NUM(mx + d * ca, my + d * sa - 0.3, 1.8 * g, rot=0.14 * math.sin(i * 1.3)))
|
||||
return s
|
||||
|
||||
|
||||
def slotmachine(i, t):
|
||||
"""A slot machine rises beside the box; its lever is pulled, the reel whirs, and it lands on the number as lights flash and coins spill out."""
|
||||
s = []
|
||||
rise = ease_out(min(1.0, t * 5))
|
||||
y0 = 1.0 - rise * 1.0 # it rises a unit out of the box
|
||||
top, bot = y0 - 4.6, y0 - 0.6
|
||||
s.append(P([(-1.9, bot), (1.9, bot), (1.9, top + 0.4), (1.5, top), (-1.5, top), (-1.9, top + 0.4)]))
|
||||
s.append(P([(-1.4, bot + 0.2), (1.4, bot + 0.2), (1.2, bot + 0.6), (-1.2, bot + 0.6)])) # the tray
|
||||
pull = 1.0 if 3 <= i <= 5 else 0.5 if i in (2, 6) else 0.0
|
||||
kx, ky = 2.5, top + 0.4 + pull * 2.2
|
||||
s.append(L([(1.9, top + 2.2), (2.5, top + 2.2), (kx, ky)], 0.14))
|
||||
s.append(C(kx, ky, 0.28))
|
||||
wy0, wy1 = top + 1.0, top + 2.8 # the window
|
||||
s.append(K("yellow"))
|
||||
s.append(P([(-1.45, wy0), (1.45, wy0), (1.45, wy1), (-1.45, wy1)], 0, 0.03))
|
||||
s.append(K("blue"))
|
||||
if i < 13: # the reel spins: digits whizz past
|
||||
for k in range(3):
|
||||
y = wy0 + 0.2 + ((i * 0.55 + k * 0.6) % 1.4)
|
||||
s.append(L([(-1.1, y), (1.1, y)], 0.09))
|
||||
if 4 <= i:
|
||||
s.append(NUM(0, wy0 + 0.3 + (i % 2) * 1.0, 0.5, rot=0.0))
|
||||
else:
|
||||
b = [0.35, -0.12, 0.05, 0.0][min(3, i - 13)]
|
||||
s.append(NUM(0, (wy0 + wy1) / 2 + b, 1.15))
|
||||
if i >= 13: # lights on top flash
|
||||
for k in range(5):
|
||||
s.append(K(["red", "blue", "yellow"][(k + i) % 3]))
|
||||
s.append(C(-1.2 + k * 0.6, top - 0.3, 0.2 if (k + i) % 2 else 0.13))
|
||||
s.append(K("yellow"))
|
||||
for m in range(7): # coins spill from the tray
|
||||
u = (i - 13 - m * 0.6) / 10
|
||||
if 0 < u <= 1:
|
||||
vx = -2.2 + m * 0.75
|
||||
x, y = vx * u * 1.4, bot + 0.4 - 2.6 * u + 4.5 * u * u
|
||||
s.append(P(ring(x, y, 0.2, 8, 0, 0.02)))
|
||||
return s
|
||||
|
||||
|
||||
def bannerplane(i, t):
|
||||
"""A little plane buzzes across above the box towing a banner with the number on it, the banner rippling in its wake."""
|
||||
s = []
|
||||
x = -1.0 + t * 5.6
|
||||
y = -3.8 + 0.18 * math.sin(i * 0.8)
|
||||
z = 1.35 # the plane's size
|
||||
|
||||
def at(px, py):
|
||||
return (x + px * z, y + py * z)
|
||||
s.append(P([at(-0.9, -0.05), at(0.6, -0.25), at(1.0, 0), at(0.6, 0.25), at(-0.9, 0.12)]))
|
||||
s.append(P([at(-0.75, -0.05), at(-1.05, -0.65), at(-0.65, -0.6), at(-0.45, -0.1)])) # tail fin
|
||||
flap = 0.2 if i % 2 else -0.1
|
||||
s.append(P([at(-0.1, 0), at(0.35, 0), at(0.15, 0.6 + flap), at(-0.3, 0.6 + flap)])) # wing
|
||||
s.append(K("yellow"))
|
||||
s.append(C(*at(0.45, -0.08), 0.12)) # the window
|
||||
s.append(K("blue"))
|
||||
if i % 2: # the propeller, a blur
|
||||
s.append(L([at(1.1, -0.45), at(1.1, 0.45)], 0.09))
|
||||
else:
|
||||
s.append(L([at(1.05, -0.15), at(1.15, 0.15)], 0.13))
|
||||
bx1 = x - 1.25 * z - 0.5 # the banner's leading edge
|
||||
bw, bh = 4.0, 1.75
|
||||
s.append(L([at(-0.9, 0), (bx1, y - 0.3), (bx1, y + 0.3)], 0.05))
|
||||
|
||||
def wave(px):
|
||||
return 0.2 * math.sin((bx1 - px) * 1.8 - i * 1.5)
|
||||
xs = [bx1 - bw * k / 8 for k in range(9)]
|
||||
edge = [(px, y - bh / 2 + wave(px)) for px in xs] + [(px, y + bh / 2 + wave(px) * 1.3) for px in reversed(xs)]
|
||||
s.append(K("yellow"))
|
||||
s.append(P(edge, 0, 0.03))
|
||||
s.append(K("blue"))
|
||||
s.append(P(edge, 0.08, 0.03))
|
||||
s.append(K("red"))
|
||||
cx = bx1 - bw / 2
|
||||
s.append(NUM(cx, y + wave(cx) + 0.05, 1.3, rot=-0.15 * math.cos((bw / 2) * 1.8 - i * 1.5)))
|
||||
if i < 5: # whoosh lines as it sweeps in
|
||||
s.append(K("blue"))
|
||||
for k in range(3):
|
||||
s.append(L([(xs[-1] - 0.4 - k * 0.3, y - 0.7 + k * 0.7), (xs[-1] - 1.2 - k * 0.3, y - 0.7 + k * 0.7)], 0.07))
|
||||
return s
|
||||
|
||||
|
||||
def cannon(i, t):
|
||||
"""A little cannon rolls out by the box, its fuse fizzes, and BOOM: the number is fired high in an arc and lands with a bounce."""
|
||||
s = []
|
||||
rec = 0.55 if i in (6, 7) else 0.25 if i == 8 else 0.0
|
||||
cx, cy = -1.0 - rec, -0.5
|
||||
ang = -0.75
|
||||
z = 1.35
|
||||
barrel = rotate([(-0.6 * z, -0.45 * z), (1.5 * z, -0.34 * z), (1.6 * z, -0.42 * z), (1.6 * z, 0.42 * z),
|
||||
(1.5 * z, 0.34 * z), (-0.6 * z, 0.45 * z)], ang)
|
||||
s.append(P([(cx + x, cy + y) for x, y in barrel]))
|
||||
s.append(K("blue"))
|
||||
wx, wy = cx - 0.15, cy + 0.35
|
||||
s.append(C(wx, wy, 0.6, 0.16)) # the wheel and its spokes
|
||||
for k in range(3):
|
||||
a = k * math.pi / 3 + rec * 3 + i * 0.05
|
||||
s.append(L([(wx + 0.55 * math.cos(a), wy + 0.55 * math.sin(a)), (wx - 0.55 * math.cos(a), wy - 0.55 * math.sin(a))], 0.08))
|
||||
mx, my = cx + 1.7 * z * math.cos(ang), cy + 1.7 * z * math.sin(ang) # the muzzle
|
||||
s.append(K("red"))
|
||||
if i < 6: # the fuse burns down
|
||||
bx, by = cx - 0.7 * z * math.cos(ang), cy - 0.7 * z * math.sin(ang)
|
||||
fx, fy = bx - 0.45 + i * 0.05, by - 0.3 + i * 0.03
|
||||
s.append(L([(bx, by), (fx, fy)], 0.06))
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(fx, fy, 0.35 + (i % 2) * 0.15, 0.13, 6, i)))
|
||||
elif i <= 8: # the blast
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(mx + 0.4, my - 0.4, 1.7 - (i - 6) * 0.4, 0.7, 10, i)))
|
||||
if i >= 6:
|
||||
s.append(K("red"))
|
||||
for k in range(3): # smoke puffs drifting off
|
||||
age = i - 6 - k
|
||||
if 0 <= age < 9:
|
||||
s.append(C(mx - 0.3 + 0.3 * k - age * 0.15, my - 0.3 - age * 0.2, 0.25 + age * 0.08, 0.08))
|
||||
u = min(1.0, (i - 6) / 9) # the number's flight
|
||||
tx, ty = 3.6, -0.75
|
||||
x = mx + (tx - mx) * u
|
||||
y = my + (ty - my) * u - 5.0 * u * (1 - u)
|
||||
h = 0.5 + 1.2 * u
|
||||
if i > 15: # landed: bounce and squash
|
||||
b = [0.0, -0.6, -0.8, -0.55, 0.0, -0.2, 0.0, 0.0][min(7, i - 16)]
|
||||
y = ty + b
|
||||
h = 1.7
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(x, y, h, rot=(1 - u) * -4.0))
|
||||
if i in (15, 16, 20):
|
||||
s.append(K("red"))
|
||||
s += rays(tx, ty + 0.9, 0.4, 0.9, 5, math.pi * 0.9, 0.08)
|
||||
return s
|
||||
|
||||
|
||||
def drum(i, t):
|
||||
"""A drum stands on the box and gets a rapid drumroll, then a cymbal CRASH and the number leaps out of the drum."""
|
||||
s = []
|
||||
top, bot = -2.0, -0.2
|
||||
w = 1.3
|
||||
s.append(P([(-w, top), (w, top), (w, bot), (-w, bot)]))
|
||||
s.append(K("yellow"))
|
||||
s.append(L([(-w + k * w / 4, top + 0.25 if k % 2 else bot - 0.2) for k in range(9)], 0.09)) # the lacing
|
||||
s.append(P([(w * math.cos(a), top + 0.36 * math.sin(a)) for a in [k * math.pi / 8 for k in range(16)]]))
|
||||
s.append(K("red"))
|
||||
hit = i < 13
|
||||
for side in (-1, 1): # the sticks, left and right in turn
|
||||
down = hit and (i + (side > 0)) % 2 == 1
|
||||
if hit:
|
||||
tipx, tipy = side * 0.45, top - (0.0 if down else 1.0)
|
||||
else: # done: held up out of the way
|
||||
tipx, tipy = side * (1.5 if side < 0 else 1.0), top + 0.2
|
||||
hx, hy = (tipx + side * 1.6, tipy - (0.4 if down else 0.9)) if hit else (tipx + side * 0.9, tipy - 1.5)
|
||||
s.append(L([(hx, hy), (tipx, tipy)], 0.13))
|
||||
s.append(C(tipx, tipy, 0.16))
|
||||
if down:
|
||||
s += rays(tipx, top - 0.1, 0.25, 0.6, 3, -math.pi * 0.5 - 0.6, 0.06)
|
||||
s.append(K("blue"))
|
||||
s.append(L([(2.3, -0.2), (2.3, -2.8)], 0.09)) # the cymbal on its stand
|
||||
tilt = 0.25 if hit else 0.25 + 0.35 * math.sin((i - 13) * 2.0) * math.exp(-(i - 13) * 0.2)
|
||||
s.append(K("yellow"))
|
||||
s.append(P(rotate([(1.5, -2.8), (2.3, -3.02), (3.1, -2.8), (2.3, -2.7)], tilt, 2.3, -2.8)))
|
||||
if not hit:
|
||||
s += rays(2.3, -2.85, 1.0, 1.4 + 0.25 * (i % 2), 7, i * 0.2, 0.09)
|
||||
g = pop_scale(t, 13 / 23, 0.12, 1.3)
|
||||
y = top - 1.0 - 1.6 * ease_out(min(1.0, (i - 13) / 4))
|
||||
s.append(K("red"))
|
||||
s.append(NUM(-0.3, y, 1.8 * g, rot=0.1 * math.sin(i)))
|
||||
if i % 2:
|
||||
s.append(K("blue"))
|
||||
s += rays(-0.3, y, 1.6, 2.0, 10, i * 0.15, 0.08)
|
||||
return s
|
||||
|
||||
|
||||
def pinata(i, t):
|
||||
"""A star pinata swings over the box; a stick whacks it, whacks it again, and the third time it bursts: sweets fly and the number drops out."""
|
||||
s = []
|
||||
px, py = 0.4, -6.2 # where its string hangs from
|
||||
hits = (4, 9, 14)
|
||||
sw = 0.0
|
||||
for h in hits:
|
||||
if i >= h:
|
||||
sw = 0.4 * math.exp(-(i - h) * 0.3) * math.sin((i - h) * 1.1 + 0.9)
|
||||
bx, by = px + 2.6 * math.sin(sw), py + 2.6 * math.cos(sw)
|
||||
for h in hits: # the stick swings in from the left
|
||||
if h - 2 <= i <= h:
|
||||
a = [-1.7, -1.0, -0.3][i - h + 2]
|
||||
s.append(K("red"))
|
||||
s.append(L([(-2.8, -0.2), (-2.8 + 3.0 * math.cos(a), -0.2 + 3.0 * math.sin(a))], 0.18))
|
||||
s.append(K("yellow"))
|
||||
if i < hits[2]:
|
||||
rot = -math.pi / 2 + sw
|
||||
s.append(L([(px, py), (bx, by - 1.3)], 0.05))
|
||||
s.append(P(star(bx, by, 1.6, 0.85, 5, rot)))
|
||||
s.append(K("blue"))
|
||||
for k in range(5): # tassels off each point
|
||||
a = rot + k * 2 * math.pi / 5
|
||||
tx, ty = bx + 1.6 * math.cos(a), by + 1.6 * math.sin(a)
|
||||
s.append(L([(tx, ty), (tx + 0.15 * math.sin(i + k), ty + 0.45)], 0.08))
|
||||
s.append(C(bx, by, 0.35))
|
||||
s.append(K("yellow"))
|
||||
if i in (hits[0], hits[0] + 1, hits[1], hits[1] + 1):
|
||||
s += rays(bx - 1.2, by + 0.3, 0.2, 0.7, 4, math.pi * 0.75, 0.09)
|
||||
else:
|
||||
k = i - hits[2]
|
||||
for m in range(12): # bits of pinata and sweets
|
||||
a = m * 2 * math.pi / 12 + 0.4
|
||||
r = 0.6 + k * 0.55
|
||||
x, y = bx + r * math.cos(a), by + r * math.sin(a) + k * k * 0.07
|
||||
if m % 3 == 0:
|
||||
s.append(K(["red", "blue"][m % 2]))
|
||||
s.append(C(x, y, 0.2))
|
||||
else:
|
||||
s.append(K("yellow"))
|
||||
s.append(P(rotate([(x - 0.25, y - 0.15), (x + 0.25, y - 0.12), (x + 0.05, y + 0.2)], m + k, x, y)))
|
||||
if k <= 1:
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(bx, by, 2.1 - k * 0.4, 0.9, 10, 0.2), 0.12))
|
||||
drop = min(1.0, k / 4)
|
||||
b = [0, 0, 0, 0, 0, -0.4, -0.12, 0, 0, 0][min(9, k)]
|
||||
s.append(K("red"))
|
||||
s.append(NUM(bx, by + drop * 2.2 + b, 0.9 + 0.9 * drop, rot=(1 - drop) * 0.7))
|
||||
return s
|
||||
|
||||
|
||||
def champagne(i, t):
|
||||
"""A bottle rises out of the box, shakes, and POP: the cork flies, a fountain of fizz sprays up, and the number rides up on the bubbles."""
|
||||
s = []
|
||||
rise = ease_out(min(1.0, t * 4))
|
||||
shake = 0.18 * math.sin(i * 2.6) if 3 <= i < 8 else 0.0
|
||||
by = 0.2 - 1.2 * rise
|
||||
z = 1.5
|
||||
|
||||
def sc(pts):
|
||||
return rotate([(x * z, by + (y - by) * z) for x, y in pts], shake, 0, by)
|
||||
s.append(P(sc([(-0.45, by), (0.45, by), (0.45, by - 1.5), (0.15, by - 2.0), (0.15, by - 2.5), (-0.15, by - 2.5),
|
||||
(-0.15, by - 2.0), (-0.45, by - 1.5)])))
|
||||
s.append(K("yellow"))
|
||||
s.append(P(sc([(-0.45, by - 0.5), (0.45, by - 0.5), (0.45, by - 1.1), (-0.45, by - 1.1)]))) # label
|
||||
s.append(P(sc([(-0.15, by - 2.1), (0.15, by - 2.1), (0.15, by - 2.45), (-0.15, by - 2.45)]))) # foil
|
||||
nx, ny = sc([(0, by - 2.55)])[0] # the neck's mouth
|
||||
s.append(K("red"))
|
||||
if i < 8:
|
||||
s.append(P(rotate([(nx - 0.25, ny), (nx + 0.25, ny), (nx + 0.3, ny - 0.55), (nx - 0.3, ny - 0.55)], shake, nx, ny)))
|
||||
else: # the cork flies off
|
||||
k = i - 8
|
||||
cx, cy = nx + k * 0.45, ny - 0.4 - k * 0.9 + k * k * 0.05
|
||||
s.append(P(rotate([(cx - 0.25, cy), (cx + 0.25, cy), (cx + 0.3, cy - 0.55), (cx - 0.3, cy - 0.55)], k * 0.9, cx, cy)))
|
||||
if k < 2:
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(nx, ny - 0.3, 1.2, 0.4, 8, i)))
|
||||
s.append(K("blue"))
|
||||
for m in range(9): # the fountain of fizz
|
||||
a = -math.pi / 2 + (m - 4) * 0.22
|
||||
for q in range(2):
|
||||
r = (k - q * 2) * 0.55
|
||||
if r > 0:
|
||||
x = nx + r * math.cos(a)
|
||||
y = ny + r * math.sin(a) + (r * 0.35) ** 2
|
||||
s.append(C(x, y, 0.1 + 0.05 * ((m + q + i) % 2), 0 if (m + q) % 2 else 0.05))
|
||||
u = ease_out(min(1.0, k / 8))
|
||||
y = ny - 0.8 - 2.6 * u
|
||||
s.append(K("red"))
|
||||
s.append(NUM(nx + 0.12 * math.sin(i * 0.9), y, 0.7 + 1.0 * u, rot=0.12 * math.sin(i * 0.7)))
|
||||
return s
|
||||
|
||||
|
||||
def stamp(i, t):
|
||||
"""A big rubber stamp hovers, rears up and comes down above the box with a KACHUNK, then lifts away: the number left stamped inside a jagged seal."""
|
||||
s = []
|
||||
cx, cy = 0.2, -2.6 # where it lands
|
||||
ys = [-3.0, -3.3, -3.6, -3.9, -3.2, -1.5, 0.0, 0.0, 0.0, 0.0, -0.3, -1.2, -2.6, -4.2, -6.0]
|
||||
off = ys[i] if i < len(ys) else None
|
||||
if i >= 7: # the imprint
|
||||
g = 1.12 if i == 7 else 1.0
|
||||
tilt = -0.14
|
||||
s.append(P(rotate(star(cx, cy, 1.9 * g, 1.68 * g, 18, i * 0.02), tilt, cx, cy), 0.1))
|
||||
s.append(P(rotate(ring(cx, cy, 1.45 * g, 20, 0, 0.03), tilt, cx, cy), 0.06))
|
||||
s.append(NUM(cx, cy + 0.02, 1.1 * g, rot=tilt))
|
||||
if 7 <= i <= 9:
|
||||
s += rays(cx, cy, 2.2, 2.8 + (i - 7) * 0.3, 10, 0.3, 0.09)
|
||||
if off is not None: # the stamp itself
|
||||
y = cy + off
|
||||
sq = 0.82 if i == 6 else 1.0
|
||||
s.append(K("blue"))
|
||||
s.append(P([(cx - 1.6, y - 0.2 * sq), (cx + 1.6, y - 0.2 * sq), (cx + 1.5, y - 0.75 * sq), (cx - 1.5, y - 0.75 * sq)]))
|
||||
s.append(P([(cx - 0.3, y - 0.75 * sq), (cx + 0.3, y - 0.75 * sq), (cx + 0.24, y - 1.7 * sq), (cx - 0.24, y - 1.7 * sq)]))
|
||||
s.append(C(cx, y - 2.05 * sq, 0.48))
|
||||
if i == 6:
|
||||
s.append(K("red"))
|
||||
s += rays(cx, y - 0.1, 1.9, 2.4, 8, 0.0, 0.1)
|
||||
return s
|
||||
|
||||
|
||||
ANIMS = [
|
||||
(megaphone, "yellow", "blare"), (slotmachine, "red", "jackpot"),
|
||||
(bannerplane, "blue", "propeller"), (cannon, "red", "kaboom"),
|
||||
(drum, "blue", "drumroll"), (pinata, "yellow", "whack"),
|
||||
(champagne, "blue", "uncork"), (stamp, "red", "kachunk"),
|
||||
]
|
||||
@@ -0,0 +1,123 @@
|
||||
"""Streak level 0's sounds: 2 s each, lively, one per animation in level0.py (same names as its ANIMS).
|
||||
|
||||
Each fn() returns a buf from tools/sound_kit.py; gen_sounds.py normalises and writes it as
|
||||
<name>.wav. Seed every random source (random.Random(n)) so the output never changes; level 0
|
||||
uses seeds 2000-2099 (level k: 2000 + 100 k, calm: 2900).
|
||||
"""
|
||||
import math
|
||||
import random
|
||||
|
||||
from sound_kit import SR, add_noise, add_tone, bell, sbuf
|
||||
|
||||
|
||||
def blare():
|
||||
"""Three brassy honks, each a bit higher, the last one held."""
|
||||
b = sbuf()
|
||||
for k, (st, f, dur) in enumerate(((0.25, 330, 0.25), (0.75, 392, 0.25), (1.25, 523, 0.65))):
|
||||
for ratio, a in ((1, 0.35), (2, 0.18), (3, 0.1)):
|
||||
add_tone(b, st, dur, f * ratio, f * ratio * 1.01, a, a=0.02, d=0.6, shape="saw", vib=(6, 0.01 * k))
|
||||
add_noise(b, st, 0.06, 0.15, a=0.002, d=0.03, lp0=0.6, seed=2001 + k)
|
||||
return b
|
||||
|
||||
|
||||
def jackpot():
|
||||
"""The reel clatters round, clunks to a stop, then a ding-ding and a shower of coins."""
|
||||
b = sbuf()
|
||||
for k in range(20): # the reel, slowing
|
||||
st = 0.25 + k * 0.04 + k * k * 0.0009
|
||||
add_noise(b, st, 0.02, 0.35, a=0.001, d=0.006, lp0=0.7, seed=2010 + k)
|
||||
add_tone(b, st, 0.02, 1800, amp=0.08, a=0.001, d=0.008)
|
||||
add_tone(b, 1.08, 0.12, 160, 90, 0.5, a=0.002, d=0.05)
|
||||
for st in (1.12, 1.27):
|
||||
bell(b, st, 1568, 0.35, 0.35)
|
||||
rng = random.Random(2030)
|
||||
for k in range(14): # coins
|
||||
bell(b, 1.4 + k * 0.035 + rng.uniform(0, 0.02), rng.uniform(2400, 3600), 0.12, 0.08)
|
||||
return b
|
||||
|
||||
|
||||
def propeller():
|
||||
"""A little plane's engine buzzing past (rising, then falling away), with a happy toot."""
|
||||
b = sbuf()
|
||||
ph = 0.0
|
||||
for k in range(int(SR * 2.0)):
|
||||
t = k / SR
|
||||
f = 120 * (1.15 if t < 1.0 else 1.15 * (0.85 + 0.15 * math.exp(-(t - 1.0) * 3)))
|
||||
ph += 2 * math.pi * f / SR
|
||||
am = 0.6 + 0.4 * math.sin(2 * math.pi * 28 * t)
|
||||
loud = min(1.0, t / 0.6) * min(1.0, (2.0 - t) / 0.7)
|
||||
b[k] += (((ph / (2 * math.pi)) % 1.0) * 2 - 1) * 0.3 * am * loud
|
||||
for st, f in ((0.9, 784), (1.05, 988)):
|
||||
add_tone(b, st, 0.14, f, amp=0.2, a=0.005, d=0.1, shape="square")
|
||||
return b
|
||||
|
||||
|
||||
def kaboom():
|
||||
"""A fizzing fuse, a big BOOM, a whistle up and over, and a bonk on landing."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 0.5, 0.25, a=0.02, d=0.5, lp0=0.9, lp1=0.7, seed=2040)
|
||||
add_noise(b, 0.5, 0.6, 0.9, a=0.001, d=0.18, lp0=0.5, lp1=0.03, seed=2041)
|
||||
add_tone(b, 0.5, 0.5, 90, 38, 0.8, a=0.001, d=0.2)
|
||||
add_tone(b, 0.62, 0.7, 700, 1500, 0.12, a=0.05, d=0.5)
|
||||
add_tone(b, 1.32, 0.3, 1500, 900, 0.1, a=0.01, d=0.15)
|
||||
add_tone(b, 1.4, 0.2, 220, 110, 0.5, a=0.001, d=0.06)
|
||||
add_tone(b, 1.62, 0.15, 260, 150, 0.25, a=0.001, d=0.05)
|
||||
return b
|
||||
|
||||
|
||||
def drumroll():
|
||||
"""A snare roll that swells, then a cymbal crash on a low tom."""
|
||||
b = sbuf()
|
||||
for k in range(26): # the roll
|
||||
st = 0.05 + k * 0.04
|
||||
add_noise(b, st, 0.05, 0.12 + k * 0.012, a=0.001, d=0.02, lp0=0.6, seed=2050 + k)
|
||||
add_tone(b, st, 0.03, 200, 180, 0.06 + k * 0.004, a=0.001, d=0.015)
|
||||
add_noise(b, 1.1, 0.9, 0.7, a=0.002, d=0.35, lp0=0.95, lp1=0.6, seed=2080)
|
||||
add_tone(b, 1.1, 0.5, 110, 70, 0.6, a=0.002, d=0.15)
|
||||
for f in (3200, 4700, 6100):
|
||||
add_tone(b, 1.1, 0.9, f, amp=0.04, a=0.002, d=0.3)
|
||||
return b
|
||||
|
||||
|
||||
def whack():
|
||||
"""Two hollow whacks, a third that bursts, then sweets pattering down."""
|
||||
b = sbuf()
|
||||
for k, st in enumerate((0.3, 0.72, 1.12)):
|
||||
add_noise(b, st, 0.12, 0.6 + 0.2 * k, a=0.001, d=0.03, lp0=0.35, seed=2060 + k)
|
||||
add_tone(b, st, 0.15, 240 - k * 30, 120, 0.5, a=0.001, d=0.05)
|
||||
add_noise(b, 1.12, 0.4, 0.4, a=0.001, d=0.1, lp0=0.8, lp1=0.2, seed=2064)
|
||||
rng = random.Random(2065)
|
||||
for k in range(16):
|
||||
add_tone(b, 1.25 + k * 0.04 + rng.uniform(0, 0.03), 0.03, rng.uniform(1200, 2400), amp=0.15, a=0.001, d=0.012)
|
||||
return b
|
||||
|
||||
|
||||
def uncork():
|
||||
"""A rattling shake, a big POP, and a long bright fizz of bubbles."""
|
||||
b = sbuf()
|
||||
for k in range(8):
|
||||
add_noise(b, 0.2 + k * 0.05, 0.04, 0.15, a=0.001, d=0.015, lp0=0.4, seed=2070 + k)
|
||||
add_tone(b, 0.68, 0.08, 1100, 300, 0.7, a=0.0005, d=0.02)
|
||||
add_noise(b, 0.68, 0.1, 0.6, a=0.0005, d=0.015, lp0=0.9, seed=2079)
|
||||
add_noise(b, 0.72, 1.28, 0.35, a=0.03, d=0.6, lp0=0.95, lp1=0.85, seed=2081)
|
||||
rng = random.Random(2082)
|
||||
for k in range(18):
|
||||
f = rng.uniform(900, 2000)
|
||||
add_tone(b, 0.75 + k * 0.065, 0.05, f, f * 1.6, 0.1, a=0.002, d=0.02)
|
||||
return b
|
||||
|
||||
|
||||
def kachunk():
|
||||
"""A wind-up, a heavy KA-CHUNK, and a brassy ta-da."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.0, 0.5, 200, 420, 0.15, a=0.3, d=0.3, shape="tri")
|
||||
add_tone(b, 0.55, 0.25, 110, 45, 0.9, a=0.001, d=0.08)
|
||||
add_noise(b, 0.55, 0.2, 0.6, a=0.001, d=0.04, lp0=0.3, seed=2090)
|
||||
add_noise(b, 0.66, 0.08, 0.3, a=0.001, d=0.02, lp0=0.8, seed=2091)
|
||||
for st, chord, dur in ((1.0, (392, 494, 587), 0.15), (1.18, (523, 659, 784), 0.75)):
|
||||
for f in chord:
|
||||
add_tone(b, st, dur, f, amp=0.12, a=0.01, d=0.5, shape="saw", vib=(5, 0.006))
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [blare, jackpot, propeller, kaboom, drumroll, whack, uncork, kachunk]
|
||||
@@ -0,0 +1,537 @@
|
||||
"""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"),
|
||||
]
|
||||
@@ -0,0 +1,162 @@
|
||||
"""Streak level 1's sounds: 2 s each, one per animation in level1.py (same names as its ANIMS).
|
||||
Seeds 2100-2199.
|
||||
"""
|
||||
import functools
|
||||
import random
|
||||
|
||||
from sound_kit import add_noise, add_tone, bell, ease_off, sbuf
|
||||
|
||||
|
||||
def tail(fn):
|
||||
"""Soften the last quarter second, so nothing still ringing stops dead at 2 s."""
|
||||
@functools.wraps(fn)
|
||||
def wrapped():
|
||||
return ease_off(fn(), 0.25)
|
||||
return wrapped
|
||||
|
||||
|
||||
def buzz(b, start, dur, f, amp=0.2, vib=(0, 0), seed=0):
|
||||
"""A reedy, buzzy note (a kazoo-ish saw with a touch of breath)."""
|
||||
for ratio, a in ((1, 1.0), (2, 0.5), (3, 0.3)):
|
||||
add_tone(b, start, dur, f * ratio, amp=amp * a, a=0.02, d=2.0, shape="saw", vib=vib)
|
||||
add_noise(b, start, dur, amp * 0.25, a=0.02, d=1.0, lp0=0.5, seed=seed)
|
||||
|
||||
|
||||
@tail
|
||||
def dingaling():
|
||||
"""A wind-up, a hefty THWACK, a slide whistle racing up, a bright bell ringing out, and a slide back down."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.05, 0.45, 0.12, a=0.3, d=0.2, lp0=0.2, lp1=0.6, seed=2100)
|
||||
add_tone(b, 0.58, 0.2, 140, 55, 0.9, a=0.001, d=0.06)
|
||||
add_noise(b, 0.58, 0.12, 0.7, a=0.001, d=0.03, lp0=0.4, seed=2101)
|
||||
add_tone(b, 0.6, 0.33, 500, 1900, 0.18, a=0.01, d=1.0, shape="tri")
|
||||
for st in (0.92, 1.12, 1.3):
|
||||
bell(b, st, 1320, 0.32 if st < 1 else 0.18, 0.7)
|
||||
add_tone(b, 1.45, 0.5, 1500, 400, 0.08, a=0.05, d=0.6, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def swoosh():
|
||||
"""Two bounces, a rising whoosh as the ball arcs, a soft net SWISH, a scoreboard buzzer, then the ball dribbling away."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.02, 0.12, 130, 80, 0.5, a=0.001, d=0.04)
|
||||
add_noise(b, 0.15, 0.6, 0.18, a=0.3, d=0.4, lp0=0.15, lp1=0.5, seed=2110)
|
||||
add_noise(b, 0.83, 0.3, 0.55, a=0.01, d=0.08, lp0=0.95, lp1=0.6, seed=2111)
|
||||
for f in (440, 554, 659):
|
||||
add_tone(b, 0.88, 0.5, f, amp=0.1, a=0.005, d=1.0, shape="square")
|
||||
for k, st in enumerate((1.08, 1.42, 1.58, 1.72, 1.82)):
|
||||
add_tone(b, st, 0.1, 150, 85, 0.5 - k * 0.07, a=0.001, d=0.035)
|
||||
add_noise(b, st, 0.04, 0.2 - k * 0.03, a=0.001, d=0.01, lp0=0.3, seed=2112 + k)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def pinfall():
|
||||
"""A heavy ball rumbling down the lane, a great clattering crash of pins, and a two-note ding of triumph."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 0.7, 0.3, a=0.25, d=1.0, lp0=0.03, lp1=0.08, seed=2120)
|
||||
add_tone(b, 0.0, 0.7, 55, 70, 0.25, a=0.25, d=1.0)
|
||||
add_noise(b, 0.67, 0.4, 0.7, a=0.001, d=0.12, lp0=0.6, lp1=0.2, seed=2121)
|
||||
rng = random.Random(2122)
|
||||
for k in range(22):
|
||||
st = 0.67 + rng.uniform(0, 0.45) * (k / 22) ** 0.6
|
||||
f = rng.uniform(600, 1500)
|
||||
add_tone(b, st, 0.06, f, f * 0.9, 0.18, a=0.001, d=0.02)
|
||||
add_tone(b, st, 0.05, f * 2.3, amp=0.06, a=0.001, d=0.01)
|
||||
bell(b, 1.3, 1047, 0.25, 0.4)
|
||||
bell(b, 1.45, 1568, 0.3, 0.6)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def crankle():
|
||||
"""A crank ratchets round, click by click; a capsule clunks down the chute and rattles off, then pops open with a springy boing and a sparkle."""
|
||||
b = sbuf()
|
||||
for k in range(5):
|
||||
for m in range(3):
|
||||
st = k * 0.167 + m * 0.035
|
||||
add_noise(b, st, 0.02, 0.35, a=0.001, d=0.005, lp0=0.8, seed=2130 + k * 3 + m)
|
||||
add_tone(b, st, 0.02, 2200, amp=0.06, a=0.001, d=0.006)
|
||||
add_tone(b, 0.7, 0.12, 200, 120, 0.6, a=0.001, d=0.04)
|
||||
for k in range(9):
|
||||
st = 0.78 + k * 0.045
|
||||
add_tone(b, st, 0.03, 600 + 40 * (k % 3), amp=0.15 - k * 0.012, a=0.001, d=0.012)
|
||||
add_tone(b, 1.33, 0.07, 900, 300, 0.6, a=0.0005, d=0.02)
|
||||
add_tone(b, 1.35, 0.45, 220, 660, 0.25, a=0.005, d=0.4, vib=(18, 0.08))
|
||||
rng = random.Random(2150)
|
||||
for k in range(6):
|
||||
bell(b, 1.45 + k * 0.06, rng.uniform(2600, 3600), 0.08, 0.15)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def arf():
|
||||
"""A little bark, a whoosh as the ball is flipped up, a pop, a soft plonk on the nose, then happy barking over flipper claps."""
|
||||
b = sbuf()
|
||||
|
||||
def bark(st, f, amp):
|
||||
for ratio, a in ((1, 1.0), (2, 0.6), (3, 0.4), (4, 0.2)):
|
||||
add_tone(b, st, 0.16, f * ratio, f * ratio * 0.7, amp * a, a=0.01, d=0.07, shape="saw")
|
||||
add_noise(b, st, 0.1, amp * 0.5, a=0.005, d=0.04, lp0=0.35, seed=int(st * 1000) + 2160)
|
||||
bark(0.1, 330, 0.35)
|
||||
add_noise(b, 0.45, 0.4, 0.2, a=0.1, d=0.3, lp0=0.2, lp1=0.6, seed=2161)
|
||||
add_tone(b, 0.92, 0.06, 1200, 400, 0.4, a=0.0005, d=0.02)
|
||||
add_tone(b, 1.25, 0.1, 500, 380, 0.4, a=0.001, d=0.04, shape="tri")
|
||||
for k, st in enumerate((1.35, 1.6, 1.82)):
|
||||
bark(st, 360 + 30 * k, 0.32)
|
||||
for k in range(5):
|
||||
add_noise(b, 1.28 + k * 0.17, 0.05, 0.4, a=0.001, d=0.015, lp0=0.7, seed=2170 + k)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def slinkety():
|
||||
"""Three metallic shimmy-clinks as the coil flops down step by step, then a long springy BOI-OING and a pop."""
|
||||
b = sbuf()
|
||||
for k, st in enumerate((0.08, 0.5, 0.92)):
|
||||
add_tone(b, st, 0.3, 900 + 80 * k, 2200 + 80 * k, 0.08, a=0.05, d=0.2, vib=(30, 0.05))
|
||||
land = st + 0.3
|
||||
for m in range(4):
|
||||
add_tone(b, land + m * 0.025, 0.12, 3100 - m * 300, amp=0.12 - m * 0.02, a=0.001, d=0.03)
|
||||
add_tone(b, land, 0.1, 180, 120, 0.3, a=0.001, d=0.03)
|
||||
add_tone(b, 1.3, 0.6, 180, 520, 0.4, a=0.005, d=0.35, vib=(16, 0.12))
|
||||
add_tone(b, 1.3, 0.6, 360, 1040, 0.12, a=0.005, d=0.3, vib=(16, 0.12), shape="tri")
|
||||
add_tone(b, 1.42, 0.06, 1400, 500, 0.4, a=0.0005, d=0.02)
|
||||
rng = random.Random(2185)
|
||||
for k in range(5):
|
||||
bell(b, 1.5 + k * 0.07, rng.uniform(2200, 3200), 0.07, 0.15)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def unwrap():
|
||||
"""Two papery hops, a big pop as the lid flies, a flurry of rising squeals from the streamers, and a bright ta-da."""
|
||||
b = sbuf()
|
||||
for k, st in enumerate((0.33, 0.71)):
|
||||
add_tone(b, st, 0.12, 180, 110, 0.4, a=0.001, d=0.04)
|
||||
add_noise(b, st, 0.15, 0.3, a=0.003, d=0.06, lp0=0.7, seed=2140 + k)
|
||||
add_tone(b, 1.0, 0.08, 1300, 350, 0.6, a=0.0005, d=0.02)
|
||||
add_noise(b, 1.0, 0.1, 0.5, a=0.0005, d=0.03, lp0=0.9, seed=2143)
|
||||
rng = random.Random(2144)
|
||||
for k in range(7):
|
||||
f = rng.uniform(700, 1100)
|
||||
add_tone(b, 1.03 + k * 0.04, 0.3, f, f * 2.2, 0.08, a=0.01, d=0.2, vib=(25, 0.03))
|
||||
for f in (523, 659, 784, 1047):
|
||||
add_tone(b, 1.3, 0.65, f, amp=0.09, a=0.01, d=0.5, shape="tri", vib=(5, 0.005))
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def razz():
|
||||
"""A party blower's raspy toot as it unrolls, half back, then one long proud BLAAAT and a little twinkle."""
|
||||
b = sbuf()
|
||||
buzz(b, 0.15, 0.38, 392, 0.25, vib=(9, 0.02), seed=2190)
|
||||
add_tone(b, 0.5, 0.12, 392, 330, 0.05, a=0.01, d=0.05, shape="saw")
|
||||
buzz(b, 0.72, 0.95, 523, 0.3, vib=(7, 0.025), seed=2191)
|
||||
for k in range(4):
|
||||
bell(b, 1.75 + k * 0.05, 2400 + k * 400, 0.06, 0.12)
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [dingaling, swoosh, pinfall, crankle, arf, slinkety, unwrap, razz]
|
||||
@@ -0,0 +1,548 @@
|
||||
"""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"),
|
||||
]
|
||||
@@ -0,0 +1,180 @@
|
||||
"""Streak level 2's sounds: 2 s each, one per animation in level2.py (same names as its ANIMS).
|
||||
Seeds 2200-2299.
|
||||
"""
|
||||
import functools
|
||||
import math
|
||||
import random
|
||||
|
||||
from sound_kit import SR, add_noise, add_tone, bell, ease_off, sbuf
|
||||
|
||||
|
||||
def tail(fn):
|
||||
"""Soften the last quarter second, so nothing still ringing stops dead at 2 s."""
|
||||
@functools.wraps(fn)
|
||||
def wrapped():
|
||||
return ease_off(fn(), 0.25)
|
||||
return wrapped
|
||||
|
||||
|
||||
def crackles(b, start, dur, rate, amp, seed, f=(2500, 6000)):
|
||||
"""Random tiny clicks: fizz, sparks, frying."""
|
||||
rng = random.Random(seed)
|
||||
for _ in range(int(dur * rate)):
|
||||
st = start + rng.uniform(0, dur)
|
||||
add_tone(b, st, 0.012, rng.uniform(*f), amp=amp * rng.uniform(0.3, 1.0), a=0.0005, d=0.003)
|
||||
|
||||
|
||||
@tail
|
||||
def plinkety():
|
||||
"""A fairground jingle under three popgun shots, each a tok and a tinny ping, a clack as the board flips, and a ding-ding-ding win."""
|
||||
b = sbuf()
|
||||
tune = [523, 659, 784, 659, 587, 698, 880, 698]
|
||||
for k, f in enumerate(tune):
|
||||
add_tone(b, k * 0.14, 0.12, f, amp=0.06, a=0.005, d=0.08, shape="square")
|
||||
for k, st in enumerate((0.3, 0.63, 0.96)):
|
||||
add_noise(b, st, 0.05, 0.6, a=0.0005, d=0.012, lp0=0.6, seed=2200 + k)
|
||||
add_tone(b, st, 0.04, 600, 250, 0.4, a=0.0005, d=0.012)
|
||||
bell(b, st + 0.04, 2100 + k * 250, 0.22, 0.18)
|
||||
add_tone(b, 1.12, 0.06, 400, 200, 0.4, a=0.0005, d=0.02, shape="square")
|
||||
add_noise(b, 1.12, 0.05, 0.3, a=0.0005, d=0.015, lp0=0.5, seed=2205)
|
||||
for k in range(3):
|
||||
bell(b, 1.25 + k * 0.13, 1568, 0.25, 0.35)
|
||||
for f in (523, 659, 784):
|
||||
add_tone(b, 1.65, 0.35, f, amp=0.07, a=0.01, d=0.3, shape="square")
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def bumpers():
|
||||
"""A plunger stretched and let go, three electric bumper bonks, a flipper clack, then multiball: a jangling cascade of bonks and beeps."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.0, 0.25, 300, 160, 0.12, a=0.2, d=0.3, shape="tri")
|
||||
add_noise(b, 0.25, 0.25, 0.25, a=0.005, d=0.1, lp0=0.4, lp1=0.9, seed=2210)
|
||||
|
||||
def bonk(st, f, amp):
|
||||
add_tone(b, st, 0.12, f, f * 0.7, amp, a=0.001, d=0.05, shape="square")
|
||||
add_noise(b, st, 0.03, amp * 0.6, a=0.0005, d=0.01, lp0=0.8, seed=int(st * 997) + 2211)
|
||||
for k, st in enumerate((0.42, 0.58, 0.75)):
|
||||
bonk(st, 660 + 110 * k, 0.3)
|
||||
add_tone(b, 0.92, 0.06, 220, 120, 0.4, a=0.0005, d=0.02)
|
||||
add_noise(b, 0.92, 0.05, 0.3, a=0.0005, d=0.015, lp0=0.4, seed=2220)
|
||||
rng = random.Random(2221)
|
||||
for k in range(16):
|
||||
st = 1.0 + k * 0.058
|
||||
bonk(st, rng.choice((660, 770, 880, 990, 1320)), 0.18)
|
||||
for k, f in enumerate((523, 659, 784, 1047, 1319)):
|
||||
add_tone(b, 1.0 + k * 0.07, 0.15, f, amp=0.1, a=0.002, d=0.1, shape="square")
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def spindle():
|
||||
"""The candyfloss tub's motor whirring up with airy whooshes, then a sugary harp sweep and sparkles."""
|
||||
b = sbuf()
|
||||
ph = 0.0
|
||||
for k in range(int(SR * 1.15)):
|
||||
t = k / SR
|
||||
f = 90 + 80 * t
|
||||
ph += 2 * math.pi * f / SR
|
||||
am = 0.7 + 0.3 * math.sin(2 * math.pi * (6 + 10 * t) * t)
|
||||
loud = min(1.0, t / 0.15) * (1.0 if t < 1.0 else (1.15 - t) / 0.15)
|
||||
b[k] += (((ph / (2 * math.pi)) % 1.0) * 2 - 1) * 0.12 * am * loud
|
||||
for k in range(6):
|
||||
add_noise(b, k * 0.18, 0.18, 0.15, a=0.06, d=0.1, lp0=0.2, lp1=0.6, seed=2230 + k)
|
||||
for k, f in enumerate((523, 587, 659, 784, 880, 1047, 1175, 1319, 1568)):
|
||||
add_pl = 1.08 + k * 0.045
|
||||
add_tone(b, add_pl, 0.5, f, amp=0.14, a=0.002, d=0.25, shape="tri")
|
||||
rng = random.Random(2240)
|
||||
for k in range(8):
|
||||
bell(b, 1.4 + k * 0.06, rng.uniform(2600, 4000), 0.07, 0.15)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def crowdroar():
|
||||
"""A thumping kick, the ball whizzing, a SWISH of net, and a stadium crowd erupting with whistles."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.33, 0.12, 120, 60, 0.8, a=0.001, d=0.04)
|
||||
add_noise(b, 0.33, 0.06, 0.4, a=0.0005, d=0.015, lp0=0.3, seed=2250)
|
||||
add_noise(b, 0.36, 0.4, 0.2, a=0.05, d=0.3, lp0=0.6, lp1=0.9, seed=2251)
|
||||
add_tone(b, 0.36, 0.4, 900, 1300, 0.05, a=0.05, d=0.3)
|
||||
add_noise(b, 0.75, 0.2, 0.45, a=0.01, d=0.08, lp0=0.9, lp1=0.5, seed=2252)
|
||||
for k in range(5): # the crowd: layers of soft roaring noise
|
||||
add_noise(b, 0.78 + k * 0.03, 1.22, 0.16, a=0.25, d=1.5, lp0=0.12 + 0.05 * k, seed=2253 + k)
|
||||
rng = random.Random(2260)
|
||||
for k in range(40): # voices in it
|
||||
st = 0.85 + rng.uniform(0, 1.0)
|
||||
f = rng.uniform(250, 600)
|
||||
add_tone(b, st, 0.3, f, f * rng.uniform(1.05, 1.3), 0.03, a=0.05, d=0.15, shape="saw")
|
||||
for st, f in ((1.0, 2400), (1.35, 2700)): # whistles
|
||||
add_tone(b, st, 0.25, f, f * 1.15, 0.08, a=0.02, d=0.3, vib=(9, 0.01))
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def dodgem():
|
||||
"""Two electric hums zooming in with crackling sparks, a big CRUNCH-BONK, two springy rebounds, and sparks fizzing down."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.0, 0.67, 80, 160, 0.15, a=0.1, d=2.0, shape="saw")
|
||||
add_tone(b, 0.0, 0.67, 95, 185, 0.12, a=0.1, d=2.0, shape="saw")
|
||||
crackles(b, 0.0, 0.67, 40, 0.2, 2270)
|
||||
add_noise(b, 0.67, 0.3, 0.8, a=0.0005, d=0.07, lp0=0.5, lp1=0.15, seed=2271)
|
||||
add_tone(b, 0.67, 0.25, 110, 50, 0.8, a=0.001, d=0.08)
|
||||
bell(b, 0.68, 520, 0.2, 0.15)
|
||||
for st in (0.8, 0.95):
|
||||
add_tone(b, st, 0.25, 250, 500, 0.15, a=0.005, d=0.12, vib=(20, 0.1))
|
||||
crackles(b, 0.68, 1.25, 70, 0.3, 2272)
|
||||
add_noise(b, 0.7, 1.25, 0.1, a=0.02, d=1.0, lp0=0.95, seed=2273)
|
||||
for k, f in enumerate((784, 988, 1175, 1568)):
|
||||
add_tone(b, 1.05 + k * 0.1, 0.5, f, amp=0.2, a=0.005, d=0.4, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def rawr():
|
||||
"""A tom-tom roll, a whooshing leap through fire, a soft paw landing, and a big lion ROAR."""
|
||||
b = sbuf()
|
||||
for k in range(8):
|
||||
add_tone(b, k * 0.04, 0.08, 130, 100, 0.12 + 0.03 * k, a=0.001, d=0.04)
|
||||
add_noise(b, 0.33, 0.6, 0.4, a=0.15, d=0.3, lp0=0.08, lp1=0.4, seed=2280)
|
||||
crackles(b, 0.4, 0.8, 50, 0.12, 2281, (1200, 3500))
|
||||
add_tone(b, 0.95, 0.1, 140, 80, 0.4, a=0.002, d=0.04)
|
||||
for ratio, a in ((1, 0.5), (2, 0.3), (3, 0.2), (5, 0.08)): # the roar: a growling, swelling saw
|
||||
add_tone(b, 1.08, 0.75, 120 * ratio, 85 * ratio, a * 0.5, a=0.12, d=0.5, shape="saw", vib=(28, 0.06))
|
||||
add_noise(b, 1.08, 0.75, 0.3, a=0.1, d=0.4, lp0=0.2, seed=2282)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def fizzle():
|
||||
"""Three soft cakey thumps as the tiers land, a match struck, and sparklers spitting and fizzing over a happy little tune."""
|
||||
b = sbuf()
|
||||
for k, st in enumerate((0.17, 0.42, 0.67)):
|
||||
add_tone(b, st, 0.15, 150 - 15 * k, 70, 0.5, a=0.002, d=0.05)
|
||||
add_noise(b, st, 0.08, 0.25, a=0.002, d=0.03, lp0=0.25, seed=2290 + k)
|
||||
add_noise(b, 0.92, 0.12, 0.4, a=0.003, d=0.05, lp0=0.9, lp1=0.4, seed=2293)
|
||||
add_noise(b, 1.0, 1.0, 0.18, a=0.03, d=2.0, lp0=0.95, seed=2294)
|
||||
crackles(b, 1.0, 1.0, 140, 0.25, 2295)
|
||||
for k, f in enumerate((784, 784, 880, 784, 1047, 988)):
|
||||
add_tone(b, 1.05 + k * 0.15, 0.14, f, amp=0.1, a=0.005, d=0.12, shape="tri")
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def sizzle():
|
||||
"""A frying pan sizzling, three flips (whoosh, flop), a whistling spin for the last, a ding as it lands, and a glug of syrup."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 2.0, 0.08, a=0.1, d=3.0, lp0=0.9, seed=2296)
|
||||
crackles(b, 0.0, 2.0, 50, 0.1, 2297, (3000, 7000))
|
||||
for k, (st, land) in enumerate(((0.08, 0.42), (0.42, 0.75), (0.75, 1.08))):
|
||||
add_noise(b, st, 0.15, 0.25, a=0.02, d=0.06, lp0=0.3, lp1=0.7, seed=2210 + k)
|
||||
add_tone(b, land, 0.1, 160, 110, 0.4, a=0.002, d=0.04)
|
||||
add_noise(b, land, 0.06, 0.2, a=0.002, d=0.03, lp0=0.2, seed=2220 + k)
|
||||
add_tone(b, 1.08, 0.4, 700, 1400, 0.12, a=0.02, d=0.5, vib=(12, 0.08))
|
||||
bell(b, 1.5, 1319, 0.3, 0.4)
|
||||
for k in range(5): # syrup glugs
|
||||
add_tone(b, 1.58 + k * 0.07, 0.07, 180 + 20 * k, 320 + 30 * k, 0.2, a=0.005, d=0.03)
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [plinkety, bumpers, spindle, crowdroar, dodgem, rawr, fizzle, sizzle]
|
||||
@@ -0,0 +1,611 @@
|
||||
"""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"),
|
||||
]
|
||||
@@ -0,0 +1,194 @@
|
||||
"""Streak level 3's sounds: 2 s each, one per animation in level3.py (same names as its ANIMS).
|
||||
Seeds 2300-2399.
|
||||
"""
|
||||
import functools
|
||||
import random
|
||||
|
||||
from sound_kit import add_noise, add_tone, bell, ease_off, sbuf
|
||||
|
||||
|
||||
def tail(fn):
|
||||
"""Soften the last quarter second, so nothing still ringing stops dead at 2 s."""
|
||||
@functools.wraps(fn)
|
||||
def wrapped():
|
||||
return ease_off(fn(), 0.25)
|
||||
return wrapped
|
||||
|
||||
|
||||
def crackles(b, start, dur, rate, amp, seed, f=(2500, 6000)):
|
||||
"""Random tiny clicks: fizz, sparks, crackling fireworks."""
|
||||
rng = random.Random(seed)
|
||||
for _ in range(int(dur * rate)):
|
||||
st = start + rng.uniform(0, dur)
|
||||
add_tone(b, st, 0.012, rng.uniform(*f), amp=amp * rng.uniform(0.3, 1.0), a=0.0005, d=0.003)
|
||||
|
||||
|
||||
def pop(b, st, amp, seed):
|
||||
"""A firework's thump and crackle."""
|
||||
add_tone(b, st, 0.15, 160, 60, amp, a=0.001, d=0.05)
|
||||
add_noise(b, st, 0.25, amp * 0.7, a=0.001, d=0.06, lp0=0.6, lp1=0.2, seed=seed)
|
||||
crackles(b, st + 0.05, 0.4, 60, amp * 0.4, seed + 1)
|
||||
|
||||
|
||||
def organ(b, st, dur, f, amp):
|
||||
"""A steam-organ pipe: square and triangle, with a wobble."""
|
||||
add_tone(b, st, dur, f, amp=amp, a=0.01, d=0.5, shape="square", vib=(6, 0.008))
|
||||
add_tone(b, st, dur, f * 2, amp=amp * 0.4, a=0.01, d=0.5, shape="tri", vib=(6, 0.008))
|
||||
|
||||
|
||||
@tail
|
||||
def skyride():
|
||||
"""The big wheel creaks round while its lights tinkle on, climbing; fireworks thump behind it and a bright chord rings out as the hub lights up."""
|
||||
b = sbuf()
|
||||
for k in range(3):
|
||||
add_tone(b, 0.05 + k * 0.25, 0.2, 180, 150, 0.08, a=0.05, d=0.1, shape="saw", vib=(30, 0.05))
|
||||
for k, f in enumerate((784, 880, 988, 1175, 1319, 1568, 1760, 2093)):
|
||||
bell(b, 0.5 + k * 0.035, f, 0.1, 0.2)
|
||||
for f in (523, 659, 784, 1047):
|
||||
add_tone(b, 0.75, 1.2, f, amp=0.1, a=0.02, d=0.8, shape="tri", vib=(5, 0.006))
|
||||
for k in range(4):
|
||||
pop(b, 0.67 + k * 0.25, 0.35, 2300 + 10 * k)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def clackety():
|
||||
"""The chain lift clacking up, a breathless pause, a roaring plunge round the loop with whoops, then fireworks and a cheer."""
|
||||
b = sbuf()
|
||||
for k in range(14): # the chain
|
||||
st = 0.02 + k * 0.038
|
||||
add_noise(b, st, 0.02, 0.35, a=0.0005, d=0.006, lp0=0.6, seed=2340 + k)
|
||||
add_tone(b, st, 0.02, 900, amp=0.08, a=0.0005, d=0.006)
|
||||
add_noise(b, 0.6, 0.9, 0.5, a=0.15, d=0.6, lp0=0.08, lp1=0.25, seed=2360)
|
||||
add_tone(b, 0.6, 0.9, 70, 110, 0.35, a=0.15, d=0.6, shape="saw")
|
||||
rng = random.Random(2361)
|
||||
for k in range(4): # whoops from the riders
|
||||
f = rng.uniform(700, 1000)
|
||||
add_tone(b, 0.65 + k * 0.12, 0.4, f, f * 1.5, 0.07, a=0.03, d=0.3, vib=(8, 0.04))
|
||||
for k in range(3):
|
||||
pop(b, 1.08 + k * 0.17, 0.35, 2370 + 10 * k)
|
||||
add_noise(b, 1.1, 0.9, 0.15, a=0.2, d=0.8, lp0=0.2, seed=2399)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def hupla():
|
||||
"""A soft drumroll under two swinging whooshes, a sharp HUP, three somersault swishes, a slap as hands catch, and a cymbal and ta-da."""
|
||||
b = sbuf()
|
||||
for k in range(13):
|
||||
add_noise(b, k * 0.04, 0.04, 0.08 + 0.006 * k, a=0.001, d=0.015, lp0=0.5, seed=2310 + k)
|
||||
for st in (0.0, 0.3):
|
||||
add_noise(b, st, 0.3, 0.2, a=0.12, d=0.12, lp0=0.15, lp1=0.4, seed=2330)
|
||||
for ratio, a in ((1, 1.0), (2, 0.5), (3, 0.3)): # the hup
|
||||
add_tone(b, 0.5, 0.1, 400 * ratio, 520 * ratio, 0.18 * a, a=0.005, d=0.05, shape="saw")
|
||||
for k in range(3):
|
||||
add_noise(b, 0.58 + k * 0.17, 0.15, 0.25, a=0.05, d=0.05, lp0=0.3, lp1=0.8, seed=2335 + k)
|
||||
add_noise(b, 1.08, 0.05, 0.6, a=0.0005, d=0.012, lp0=0.7, seed=2339)
|
||||
add_noise(b, 1.12, 0.85, 0.35, a=0.002, d=0.35, lp0=0.95, lp1=0.6, seed=2338)
|
||||
for f in (3200, 4700):
|
||||
add_tone(b, 1.12, 0.8, f, amp=0.04, a=0.002, d=0.3)
|
||||
for st, chord, dur in ((1.12, (392, 494, 587), 0.15), (1.3, (523, 659, 784), 0.65)):
|
||||
for f in chord:
|
||||
add_tone(b, st, dur, f, amp=0.1, a=0.01, d=0.5, shape="saw", vib=(5, 0.006))
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def photofinish():
|
||||
"""A starter's pistol, pounding footsteps getting faster, the tape snapping, then cheering, camera shutters and flashguns whining."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 0.2, 0.8, a=0.0005, d=0.04, lp0=0.9, lp1=0.3, seed=2350)
|
||||
st, k = 0.1, 0
|
||||
while st < 0.74:
|
||||
add_tone(b, st, 0.06, 110, 70, 0.4, a=0.001, d=0.02)
|
||||
add_noise(b, st, 0.03, 0.2, a=0.001, d=0.01, lp0=0.3, seed=2351 + k)
|
||||
st += 0.11 - 0.004 * k
|
||||
k += 1
|
||||
add_tone(b, 0.75, 0.06, 1500, 600, 0.4, a=0.0005, d=0.015)
|
||||
add_noise(b, 0.75, 0.08, 0.5, a=0.0005, d=0.02, lp0=0.95, seed=2372)
|
||||
for k in range(5):
|
||||
add_noise(b, 0.78 + k * 0.03, 1.2, 0.13, a=0.25, d=1.5, lp0=0.12 + 0.05 * k, seed=2373 + k)
|
||||
rng = random.Random(2380)
|
||||
for k in range(6): # shutters and flash whines
|
||||
st = 0.8 + k * 0.18 + rng.uniform(0, 0.05)
|
||||
add_noise(b, st, 0.03, 0.4, a=0.0005, d=0.008, lp0=0.8, seed=2381 + k)
|
||||
add_tone(b, st + 0.02, 0.2, 2500, 4500, 0.04, a=0.02, d=0.2)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def calliope():
|
||||
"""A steam-organ waltz, oom-pah-pah under a jolly tune, then fireworks bursting overhead."""
|
||||
b = sbuf()
|
||||
beat = 0.19
|
||||
bass = [131, 196, 196, 147, 220, 220, 131, 196, 196, 165, 247, 247]
|
||||
for k, f in enumerate(bass[:10]):
|
||||
organ(b, k * beat, beat * 0.8, f if k % 3 == 0 else f * 2, 0.08 if k % 3 == 0 else 0.05)
|
||||
tune = [(0, 659, 2), (2, 784, 1), (3, 880, 2), (5, 784, 1), (6, 1047, 3), (9, 988, 1)]
|
||||
for st, f, n in tune:
|
||||
organ(b, st * beat, n * beat * 0.92, f, 0.09)
|
||||
for f in (523, 659, 784):
|
||||
organ(b, 10 * beat, 0.4, f, 0.07)
|
||||
for k in range(3):
|
||||
pop(b, 0.83 + k * 0.17, 0.3, 2320 + 10 * k)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def airhorn():
|
||||
"""A thumping kick, a whistle up and over, then a blaring stadium air horn, twice, and fireworks."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.25, 0.12, 120, 55, 0.8, a=0.001, d=0.04)
|
||||
add_noise(b, 0.25, 0.06, 0.5, a=0.0005, d=0.015, lp0=0.4, seed=2390)
|
||||
add_tone(b, 0.3, 0.55, 600, 1400, 0.08, a=0.05, d=0.5, shape="tri")
|
||||
for st, dur in ((0.83, 0.25), (1.15, 0.6)):
|
||||
for f in (466, 587, 698):
|
||||
for ratio, a in ((1, 1.0), (2, 0.4)):
|
||||
add_tone(b, st, dur, f * ratio, f * ratio * 0.99, 0.1 * a, a=0.01, d=1.0, shape="saw")
|
||||
for k in range(4):
|
||||
pop(b, 0.9 + k * 0.17, 0.3, 2391 + k)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def tossup():
|
||||
"""Clubs and balls slapping hand to hand, faster and faster, a big whoosh as everything flies up, a slide whistle, and a ringing catch with bells whirling round."""
|
||||
b = sbuf()
|
||||
st, k = 0.05, 0
|
||||
while st < 1.12:
|
||||
f = 500 if k % 2 else 380
|
||||
add_tone(b, st, 0.05, f, f * 0.8, 0.25, a=0.001, d=0.02)
|
||||
add_noise(b, st, 0.03, 0.15, a=0.001, d=0.01, lp0=0.4, seed=2315 + k)
|
||||
st += max(0.07, 0.17 - 0.008 * k)
|
||||
k += 1
|
||||
add_noise(b, 1.15, 0.35, 0.35, a=0.03, d=0.2, lp0=0.2, lp1=0.8, seed=2398)
|
||||
add_tone(b, 1.15, 0.3, 500, 1500, 0.12, a=0.02, d=0.4, shape="tri")
|
||||
bell(b, 1.27, 1568, 0.3, 0.6)
|
||||
for k in range(8):
|
||||
bell(b, 1.35 + k * 0.07, [1319, 1568, 1760, 2093][k % 4], 0.08, 0.2)
|
||||
return b
|
||||
|
||||
|
||||
@tail
|
||||
def kersplash():
|
||||
"""A throw, a clanging bullseye, the plank's clunk, a long fall, a huge SPLOOSH with drops raining down, and a honk of the clown's horn."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.05, 0.35, 0.15, a=0.1, d=0.2, lp0=0.2, lp1=0.6, seed=2325)
|
||||
bell(b, 0.42, 880, 0.35, 0.35)
|
||||
add_noise(b, 0.42, 0.05, 0.4, a=0.0005, d=0.01, lp0=0.7, seed=2326)
|
||||
add_tone(b, 0.55, 0.1, 200, 110, 0.5, a=0.001, d=0.03)
|
||||
add_tone(b, 0.6, 0.2, 900, 400, 0.08, a=0.01, d=0.2, shape="tri")
|
||||
add_noise(b, 0.75, 0.6, 0.9, a=0.003, d=0.2, lp0=0.5, lp1=0.1, seed=2327)
|
||||
add_tone(b, 0.75, 0.25, 90, 45, 0.6, a=0.002, d=0.1)
|
||||
rng = random.Random(2328)
|
||||
for k in range(16): # drops falling back
|
||||
st = 0.95 + rng.uniform(0, 0.6)
|
||||
f = rng.uniform(700, 1600)
|
||||
add_tone(b, st, 0.05, f, f * 1.7, 0.1, a=0.002, d=0.02)
|
||||
for st in (1.35, 1.55):
|
||||
for ratio, a in ((1, 1.0), (2, 0.5), (3, 0.3)):
|
||||
add_tone(b, st, 0.15, 330 * ratio, 300 * ratio, 0.15 * a, a=0.005, d=0.1, shape="saw")
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [skyride, clackety, hupla, photofinish, calliope, airhorn, tossup, kersplash]
|
||||
@@ -0,0 +1,480 @@
|
||||
"""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"),
|
||||
]
|
||||
@@ -0,0 +1,141 @@
|
||||
"""Streak level 4's sounds: 2 s each, one per animation in level4.py (same names as its ANIMS).
|
||||
|
||||
Seeds 2400-2499 (see level0_sounds.py).
|
||||
"""
|
||||
import math
|
||||
import random
|
||||
|
||||
from sound_kit import SR, add_noise, add_tone, bell, ease_off, sbuf
|
||||
|
||||
|
||||
def brass(b, st, dur, f, amp=0.12, d=0.6, vib=(5, 0.006)):
|
||||
for ratio, a in ((1, 1.0), (2, 0.45), (3, 0.2)):
|
||||
add_tone(b, st, dur, f * ratio, amp=amp * a, a=0.02, d=d, shape="saw", vib=vib)
|
||||
|
||||
|
||||
def piano(b, st, f, amp=0.25, d=0.35, dur=0.9):
|
||||
for ratio, a in ((1, 1.0), (2, 0.35), (3, 0.12), (4, 0.06)):
|
||||
add_tone(b, st, dur, f * ratio, amp=amp * a, a=0.003, d=d / ratio ** 0.4)
|
||||
|
||||
|
||||
def ovation():
|
||||
"""The curtains swish open, a brassy fanfare, and a roar of applause."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.05, 0.7, 0.35, a=0.3, d=0.3, lp0=0.25, lp1=0.6, seed=2400)
|
||||
for st, chord, dur in ((0.66, (392, 494, 587), 0.14), (0.82, (523, 659, 784, 1046), 0.9)):
|
||||
for f in chord:
|
||||
brass(b, st, dur, f, 0.09, 0.5)
|
||||
rng = random.Random(2401)
|
||||
for k in range(150): # the applause: many hands
|
||||
st = 0.85 + rng.uniform(0, 1.12)
|
||||
swell = min(1.0, (st - 0.85) / 0.3)
|
||||
add_noise(b, st, 0.03, 0.12 * swell, a=0.0005, d=0.008, lp0=rng.uniform(0.5, 0.9), seed=2402 + k)
|
||||
return ease_off(b, 0.4)
|
||||
|
||||
|
||||
def showtime():
|
||||
"""Bulbs ticking round, a big-band hit as the number lands, and a swinging riff."""
|
||||
b = sbuf()
|
||||
for k in range(22): # the chase
|
||||
add_tone(b, 0.02 + k * 0.083, 0.02, 3000 if k % 3 else 2200, amp=0.06, a=0.001, d=0.006)
|
||||
for f in (233, 294, 349, 415, 523): # the hit, a fat seventh
|
||||
brass(b, 0.42, 0.35, f, 0.08, 0.2)
|
||||
add_noise(b, 0.42, 0.5, 0.25, a=0.002, d=0.2, lp0=0.95, seed=2410)
|
||||
for st, f in ((0.95, 392), (1.12, 466), (1.2, 523), (1.37, 587), (1.45, 698)):
|
||||
brass(b, st, 0.14, f, 0.1, 0.15)
|
||||
for f in (349, 440, 523, 698):
|
||||
brass(b, 1.58, 0.42, f, 0.07, 0.4, vib=(6, 0.01))
|
||||
add_noise(b, 1.58, 0.42, 0.18, a=0.002, d=0.25, lp0=0.95, seed=2411)
|
||||
return b
|
||||
|
||||
|
||||
def projector():
|
||||
"""A projector's clatter, three countdown beeps, and a swelling chord as the picture lights."""
|
||||
b = sbuf()
|
||||
for k in range(48): # the clatter, 24 a second
|
||||
st = k / 24
|
||||
add_noise(b, st, 0.015, 0.1, a=0.0005, d=0.004, lp0=0.6, seed=2420 + k)
|
||||
add_tone(b, st, 0.012, 900, amp=0.03, a=0.0005, d=0.003)
|
||||
for st in (0.25, 0.58, 0.92):
|
||||
add_tone(b, st, 0.12, 1000, amp=0.25, a=0.003, d=1.0, shape="tri")
|
||||
for f in (262, 330, 392, 523, 659):
|
||||
add_tone(b, 1.08, 0.92, f, amp=0.08, a=0.12, d=1.0, shape="saw", vib=(5, 0.005))
|
||||
bell(b, 1.08, 1046, 0.12, 0.5)
|
||||
return ease_off(b, 0.25)
|
||||
|
||||
|
||||
def arpeggio():
|
||||
"""A rippling run up the keyboard, a big chord as the notes spray, and a sparkle at the top."""
|
||||
b = sbuf()
|
||||
notes = [131, 165, 196, 262, 330, 392, 523, 659, 784, 1046, 1319]
|
||||
for k, f in enumerate(notes):
|
||||
piano(b, 0.22 + k * 0.055, f, 0.2, 0.3, 0.6)
|
||||
for f in (131, 262, 330, 392, 523, 659):
|
||||
piano(b, 0.85, f, 0.17, 0.6, 1.15)
|
||||
rng = random.Random(2430)
|
||||
for k in range(8):
|
||||
piano(b, 1.0 + k * 0.1 + rng.uniform(0, 0.03), rng.choice((1568, 2093, 2637, 3136)), 0.07, 0.15, 0.4)
|
||||
return ease_off(b, 0.2)
|
||||
|
||||
|
||||
def bwong():
|
||||
"""A whoosh as the mallet winds back, then one huge shimmering, beating gong stroke."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.3, 0.37, 0.2, a=0.3, d=0.2, lp0=0.1, lp1=0.4, seed=2440)
|
||||
st = 0.67
|
||||
add_tone(b, st, 0.2, 80, 50, 0.7, a=0.001, d=0.06)
|
||||
add_noise(b, st, 0.12, 0.4, a=0.001, d=0.03, lp0=0.3, seed=2441)
|
||||
for ratio, a, d in ((1, 0.5, 0.9), (1.012, 0.35, 0.9), (1.52, 0.3, 0.7), (2.03, 0.22, 0.6), (2.71, 0.16, 0.5),
|
||||
(3.49, 0.1, 0.35), (4.13, 0.07, 0.3), (5.6, 0.04, 0.2)):
|
||||
f = 98 * ratio
|
||||
add_tone(b, st, 2.0 - st, f * 0.985, f * 1.01, a, a=0.004, d=d)
|
||||
return ease_off(b, 0.3)
|
||||
|
||||
|
||||
def burner():
|
||||
"""Three roaring gusts of the burner, under a rising, airy tune."""
|
||||
b = sbuf()
|
||||
for k, (st, dur) in enumerate(((0.08, 0.26), (0.75, 0.2), (1.33, 0.28))):
|
||||
add_noise(b, st, dur + 0.1, 0.55, a=0.02, d=0.25, lp0=0.15, seed=2450 + k)
|
||||
add_noise(b, st, dur + 0.1, 0.15, a=0.01, d=0.15, lp0=0.6, seed=2455 + k)
|
||||
add_tone(b, st, dur + 0.1, 55, 60, 0.25, a=0.02, d=0.2, shape="tri")
|
||||
for st, f, dur in ((0.35, 392, 0.4), (0.7, 523, 0.4), (1.05, 659, 0.4), (1.4, 784, 0.6)):
|
||||
add_tone(b, st, dur, f, amp=0.12, a=0.06, d=0.5, shape="tri", vib=(5, 0.008))
|
||||
add_tone(b, st, dur, f * 2, amp=0.03, a=0.06, d=0.3)
|
||||
return ease_off(b, 0.3)
|
||||
|
||||
|
||||
def quindar():
|
||||
"""The beep of a far-off radio, a hissing descent, a soft thump down, the answering beep and a bright chord."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.0, 0.25, 2525, amp=0.18, a=0.003, d=1.0)
|
||||
add_noise(b, 0.15, 0.8, 0.3, a=0.15, d=0.6, lp0=0.7, lp1=0.4, seed=2460)
|
||||
add_tone(b, 0.15, 0.8, 70, 85, 0.15, a=0.1, d=0.6, shape="tri")
|
||||
add_tone(b, 0.92, 0.2, 90, 45, 0.6, a=0.001, d=0.06)
|
||||
add_noise(b, 0.92, 0.35, 0.3, a=0.002, d=0.12, lp0=0.3, lp1=0.1, seed=2461)
|
||||
add_tone(b, 1.0, 0.25, 2475, amp=0.18, a=0.003, d=1.0)
|
||||
for f in (392, 523, 659, 784):
|
||||
add_tone(b, 1.12, 0.88, f, amp=0.09, a=0.03, d=0.6, shape="tri", vib=(5, 0.006))
|
||||
bell(b, 1.12, 1568, 0.07, 0.4)
|
||||
return ease_off(b, 0.25)
|
||||
|
||||
|
||||
def starfall():
|
||||
"""Falling pings, more and more of them, a rushing fireball, and a crackling burst of shimmer."""
|
||||
b = sbuf()
|
||||
rng = random.Random(2470)
|
||||
for k in range(22):
|
||||
st = 0.04 + 0.95 * (k / 22) ** 0.8 + rng.uniform(0, 0.03)
|
||||
f = rng.uniform(1800, 3400)
|
||||
add_tone(b, st, 0.22, f, f * 0.55, amp=0.12, a=0.003, d=0.08)
|
||||
add_noise(b, 0.5, 0.5, 0.35, a=0.45, d=0.2, lp0=0.1, lp1=0.8, seed=2471)
|
||||
add_tone(b, 1.0, 0.2, 120, 50, 0.55, a=0.001, d=0.08)
|
||||
add_noise(b, 1.0, 0.35, 0.4, a=0.001, d=0.08, lp0=0.9, seed=2472)
|
||||
for k in range(18):
|
||||
add_noise(b, 1.05 + rng.uniform(0, 0.6), 0.01, 0.15, a=0.0005, d=0.003, lp0=0.9, seed=2473 + k)
|
||||
for f in (1047, 1319, 1568, 2093):
|
||||
bell(b, 1.0, f, 0.1, 0.45)
|
||||
return ease_off(b, 0.3)
|
||||
|
||||
|
||||
SOUNDS = [ovation, showtime, projector, arpeggio, bwong, burner, quindar, starfall]
|
||||
@@ -0,0 +1,434 @@
|
||||
"""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"),
|
||||
]
|
||||
@@ -0,0 +1,160 @@
|
||||
"""Streak level 5's sounds: 2 s each, one per animation in level5.py (same names as its ANIMS).
|
||||
|
||||
Seeds 2500-2599 (see level0_sounds.py).
|
||||
"""
|
||||
import math
|
||||
import random
|
||||
|
||||
from sound_kit import SR, TAU, add_noise, add_tone, bell, ease_off, sbuf
|
||||
|
||||
|
||||
def brass(b, st, dur, f, amp=0.1, d=0.6, vib=(5, 0.006), a=0.02):
|
||||
for ratio, g in ((1, 1.0), (2, 0.45), (3, 0.2)):
|
||||
add_tone(b, st, dur, f * ratio, amp=amp * g, a=a, d=d, shape="saw", vib=vib)
|
||||
|
||||
|
||||
def organ(b, st, dur, f, amp=0.08, d=1.5):
|
||||
for ratio, g in ((0.5, 0.6), (1, 1.0), (2, 0.5), (3, 0.25), (4, 0.2)):
|
||||
add_tone(b, st, dur, f * ratio, amp=amp * g, a=0.03, d=d)
|
||||
|
||||
|
||||
def nova():
|
||||
"""A deep throbbing swell, a sudden sucking hush, then an enormous boom that rings off into shimmer."""
|
||||
b = sbuf()
|
||||
for k in range(int(0.75 * SR)): # the swell, throbbing
|
||||
tt = k / SR
|
||||
b[k] += math.sin(TAU * (45 + 40 * tt) * tt) * 0.35 * (tt / 0.75) * (0.6 + 0.4 * math.sin(TAU * 7 * tt))
|
||||
add_noise(b, 0.0, 0.75, 0.2, a=0.7, d=0.3, lp0=0.05, lp1=0.3, seed=2500)
|
||||
add_noise(b, 0.75, 0.17, 0.3, a=0.15, d=0.05, lp0=0.9, lp1=0.2, seed=2501)
|
||||
add_tone(b, 0.75, 0.17, 400, 1600, 0.12, a=0.15, d=0.1)
|
||||
add_tone(b, 0.92, 0.7, 70, 28, 0.9, a=0.001, d=0.3)
|
||||
add_noise(b, 0.92, 1.08, 0.8, a=0.001, d=0.3, lp0=0.6, lp1=0.04, seed=2502)
|
||||
for f in (523, 659, 784, 1046):
|
||||
add_tone(b, 1.0, 1.0, f, f * 1.005, 0.06, a=0.25, d=0.6, vib=(4, 0.01))
|
||||
bell(b, 1.0, 2093, 0.08, 0.5)
|
||||
return ease_off(b, 0.35)
|
||||
|
||||
|
||||
def totality():
|
||||
"""A dimming, falling hush, a single glinting ping, then a vast bright chord like a choir."""
|
||||
b = sbuf()
|
||||
for f in (220, 262, 330):
|
||||
add_tone(b, 0.0, 0.92, f, f * 0.84, 0.08, a=0.2, d=1.0, shape="tri")
|
||||
add_noise(b, 0.0, 0.9, 0.08, a=0.3, d=0.5, lp0=0.05, seed=2510)
|
||||
bell(b, 0.92, 2637, 0.25, 0.45)
|
||||
bell(b, 0.92, 3951, 0.1, 0.3)
|
||||
rng = random.Random(2511)
|
||||
for f in (131, 196, 262, 330, 392, 523, 659): # the choir: detuned voices
|
||||
for v in range(2):
|
||||
ff = f * (1 + rng.uniform(-0.004, 0.004))
|
||||
add_tone(b, 1.0, 1.0, ff, amp=0.035, a=0.15, d=1.5, shape="saw", vib=(5 + v, 0.007))
|
||||
add_tone(b, 1.0, 1.0, ff, amp=0.04, a=0.12, d=1.5, shape="sine", vib=(5 - v, 0.006))
|
||||
return ease_off(b, 0.35)
|
||||
|
||||
|
||||
def cosmos():
|
||||
"""A deep, slowly swirling drone, wheeling glassy notes, and a bright bloom as the core lights up."""
|
||||
b = sbuf()
|
||||
for k in range(len(b)): # the drone, swirling
|
||||
tt = k / SR
|
||||
sw = 0.5 + 0.5 * math.sin(TAU * 1.5 * tt)
|
||||
b[k] += (math.sin(TAU * 55 * tt) * 0.2 + math.sin(TAU * 110.4 * tt) * 0.1 * sw
|
||||
+ math.sin(TAU * 165.2 * tt) * 0.05 * (1 - sw)) * min(1.0, tt / 0.3)
|
||||
notes = [523, 659, 784, 988, 1175, 988, 784, 659]
|
||||
for k in range(18):
|
||||
st = 0.05 + k * 0.105
|
||||
bell(b, st, notes[k % len(notes)] * (2 if k >= 9 else 1), 0.07, 0.25)
|
||||
for f in (262, 392, 523, 659, 784):
|
||||
add_tone(b, 0.5, 1.5, f, amp=0.05, a=0.3, d=1.0, vib=(3, 0.006))
|
||||
add_noise(b, 0.5, 0.6, 0.12, a=0.25, d=0.3, lp0=0.6, seed=2520)
|
||||
return ease_off(b, 0.4)
|
||||
|
||||
|
||||
def warpjump():
|
||||
"""An engine winding up higher and higher, a punching jump with a thunderclap, and a rush of light."""
|
||||
b = sbuf()
|
||||
for ratio, a in ((1, 0.25), (2.01, 0.1), (3, 0.06)):
|
||||
add_tone(b, 0.0, 0.85, 70 * ratio, 700 * ratio, a, a=0.5, d=0.5, shape="saw")
|
||||
add_noise(b, 0.25, 0.6, 0.3, a=0.55, d=0.2, lp0=0.05, lp1=0.7, seed=2530)
|
||||
add_tone(b, 0.85, 0.4, 1200, 60, 0.6, a=0.001, d=0.12)
|
||||
add_noise(b, 0.85, 0.5, 0.7, a=0.001, d=0.12, lp0=0.8, lp1=0.1, seed=2531)
|
||||
add_tone(b, 0.85, 0.5, 55, 35, 0.5, a=0.001, d=0.2)
|
||||
add_noise(b, 0.95, 1.0, 0.18, a=0.3, d=0.4, lp0=0.2, lp1=0.9, seed=2532)
|
||||
for f in (392, 587, 784, 1175):
|
||||
add_tone(b, 1.05, 0.95, f * 0.9, f, 0.06, a=0.08, d=0.6, shape="tri", vib=(6, 0.006))
|
||||
return ease_off(b, 0.3)
|
||||
|
||||
|
||||
def toccata():
|
||||
"""A rippling organ flourish, then three thundering chords, the last held huge."""
|
||||
b = sbuf()
|
||||
for k, (st, f) in enumerate(((0.0, 880), (0.07, 784), (0.14, 880), (0.26, 784), (0.31, 698),
|
||||
(0.36, 659), (0.41, 587), (0.46, 554), (0.53, 587))):
|
||||
organ(b, st, 0.1 if k < 8 else 0.25, f, 0.06, 0.4)
|
||||
for st, chord, dur in ((0.5, (73, 147, 220, 294, 349), 0.42), (1.0, (69, 139, 220, 277, 330), 0.42),
|
||||
(1.5, (73, 147, 220, 294, 370, 440), 0.5)):
|
||||
for f in chord:
|
||||
organ(b, st, dur, f, 0.05, 2.0)
|
||||
add_noise(b, st, 0.1, 0.08, a=0.01, d=0.05, lp0=0.3, seed=int(2540 + st * 10))
|
||||
return ease_off(b, 0.15)
|
||||
|
||||
|
||||
def powerchord():
|
||||
"""A count-in on the hi-hat, then a thumping kick, a huge crunching power chord and the whoosh of the pyro."""
|
||||
b = sbuf()
|
||||
for k in range(3): # count-in
|
||||
add_noise(b, 0.05 + k * 0.2, 0.05, 0.2, a=0.001, d=0.015, lp0=0.95, seed=2550 + k)
|
||||
add_tone(b, 0.05 + k * 0.2, 0.03, 1500, amp=0.06, a=0.001, d=0.01)
|
||||
g = sbuf() # the guitar, driven hard
|
||||
for f in (82.4, 123.5, 164.8):
|
||||
for det in (1.0, 1.006):
|
||||
add_tone(g, 0.67, 1.33, f * det, amp=0.5, a=0.005, d=1.2, shape="saw", vib=(5, 0.004))
|
||||
for k in range(len(b)):
|
||||
b[k] += 0.3 * math.tanh(3.0 * g[k])
|
||||
for k in range(int((2.0 - 0.67) / 0.25) + 1): # kick on the beat
|
||||
st = 0.67 + k * 0.25
|
||||
add_tone(b, st, 0.15, 120, 45, 0.6, a=0.001, d=0.05)
|
||||
add_noise(b, 0.67, 1.0, 0.35, a=0.002, d=0.35, lp0=0.95, lp1=0.6, seed=2560)
|
||||
for st in (0.67, 1.25): # pyro whoosh
|
||||
add_noise(b, st, 0.5, 0.35, a=0.03, d=0.2, lp0=0.12, lp1=0.4, seed=int(2561 + st * 10))
|
||||
return ease_off(b, 0.25)
|
||||
|
||||
|
||||
def aria():
|
||||
"""A soprano climbs to a soaring top note and holds it, until a row of glasses shatters."""
|
||||
b = sbuf()
|
||||
for k, (st, f, dur) in enumerate(((0.33, 523, 0.17), (0.5, 659, 0.17), (0.67, 784, 0.2), (0.87, 1046, 1.13))):
|
||||
vib = (5.5, 0.01 + 0.012 * (k == 3))
|
||||
for ratio, a in ((1, 0.3), (2, 0.1), (3, 0.06), (4, 0.025)):
|
||||
add_tone(b, st, dur, f * ratio, amp=a, a=0.04, d=2.0 if k == 3 else 0.5, vib=vib)
|
||||
add_tone(b, 0.0, 0.33, 196, 196, 0.08, a=0.05, d=0.2, shape="tri") # the pianist's chord before
|
||||
add_tone(b, 0.0, 0.33, 262, 262, 0.06, a=0.05, d=0.2, shape="tri")
|
||||
st = 1.08
|
||||
add_noise(b, st, 0.4, 0.5, a=0.001, d=0.08, lp0=0.95, seed=2570)
|
||||
rng = random.Random(2571)
|
||||
for k in range(24):
|
||||
add_tone(b, st + rng.uniform(0, 0.55), 0.15, rng.uniform(3000, 6000), amp=0.07, a=0.001, d=0.04)
|
||||
return ease_off(b, 0.3)
|
||||
|
||||
|
||||
def klieg():
|
||||
"""The hum of the searchlights, cameras popping and whining, then a sweeping red-carpet fanfare."""
|
||||
b = sbuf()
|
||||
for k in range(len(b)): # the arc lamps' buzz
|
||||
tt = k / SR
|
||||
b[k] += 0.05 * math.sin(TAU * 60 * tt) + 0.03 * math.sin(TAU * 120 * tt + 0.3)
|
||||
rng = random.Random(2580)
|
||||
for k in range(9): # flashbulbs: pop, then the recharge whine
|
||||
st = 0.05 + k * 0.2 + rng.uniform(0, 0.08)
|
||||
add_noise(b, st, 0.03, 0.3, a=0.0005, d=0.006, lp0=0.9, seed=2581 + k)
|
||||
add_tone(b, st + 0.02, 0.15, 2500, 5500, 0.03, a=0.02, d=0.1)
|
||||
for st, chord, dur in ((0.92, (294, 370, 440), 0.12), (1.06, (294, 370, 440), 0.12),
|
||||
(1.2, (392, 494, 587, 784), 0.8)):
|
||||
for f in chord:
|
||||
brass(b, st, dur, f, 0.07, 0.6)
|
||||
add_noise(b, 1.2, 0.8, 0.12, a=0.002, d=0.3, lp0=0.95, seed=2595)
|
||||
bell(b, 1.2, 1568, 0.08, 0.4)
|
||||
return ease_off(b, 0.3)
|
||||
|
||||
|
||||
SOUNDS = [nova, totality, cosmos, warpjump, toccata, powerchord, aria, klieg]
|
||||
@@ -0,0 +1,588 @@
|
||||
"""Streak level 6: a 254-day streak. Eight big 2-second celebrations, each showing the streak number.
|
||||
|
||||
Same rules as level0.py: fn(i, t) -> shapes, i = frame 0..23, t = 0..1; NUM(...) is where the
|
||||
number goes (laid out for 3 digits). These are the second-rarest rewards in the app, so they're
|
||||
built big: mythic beasts, monuments and great machines. Sounds: level6_sounds.py, same names.
|
||||
"""
|
||||
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 tf(pts, ox, oy, sc=1.0, rot=0.0):
|
||||
"""Local points scaled by sc, turned rot, moved to (ox, oy)."""
|
||||
c, s = math.cos(rot), math.sin(rot)
|
||||
return [(ox + sc * (x * c - y * s), oy + sc * (x * s + y * c)) for x, y in pts]
|
||||
|
||||
|
||||
def tube(spine, w0, w1):
|
||||
"""A tapering band round a polyline: width w0 at its start, w1 at its end."""
|
||||
left, right = [], []
|
||||
n = len(spine)
|
||||
for k, (x, y) in enumerate(spine):
|
||||
px, py = spine[max(0, k - 1)]
|
||||
nx, ny = spine[min(n - 1, k + 1)]
|
||||
dx, dy = nx - px, ny - py
|
||||
d = math.hypot(dx, dy) or 1.0
|
||||
w = (w0 + (w1 - w0) * k / (n - 1)) / 2
|
||||
left.append((x - dy / d * w, y + dx / d * w))
|
||||
right.append((x + dy / d * w, y - dx / d * w))
|
||||
return left + right[::-1]
|
||||
|
||||
|
||||
# ── 1. dragon ──
|
||||
|
||||
def dragon(i, t):
|
||||
"""A dragon rears up behind the box, beats a wing, draws a breath and roars a great cone of fire; the number glows in the flames and is left smouldering."""
|
||||
s = []
|
||||
u = ease_out(min(1.0, i / 6))
|
||||
back = (-0.35, -0.3) if i in (6, 7) else (0.0, 0.0) # the breath in
|
||||
thrust = 0.3 if 8 <= i <= 16 else 0.0
|
||||
shake = 0.08 * math.sin(i * 2.7) if 8 <= i <= 16 else 0.0
|
||||
hx, hy = -2.3 + back[0] + thrust, -0.4 - 4.0 * u + back[1] + shake
|
||||
flap = [0.0, -0.6, -1.2, -0.4, 0.6, 1.0, 0.2][i % 7] if i < 14 else 0.3 * math.sin(i * 0.8)
|
||||
s.append(L([(-3.6, 0.9), (-4.6, 1.0), (-5.0, 0.5), (-4.7, 0.15 + 0.1 * math.sin(i))], 0.22)) # the tail
|
||||
s.append(P(ring(-3.0, 0.65, 1.0, 12, 0, 0.05))) # the haunch
|
||||
wing = [(-2.9, -0.9), (-3.6, -2.9 + flap), (-5.3, -3.9 + flap * 1.4), (-4.9, -2.9 + flap), (-5.2, -2.0 + flap * 0.6),
|
||||
(-4.5, -1.8 + flap * 0.5), (-4.4, -0.9 + flap * 0.3), (-3.7, -0.7), (-3.2, 0.0)]
|
||||
s.append(P(wing)) # the wing
|
||||
s.append(K("yellow"))
|
||||
for k in (2, 4, 6): # its finger bones
|
||||
s.append(L([(-3.6, -2.9 + flap), wing[k]], 0.05))
|
||||
s.append(K("red"))
|
||||
spine = [(-2.7, 1.0), (-3.4, -0.4), (-3.3, -1.7 * u - 0.2), (hx - 0.6, hy + 1.6), (hx, hy)]
|
||||
s.append(P(tube(spine, 1.5, 0.75))) # the neck
|
||||
for k in range(1, 4): # spines down its back
|
||||
x, y = spine[k]
|
||||
s.append(P([(x - 0.4, y), (x - 0.95, y - 0.25), (x - 0.35, y - 0.5)]))
|
||||
jaw = 0.55 if 8 <= i <= 16 else 0.3 if i in (6, 7) else 0.08
|
||||
s.append(P(tf([(-0.3, -0.5), (0.6, -0.62), (1.6, -0.42), (2.1, -0.12), (1.9, 0.05), (0.6, 0.12), (-0.3, 0.35)], hx, hy)))
|
||||
s.append(P(tf(rotate([(0.2, 0.1), (1.7, 0.1), (1.6, 0.32), (0.2, 0.55)], jaw, 0.2, 0.1), hx, hy))) # the jaw
|
||||
s.append(P(tf([(-0.1, -0.5), (-1.0, -1.4), (0.3, -0.62)], hx, hy))) # horns
|
||||
s.append(P(tf([(0.4, -0.58), (-0.2, -1.6), (0.8, -0.62)], hx, hy)))
|
||||
s.append(K("yellow"))
|
||||
s.append(C(hx + 0.7, hy - 0.3, 0.13)) # the eye
|
||||
mx, my = hx + 2.1, hy + 0.35 # the mouth
|
||||
if 8 <= i <= 19: # the fire cone
|
||||
grow = min(1.0, (i - 7) / 3)
|
||||
tail = max(0.0, (i - 16) / 4)
|
||||
d0, d1 = 6.4 * tail, 6.4 * grow
|
||||
ang = 0.06
|
||||
|
||||
def edge(d, side):
|
||||
hw = (0.35 + 0.33 * d) * (1 + 0.08 * math.sin(d * 3 + i * 2.1 + side))
|
||||
return (mx + d * math.cos(ang) - side * hw * math.sin(ang), my + d * math.sin(ang) + side * hw * math.cos(ang))
|
||||
ds = [d0 + (d1 - d0) * m / 9 for m in range(10)]
|
||||
top = [edge(d, -1) for d in ds]
|
||||
bot = [edge(d, 1) for d in ds]
|
||||
tip = [(mx + d1 + 0.6, my + 0.4 * math.sin(i * 1.7) + d1 * math.sin(ang))]
|
||||
s.append(P(top + tip + bot[::-1], 0, 0.12))
|
||||
for m in range(0, 9, 2): # licks off the edges
|
||||
x, y = top[m]
|
||||
s.append(P([(x - 0.3, y + 0.1), (x + 0.15, y - 0.55 - 0.2 * ((m + i) % 2)), (x + 0.4, y + 0.1)]))
|
||||
x, y = bot[m]
|
||||
s.append(P([(x - 0.3, y - 0.1), (x + 0.15, y + 0.45 + 0.2 * ((m + i) % 2)), (x + 0.4, y - 0.1)]))
|
||||
if i <= 16:
|
||||
s.append(K("red"))
|
||||
s.append(P([(mx, my - 0.25), (mx + 1.4 * grow, my + 0.05 + 0.15 * math.sin(i)), (mx, my + 0.3)]))
|
||||
s.append(K("red"))
|
||||
nx, ny = mx + 3.35, my + 0.25
|
||||
if i >= 10:
|
||||
g = pop_scale(t, 10 / 23, 0.12, 1.25)
|
||||
s.append(NUM(nx, ny, 2.05 * g, rot=0.06 + 0.04 * math.sin(i * 1.3)))
|
||||
if i >= 18: # smouldering: sparks
|
||||
s.append(K("yellow"))
|
||||
for k in range(6):
|
||||
a = k * 1.05 + i * 0.4
|
||||
s.append(C(nx + 2.9 * math.cos(a), ny + 1.5 * math.sin(a), 0.08 + 0.05 * ((k + i) % 2)))
|
||||
if i >= 15: # smoke from the nostrils
|
||||
s.append(K("red"))
|
||||
for k in range(2):
|
||||
age = i - 15 - k * 3
|
||||
if 0 <= age < 8:
|
||||
s.append(C(hx + 1.6 - age * 0.12, hy - 0.8 - age * 0.3, 0.12 + age * 0.05, 0.06))
|
||||
return s
|
||||
|
||||
|
||||
# ── 2. excavator ──
|
||||
|
||||
def excavator(i, t):
|
||||
"""A big excavator by the box swings its arm down, bites deep into the ground and heaves up a scoop of earth; the number rises out of the hole it dug while the digger shakes its loaded bucket in triumph."""
|
||||
s = []
|
||||
g = -0.55 # the ground line
|
||||
up, dig = (-2.4, -2.9, 0.4), (-2.95, 1.6, -0.4) # (boom, stick, bucket curl)
|
||||
poses = [up, (-2.55, -1.6, 0.2), (-2.75, -0.1, 0.0), (-2.9, 1.1, -0.3), dig,
|
||||
(-2.95, 1.62, 0.3), (-2.9, 1.5, 1.1), (-2.85, 1.2, 1.8), (-2.75, 0.2, 1.9), (-2.6, -1.2, 1.9),
|
||||
(-2.48, -2.3, 1.9), (-2.42, -2.8, 1.9), (-2.4, -2.9, 1.9)]
|
||||
if i < len(poses):
|
||||
a1, a2, cu = poses[i]
|
||||
elif i < 16:
|
||||
a1, a2, cu = -2.4, -2.9, 1.9 + 0.12 * math.sin(i * 2.0)
|
||||
else: # shakes it, triumphant
|
||||
a1, a2, cu = -2.4 - 0.06 * math.sin(i * 1.7), -2.9 + 0.12 * math.sin(i * 1.3), 1.9 + 0.3 * math.sin(i * 2.2)
|
||||
bob = -0.12 if i in (5, 6, 16, 17) else 0.0
|
||||
s.append(K("blue"))
|
||||
s.append(P([(3.0, g), (7.4, g), (7.7, g - 0.45), (7.4, g - 0.9), (3.0, g - 0.9), (2.7, g - 0.45)])) # the tracks
|
||||
s.append(K("yellow"))
|
||||
for k in range(5):
|
||||
s.append(C(3.3 + k * 1.0, g - 0.45, 0.24))
|
||||
by = g - 0.9 + bob
|
||||
s.append(P([(3.4, by), (7.2, by), (7.2, by - 1.5), (5.0, by - 1.5), (5.0, by - 2.9), (3.5, by - 2.9), (3.3, by - 1.5)])) # house + cab
|
||||
s.append(L([(6.6, by - 1.5), (6.6, by - 2.3)], 0.16)) # the exhaust
|
||||
s.append(K("blue"))
|
||||
s.append(P([(3.75, by - 1.75), (4.75, by - 1.75), (4.75, by - 2.65), (3.85, by - 2.65)])) # the window
|
||||
if i in (2, 3, 6, 7, 8, 9): # it works hard: smoke
|
||||
s.append(C(6.7 + (i % 3) * 0.2, by - 2.7 - (i % 3) * 0.35, 0.18 + (i % 3) * 0.08, 0.07))
|
||||
bx, byy = 4.0, by - 1.6 # the boom's pivot
|
||||
ex, ey = bx + 3.6 * math.cos(a1), byy + 3.6 * math.sin(a1)
|
||||
tx, ty = ex + 3.2 * math.cos(a2), ey + 3.2 * math.sin(a2)
|
||||
s.append(K("yellow"))
|
||||
s.append(P([(bx, byy - 0.35), (ex, ey - 0.25), (ex, ey + 0.25), (bx, byy + 0.35)])) # the boom
|
||||
s.append(L([(ex, ey), (tx, ty)], 0.38)) # the stick
|
||||
s.append(K("blue"))
|
||||
mx, my = bx + 1.8 * math.cos(a1), byy + 1.8 * math.sin(a1)
|
||||
s.append(L([(bx + 0.5, byy + 0.4), (mx, my + 0.3)], 0.14)) # its ram
|
||||
s.append(C(ex, ey, 0.2))
|
||||
full = i >= 6
|
||||
bucket = rotate([(tx, ty), (tx + 0.9, ty + 0.1), (tx + 1.0, ty + 0.9), (tx + 0.3, ty + 1.05), (tx - 0.25, ty + 0.6)], a2 - 1.3 + cu, tx, ty)
|
||||
s.append(K("yellow"))
|
||||
s.append(P(bucket))
|
||||
s.append(K("blue"))
|
||||
s.append(L([bucket[2], bucket[3]], 0.1)) # the teeth's edge
|
||||
s.append(K("red"))
|
||||
if full: # the heaped earth in the bucket
|
||||
cx, cy = sum(p[0] for p in bucket) / 5, sum(p[1] for p in bucket) / 5
|
||||
s.append(P(ring(cx, cy - 0.25, 0.6, 9, i, 0.12)))
|
||||
for k in range(4): # clods falling off as it lifts
|
||||
age = i - 8 - k
|
||||
if 0 <= age < 6:
|
||||
s.append(C(tx + 0.4 + k * 0.3 - age * 0.1, min(g - 0.1, ty + 0.9 + age * age * 0.18), 0.13 + 0.04 * (k % 2)))
|
||||
if 4 <= i <= 7: # dirt flicked up by the bite
|
||||
for k in range(5):
|
||||
a = -math.pi / 2 + (k - 2) * 0.45
|
||||
r = 0.7 + (i - 4) * 0.4
|
||||
s.append(C(0.3 + r * math.cos(a), g + 0.2 + r * math.sin(a), 0.12))
|
||||
if i >= 5: # the dug-up mounds either side
|
||||
for x in (-1.6, 1.7):
|
||||
s.append(P([(x - 0.7, g + 0.1), (x - 0.2, g - 0.45), (x + 0.3, g - 0.35), (x + 0.7, g + 0.1)]))
|
||||
if i >= 10: # the number rises out of the hole
|
||||
rise = ease_out(min(1.0, (i - 10) / 4))
|
||||
gg = pop_scale(t, 10 / 23, 0.15, 1.25)
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(-0.4, g - 0.2 - 1.5 * rise, 1.95 * gg, rot=0.05 * math.sin(i * 1.1)))
|
||||
if i in (11, 12, 13):
|
||||
s.append(K("red"))
|
||||
s += rays(-0.4, g - 1.7, 2.5, 3.0, 9, -0.2, 0.08)
|
||||
return s
|
||||
|
||||
|
||||
# ── 3. geyser ──
|
||||
|
||||
def geyser(i, t):
|
||||
"""The ground by the box rumbles and spits, then a geyser blasts up in a towering column and holds the number high on its crown of spray."""
|
||||
s = []
|
||||
vx, vy = 1.3, -0.55 # the vent
|
||||
sh = 0.1 * math.sin(i * 3.1) if i < 7 else 0.0
|
||||
s.append(K("yellow"))
|
||||
s.append(P([(vx - 2.3 + sh, vy + 0.2), (vx - 1.5 + sh, vy - 0.35), (vx - 0.55, vy - 0.45), (vx + 0.55, vy - 0.45),
|
||||
(vx + 1.5 + sh, vy - 0.35), (vx + 2.3 + sh, vy + 0.2)])) # the sinter mound
|
||||
s.append(K("blue"))
|
||||
if i < 7: # spits and bubbles
|
||||
hgt = [0.3, 0.8, 0.2, 1.4, 0.4, 1.9, 0.6][i]
|
||||
s.append(P([(vx - 0.3, vy - 0.4), (vx - 0.1, vy - 0.4 - hgt), (vx + 0.15, vy - 0.4 - hgt * 0.8), (vx + 0.3, vy - 0.4)]))
|
||||
for k in range(2):
|
||||
s.append(C(vx - 0.6 + k * 1.2, vy - 0.6 - (i % 3) * 0.2, 0.12, 0.05))
|
||||
if i in (3, 5, 6):
|
||||
s.append(K("red"))
|
||||
s += rays(vx, vy - 0.5, 0.6, 1.0, 5, -math.pi * 0.9, 0.06)
|
||||
return s
|
||||
H = [3.5, 6.4, 7.4, 7.0][i - 7] if i < 11 else 6.8 + 0.35 * math.sin(i * 1.4)
|
||||
if i >= 21:
|
||||
H -= (i - 20) * 0.6
|
||||
top = vy - 0.45 - H
|
||||
n = 10
|
||||
left = [(vx - 0.45 - 0.35 * m / n + 0.12 * math.sin(m * 1.7 + i * 1.9), vy - 0.45 - H * m / n) for m in range(n + 1)]
|
||||
right = [(vx + 0.45 + 0.35 * m / n + 0.12 * math.sin(m * 1.3 + i * 2.3 + 1), vy - 0.45 - H * m / n) for m in range(n + 1)]
|
||||
s.append(P(left + right[::-1], 0, 0.06)) # the column
|
||||
for k in range(7): # the crown of spray, curling over
|
||||
a = math.pi + k * math.pi / 6
|
||||
r = 1.5 + 0.2 * ((k + i) % 2)
|
||||
s.append(P(ring(vx + r * 0.9 * math.cos(a), top + 0.3 + r * 0.55 * math.sin(a), 0.42, 9, k + i, 0.06)))
|
||||
s.append(P(ring(vx, top + 0.1, 1.0, 12, i, 0.08)))
|
||||
for side in (-1, 1): # spray raining down both sides
|
||||
for m in range(6):
|
||||
u = ((i * 0.33 + m / 6) % 1.0)
|
||||
x = vx + side * (1.2 + 2.3 * u)
|
||||
y = top + 0.8 - 1.2 * u + 7.4 * u * u
|
||||
if y < vy:
|
||||
s.append(C(x, y, 0.1 + 0.06 * (m % 2)))
|
||||
if i >= 8: # steam drifting off
|
||||
s.append(K("yellow"))
|
||||
for k in range(3):
|
||||
age = (i - 8 + k * 4) % 12
|
||||
s.append(C(vx + 1.6 + age * 0.15, vy - 1.5 - age * 0.4 - k, 0.22 + age * 0.05, 0.07))
|
||||
s.append(K("red"))
|
||||
g = pop_scale(t, 8 / 23, 0.12, 1.3)
|
||||
s.append(NUM(vx, top - 1.9, 2.25 * g, rot=0.08 * math.sin(i * 0.9)))
|
||||
return s
|
||||
|
||||
|
||||
# ── 4. pyramid ──
|
||||
|
||||
def pyramid(i, t):
|
||||
"""A pyramid builds itself above the box, one course of stone blocks thudding down at a time; a capstone lands on top and the number is carved into its face in a blaze of light."""
|
||||
s = []
|
||||
bx, by, hw, H = 1.0, -0.55, 4.3, 6.6 # base centre, half-width, height
|
||||
nc = 5
|
||||
ch = 1.05
|
||||
|
||||
def half(y):
|
||||
return hw * (1 - (by - y) / H)
|
||||
if i >= 13: # the blaze behind it
|
||||
s.append(K("yellow"))
|
||||
s += rays(bx, by - H + 0.3, 1.4, 2.4 + 0.3 * (i % 2), 14, i * 0.05, 0.12)
|
||||
s.append(K("yellow"))
|
||||
for k in range(nc):
|
||||
land = 1 + 2 * k
|
||||
if i < land:
|
||||
break
|
||||
drop = 0.9 if i == land else 0.0
|
||||
y0, y1 = by - k * ch - drop, by - (k + 1) * ch - drop
|
||||
w0, w1 = half(by - k * ch), half(by - (k + 1) * ch)
|
||||
nb = nc + 1 - k
|
||||
for m in range(nb):
|
||||
f0, f1 = m / nb, (m + 1) / nb
|
||||
g = 0.05
|
||||
pts = [(bx - w0 + 2 * w0 * f0 + g, y0 - g), (bx - w0 + 2 * w0 * f1 - g, y0 - g),
|
||||
(bx - w1 + 2 * w1 * f1 - g, y1 + g), (bx - w1 + 2 * w1 * f0 + g, y1 + g)]
|
||||
s.append(P(pts, 0, 0.03))
|
||||
if i == land + 1: # dust as it lands
|
||||
s.append(K("red"))
|
||||
for side in (-1, 1):
|
||||
x = bx + side * (w0 + 0.3)
|
||||
s.append(C(x, y0 - 0.25, 0.25, 0.06))
|
||||
s.append(C(x + side * 0.45, y0 - 0.5, 0.18, 0.06))
|
||||
s.append(K("yellow"))
|
||||
yt = by - nc * ch
|
||||
capy = {11: -2.6, 12: -0.9}.get(i, 0.0)
|
||||
if i >= 11:
|
||||
s.append(K("red"))
|
||||
w = half(yt)
|
||||
s.append(P([(bx - w, yt - capy), (bx + w, yt - capy), (bx, by - H - capy)], 0, 0.03))
|
||||
if i in (12, 13):
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(bx, by - H, 1.3, 0.45, 8, i * 0.3)))
|
||||
elif i >= 14 and i % 3 != 1: # its glint
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(bx + 0.1, by - H + 0.35, 0.6, 0.15, 4, 0.3 * (i % 2))))
|
||||
if i >= 13:
|
||||
g = pop_scale(t, 13 / 23, 0.1, 1.2)
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(bx, by - 2.15, 1.65 * g, w=0.32, rot=0.0))
|
||||
if i in (13, 14):
|
||||
s += rays(bx, by - 2.15, 2.4, 3.0, 10, 0.2, 0.08)
|
||||
return s
|
||||
|
||||
|
||||
# ── 5. eagle ──
|
||||
|
||||
def eagle_shape(x, y, sc, flap, tilt=0.0):
|
||||
"""An eagle seen from the front, wings spread; flap: -1 = tips up, 0 = level, 1 = tips down."""
|
||||
s = []
|
||||
for side in (-1, 1):
|
||||
ty = flap * 1.6
|
||||
pts = [(side * 0.35, -0.35), (side * 1.6, -0.75 + ty * 0.4), (side * 3.2, -0.8 + ty), (side * 4.0, -0.55 + ty)]
|
||||
for m in range(5): # the fingered primaries
|
||||
fx = side * (4.0 - m * 0.35)
|
||||
fy = -0.55 + ty + 0.15 + m * 0.18
|
||||
pts += [(fx + side * 0.25, fy + 0.35), (fx - side * 0.1, fy + 0.12)]
|
||||
pts += [(side * 1.6, 0.2 + ty * 0.3), (side * 0.35, 0.35)]
|
||||
s.append(P(tf(pts if side > 0 else pts, x, y, sc, tilt)))
|
||||
s.append(P(tf([(-0.5, -0.6), (0.5, -0.6), (0.6, 0.6), (0.0, 1.0), (-0.6, 0.6)], x, y, sc, tilt))) # body
|
||||
s.append(P(tf([(-0.35, 0.8), (0.35, 0.8), (0.7, 1.7), (-0.7, 1.7)], x, y, sc, tilt))) # tail fan
|
||||
s.append(K("yellow"))
|
||||
s.append(P(tf(ring(0, -0.95, 0.45, 10, 0, 0.02), x, y, sc, tilt))) # head
|
||||
s.append(K("red"))
|
||||
s.append(P(tf([(-0.15, -0.85), (0.15, -0.85), (0.05, -0.4), (-0.05, -0.45)], x, y, sc, tilt))) # hooked beak
|
||||
s.append(C(*tf([(-0.2, -1.05)], x, y, sc, tilt)[0], 0.07 * sc))
|
||||
s.append(C(*tf([(0.2, -1.05)], x, y, sc, tilt)[0], 0.07 * sc))
|
||||
s.append(K("blue"))
|
||||
return s
|
||||
|
||||
|
||||
def eagle(i, t):
|
||||
"""An eagle stoops out of the sky onto the box, snatches the number up in its talons and climbs away on huge wingbeats, then soars, the number hanging below it."""
|
||||
s = []
|
||||
if i < 5: # the stoop, wings swept up
|
||||
u = i / 5
|
||||
x, y = 5.0 + (0.2 - 5.0) * u, -8.0 + (-2.2 + 8.0) * u * u
|
||||
sc, flap, tilt = 0.55 + 0.2 * u, -1.1, -0.5 * (1 - u)
|
||||
s.append(K("blue"))
|
||||
for k in range(3):
|
||||
s.append(L([(x + 0.6 + k * 0.4, y - 1.0 - k * 0.3), (x + 1.6 + k * 0.4, y - 2.4 - k * 0.3)], 0.07))
|
||||
s += eagle_shape(x, y, sc, flap, tilt)
|
||||
return s
|
||||
if i < 8: # the grab
|
||||
x, y = 0.3, -2.4 - (i - 5) * 0.4
|
||||
sc, flap, tilt = 0.8, [1.0, 0.0, -1.0][i - 5], 0.0
|
||||
else: # the climb, then the soar
|
||||
u = ease_out(min(1.0, (i - 8) / 9))
|
||||
x, y = 0.3 + 1.0 * u, -3.6 - 2.6 * u + 0.15 * math.sin(i * 0.9)
|
||||
sc = 0.8 + 0.35 * u
|
||||
flap = [-1.0, 0.1, 1.0][i % 3] if i < 17 else 0.15 * math.sin(i * 0.8)
|
||||
tilt = 0.05 * math.sin(i * 0.7)
|
||||
ny = y + sc * 1.7 + 1.25
|
||||
s.append(K("red"))
|
||||
g = pop_scale(t, 5 / 23, 0.15, 1.3)
|
||||
s.append(NUM(x, ny, 2.0 * g * min(1.0, 0.75 + 0.25 * sc), rot=0.1 * math.sin(i * 0.6)))
|
||||
s.append(K("yellow"))
|
||||
for side in (-1, 1): # talons gripping the number
|
||||
tx = x + side * 0.6 * sc
|
||||
s.append(L([(tx, y + 0.7 * sc), (tx + side * 0.1, ny - 1.0), (tx + side * 0.35, ny - 0.75)], 0.1))
|
||||
if i in (5, 6):
|
||||
s.append(K("red"))
|
||||
s += rays(x, ny, 2.5, 3.1, 9, 0.2, 0.09)
|
||||
s.append(K("blue"))
|
||||
s += eagle_shape(x, y, sc, flap, tilt)
|
||||
for k in range(3): # a feather or two, drifting down
|
||||
age = i - 8 - k * 4
|
||||
if age >= 0:
|
||||
fx, fy = x - 1.8 + k * 1.6 + 0.3 * math.sin(age * 0.9), min(0.8, y + 0.6 + age * 0.22)
|
||||
s.append(P(rotate([(fx - 0.25, fy), (fx, fy - 0.08), (fx + 0.25, fy), (fx, fy + 0.08)], math.sin(age) * 0.8, fx, fy)))
|
||||
return s
|
||||
|
||||
|
||||
# ── 6. drawbridge ──
|
||||
|
||||
def drawbridge(i, t):
|
||||
"""A castle springs up over the box; its drawbridge clanks down on its chains and slams flat, banners unroll down the towers and the number stands in the lit gateway."""
|
||||
s = []
|
||||
gy = -0.55 # the ground line
|
||||
grow = [0.2, 0.55, 0.9, 1.08, 0.97, 1.0][i] if i < 6 else 1.0
|
||||
|
||||
def at(pts):
|
||||
return [(x, gy + (y - gy) * grow) for x, y in pts]
|
||||
crenel = []
|
||||
for k in range(9):
|
||||
x = -1.4 + k * 0.6
|
||||
crenel += [(x, -5.6), (x, -6.0), (x + 0.3, -6.0), (x + 0.3, -5.6)]
|
||||
s.append(P(at([(-1.6, gy)] + [(-1.6, -5.6)] + crenel + [(3.6, -5.6), (3.6, gy)]))) # the gatehouse wall
|
||||
for tx in (-3.4, 3.4): # the towers
|
||||
cr = []
|
||||
for k in range(4):
|
||||
x = tx + k * 0.6
|
||||
cr += [(x, -7.0), (x, -7.5), (x + 0.3, -7.5), (x + 0.3, -7.0)]
|
||||
s.append(P(at([(tx, gy), (tx, -7.0)] + cr[2:] + [(tx + 2.0, -7.0), (tx + 2.0, gy)])))
|
||||
s.append(K("yellow"))
|
||||
for tx in (-2.4, 4.4):
|
||||
for wy in (-5.6, -3.4):
|
||||
s.append(P(at([(tx - 0.1, wy), (tx + 0.1, wy), (tx + 0.1, wy + 0.8), (tx - 0.1, wy + 0.8)]))) # arrow slits
|
||||
cx, cy, r = 1.0, -3.3, 1.95 # the gateway: an arch, lit inside
|
||||
arch = [(cx - r, gy)] + [(cx + r * math.cos(math.pi + k * math.pi / 8), cy + r * math.sin(math.pi + k * math.pi / 8)) for k in range(9)] + [(cx + r, gy)]
|
||||
s.append(P(at(arch)))
|
||||
if i >= 6:
|
||||
for tx in (-2.4, 4.4): # pennants on poles
|
||||
s.append(K("blue"))
|
||||
s.append(L([(tx, -7.5), (tx, -9.0)], 0.08))
|
||||
s.append(K("yellow"))
|
||||
s.append(P([(tx, -9.0)] + [(tx + 0.4 * k, -8.8 + 0.18 * math.sin(i * 1.4 - k * 1.1)) for k in range(1, 5)] + [(tx, -8.4)]))
|
||||
if i >= 6:
|
||||
g = pop_scale(t, 12 / 23, 0.1, 1.2) if i >= 12 else 0.0
|
||||
if g:
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(cx, -2.55, 1.55 * g, w=0.28, rot=0.0))
|
||||
edges = [-5.4, -5.3, -5.3, -5.3, -5.2, -5.2, -5.2, -4.8, -4.2, -3.4, -2.4, -1.4, 1.0, 0.5, 0.65]
|
||||
e = edges[i] if i < len(edges) else 0.6
|
||||
e = gy + (e - gy) * grow
|
||||
s.append(K("blue"))
|
||||
if e < gy: # still up: planks over the gateway
|
||||
w = 2.15 + (e + 5.4) * 0.05
|
||||
s.append(P([(cx - 2.15, gy), (cx + 2.15, gy), (cx + w, e), (cx - w, e)]))
|
||||
s.append(K("red"))
|
||||
for k in range(1, 5):
|
||||
x = cx - 2.15 + k * 0.86
|
||||
s.append(L([(x, gy - 0.1), (x, e + 0.1)], 0.05))
|
||||
s.append(K("blue"))
|
||||
for side in (-1, 1):
|
||||
s.append(L([(cx + side * 2.3, gy + (-5.5 - gy) * grow), (cx + side * 2.0, e + 0.05)], 0.07)) # the chains
|
||||
else: # down, toward us
|
||||
w = 2.15 + (e - gy) * 0.7
|
||||
s.append(P([(cx - 2.15, gy), (cx + 2.15, gy), (cx + w, e), (cx - w, e)]))
|
||||
s.append(K("red"))
|
||||
for k in range(1, 5):
|
||||
f = k / 5
|
||||
s.append(L([(cx - 2.15 + 4.3 * f, gy + 0.05), (cx - w + 2 * w * f, e - 0.05)], 0.05))
|
||||
s.append(K("blue"))
|
||||
for side in (-1, 1):
|
||||
s.append(L([(cx + side * 2.3, -5.5), (cx + side * 2.3, gy - 0.2), (cx + side * w, e)], 0.06))
|
||||
if i in (12, 13): # the slam
|
||||
s.append(K("red"))
|
||||
for side in (-1, 1):
|
||||
for k in range(3):
|
||||
s.append(C(cx + side * (w + 0.3 + k * 0.4), e - 0.1 - k * 0.25, 0.22 + k * 0.05, 0.06))
|
||||
s.append(K("yellow"))
|
||||
s += rays(cx, -2.55, 2.3, 2.9, 10, 0.1, 0.08)
|
||||
if i >= 13: # banners unroll down the towers
|
||||
n = min(1.0, (i - 12) / 4)
|
||||
for tx, col in ((-2.4, "yellow"), (4.4, "yellow")):
|
||||
bot = -6.8 + 3.6 * n
|
||||
s.append(K(col))
|
||||
s.append(P([(tx - 0.65, -6.8), (tx + 0.65, -6.8), (tx + 0.65, bot), (tx, bot - 0.45), (tx - 0.65, bot)]))
|
||||
s.append(K("blue"))
|
||||
s.append(L([(tx, -6.5), (tx, bot - 0.2)], 0.1))
|
||||
s.append(L([(tx - 0.8, -6.85), (tx + 0.8, -6.85)], 0.1))
|
||||
return s
|
||||
|
||||
|
||||
# ── 7. crane ──
|
||||
|
||||
def crane(i, t):
|
||||
"""A tower crane over the box runs its hook down, hoists a great sign with the number up out of the box and swings it into place, cables singing."""
|
||||
s = []
|
||||
mx0, mx1, jy = 4.4, 5.1, -7.0 # the mast, the jib's height
|
||||
s.append(K("yellow"))
|
||||
s.append(L([(mx0, 0.6), (mx0, jy)], 0.16))
|
||||
s.append(L([(mx1, 0.6), (mx1, jy)], 0.16))
|
||||
s.append(L([(mx0 if k % 2 == 0 else mx1, 0.6 - k * 0.76) for k in range(11)], 0.1)) # its lattice
|
||||
s.append(L([(-2.6, jy), (7.4, jy)], 0.15)) # the jib
|
||||
s.append(L([(-2.6, jy + 0.45), (7.4, jy + 0.45)], 0.13))
|
||||
s.append(L([(-2.6 + k * 0.5, jy + (0.45 if k % 2 else 0.0)) for k in range(21)], 0.08))
|
||||
s.append(L([(-2.6, jy), (mx0 + 0.35, jy - 1.4), (7.4, jy)], 0.06)) # the ties
|
||||
s.append(L([(mx0 + 0.35, jy - 1.4), (mx0 + 0.35, jy)], 0.08))
|
||||
s.append(K("blue"))
|
||||
s.append(P([(6.4, jy + 0.45), (7.4, jy + 0.45), (7.4, jy + 1.5), (6.4, jy + 1.5)])) # the counterweight
|
||||
s.append(P([(mx0 - 0.4, jy + 0.45), (mx1 + 0.05, jy + 0.45), (mx1 + 0.05, jy + 1.4), (mx0 - 0.4, jy + 1.4)])) # the cab
|
||||
s.append(K("yellow"))
|
||||
s.append(P([(mx0 - 0.3, jy + 0.6), (mx0 + 0.2, jy + 0.6), (mx0 + 0.2, jy + 1.0), (mx0 - 0.3, jy + 1.0)]))
|
||||
# the trolley's x and the hook's y, frame by frame
|
||||
if i < 6:
|
||||
u = ease_out(i / 5)
|
||||
tx, hy = 3.2 + (0.0 - 3.2) * u, jy + 1.2 + (-1.0 - jy - 1.2) * u
|
||||
elif i < 9:
|
||||
tx, hy = 0.0, -1.0 - (i - 6) * 0.15
|
||||
else:
|
||||
u = ease_out(min(1.0, (i - 9) / 7))
|
||||
tx, hy = 0.0 + 1.2 * u, -1.45 + (-5.0 + 1.45) * u
|
||||
sw = 0.0
|
||||
if i >= 9:
|
||||
sw = 0.22 * math.exp(-(i - 9) * 0.18) * math.sin((i - 9) * 0.95)
|
||||
s.append(K("blue"))
|
||||
s.append(P([(tx - 0.4, jy + 0.35), (tx + 0.4, jy + 0.35), (tx + 0.4, jy + 0.7), (tx - 0.4, jy + 0.7)])) # the trolley
|
||||
hx = tx + (hy - jy) * -math.sin(sw) * 0.0
|
||||
s.append(L([(tx - 0.1, jy + 0.7), (hx - 0.1, hy)], 0.04))
|
||||
s.append(L([(tx + 0.1, jy + 0.7), (hx + 0.1, hy)], 0.04))
|
||||
s.append(L([(hx, hy - 0.05), (hx, hy + 0.3), (hx + 0.2, hy + 0.45), (hx + 0.05, hy + 0.6)], 0.09)) # the hook
|
||||
if i >= 6:
|
||||
g = min(1.0, 0.35 + (i - 6) * 0.22)
|
||||
pw, ph = 5.4 * g, 2.6 * g
|
||||
top = hy + 0.6 + 0.9 * g
|
||||
corners = [(hx - pw / 2, top), (hx + pw / 2, top), (hx + pw / 2, top + ph), (hx - pw / 2, top + ph)]
|
||||
corners = rotate(corners, sw, hx, hy + 0.5)
|
||||
s.append(L([corners[0], rotate([(hx, hy + 0.55)], sw, hx, hy + 0.5)[0], corners[1]], 0.05)) # the sling
|
||||
s.append(K("yellow"))
|
||||
s.append(P(corners, 0, 0.03))
|
||||
s.append(K("blue"))
|
||||
s.append(P(corners, 0.12, 0.03))
|
||||
for c in corners:
|
||||
ix, iy = c[0] + (hx - c[0]) * 0.08, c[1] + (top + ph / 2 - c[1]) * 0.15
|
||||
s.append(C(ix, iy, 0.07))
|
||||
ncx, ncy = rotate([(hx, top + ph / 2)], sw, hx, hy + 0.5)[0]
|
||||
s.append(K("red"))
|
||||
s.append(NUM(ncx, ncy, 1.85 * g, rot=sw))
|
||||
if i >= 16 and i % 2 == 0: # lights along the sign
|
||||
s.append(K("red"))
|
||||
s += rays(ncx, ncy, 3.3, 3.9, 12, i * 0.1, 0.08)
|
||||
return s
|
||||
|
||||
|
||||
# ── 8. longship ──
|
||||
|
||||
def longship(i, t):
|
||||
"""A longship rows up a great swell, its striped sail bursting full with the number on it, crests, and crashes down in a burst of spray before riding on."""
|
||||
s = []
|
||||
x = -1.2 + 2.6 * ease_out(t)
|
||||
if i < 9:
|
||||
pitch, lift = -0.32 * i / 8, -0.9 * i / 8
|
||||
elif i < 12:
|
||||
pitch, lift = [-0.05, 0.22, 0.08][i - 9], [-1.0, -0.3, 0.1][i - 9]
|
||||
else:
|
||||
pitch, lift = 0.06 * math.sin((i - 12) * 0.9), 0.1 * math.sin((i - 12) * 0.9)
|
||||
wy = -0.9 + lift # the waterline under the ship
|
||||
s.append(K("blue"))
|
||||
for row in range(3): # the sea
|
||||
y = -0.6 + row * 0.5
|
||||
ph = i * 0.9 + row * 1.3
|
||||
amp = 0.25 + (0.5 if i < 10 and row == 0 else 0)
|
||||
s.append(L([(-5.0 + m * 0.6, y + amp * math.sin(ph + m * 0.8) * (1.0 if m > 3 else 0.6)) for m in range(19)], 0.12))
|
||||
|
||||
def at(pts):
|
||||
return rotate([(x + px, wy + py) for px, py in pts], pitch, x, wy)
|
||||
s.append(K("red"))
|
||||
hull = [(-3.4, -1.0), (-2.6, -0.2), (-1.2, 0.35), (1.2, 0.35), (2.6, -0.2), (3.4, -1.0), (3.1, -0.9), (2.4, -0.6),
|
||||
(-2.4, -0.6), (-3.1, -0.9)]
|
||||
s.append(P(at(hull)))
|
||||
s.append(L(at([(3.2, -0.9), (3.6, -1.7), (3.3, -2.3), (2.9, -2.1), (3.0, -1.8)]), 0.16)) # the curled prow
|
||||
s.append(L(at([(-3.2, -0.9), (-3.6, -1.7), (-3.4, -2.1), (-3.05, -2.0)]), 0.16)) # and stern
|
||||
s.append(K("yellow"))
|
||||
for k in range(6): # shields along the side
|
||||
s.append(P(at(ring(-2.0 + k * 0.8, -0.35, 0.27, 8, k, 0.02))))
|
||||
s.append(K("red"))
|
||||
sweep = math.sin(i * 1.1)
|
||||
for k in range(5): # the oars, all together
|
||||
ox, oy = at([(-1.6 + k * 0.8, -0.1)])[0]
|
||||
s.append(L([(ox, oy), (ox - 0.7 - 0.5 * sweep, oy + 1.1 - 0.2 * abs(sweep))], 0.07))
|
||||
s.append(L(at([(0.0, -0.6), (0.0, -5.8)]), 0.14)) # the mast
|
||||
full = min(1.0, max(0.0, (i - 2) / 4))
|
||||
s.append(L(at([(-2.6, -5.5), (2.6, -5.5)]), 0.12)) # the yard
|
||||
if full > 0:
|
||||
bel = 0.45 * full + 0.06 * math.sin(i * 1.5)
|
||||
hgt = 3.4 * full
|
||||
xs = [-2.5 + 5.0 * m / 8 for m in range(9)]
|
||||
edge = [(px, -5.4) for px in xs] + [(px, -5.4 + hgt + bel * math.sin(math.pi * (px + 2.5) / 5.0)) for px in reversed(xs)]
|
||||
s.append(K("yellow"))
|
||||
s.append(P(at(edge), 0, 0.03))
|
||||
s.append(K("red"))
|
||||
for sx in (-2.15, 2.15): # its stripes, down each side
|
||||
s.append(P(at([(sx - 0.3, -5.4), (sx + 0.3, -5.4), (sx + 0.3, -5.4 + hgt + bel * 0.45), (sx - 0.3, -5.4 + hgt + bel * 0.45)])))
|
||||
if i >= 6:
|
||||
s.append(K("blue"))
|
||||
ncx, ncy = at([(0.0, -3.55 + bel * 0.5)])[0]
|
||||
s.append(NUM(ncx, ncy, 1.85 * pop_scale(t, 6 / 23, 0.12, 1.2), rot=pitch))
|
||||
if 10 <= i <= 15: # the crash of spray
|
||||
k = i - 10
|
||||
s.append(K("blue"))
|
||||
for side in (-1, 1):
|
||||
bx = x + side * 3.0
|
||||
for m in range(5):
|
||||
a = -math.pi / 2 + side * (0.3 + m * 0.25)
|
||||
r = 0.5 + k * 0.5
|
||||
px, py = bx + r * math.cos(a), wy - 0.6 + r * math.sin(a) + k * k * 0.06
|
||||
s.append(C(px, py, max(0.06, 0.24 - k * 0.03)))
|
||||
return s
|
||||
|
||||
|
||||
ANIMS = [
|
||||
(dragon, "red", "scorch"), (excavator, "yellow", "hydraulic"),
|
||||
(geyser, "blue", "gush"), (pyramid, "yellow", "quarry"),
|
||||
(eagle, "blue", "screech"), (drawbridge, "red", "clank"),
|
||||
(crane, "yellow", "winch"), (longship, "red", "oarstroke"),
|
||||
]
|
||||
@@ -0,0 +1,156 @@
|
||||
"""Streak level 6's sounds: 2 s each, one per animation in level6.py (same names as its ANIMS).
|
||||
|
||||
Each fn() returns a buf from tools/sound_kit.py; gen_sounds.py normalises and writes it as
|
||||
<name>.wav. Every random source is seeded (level 6: 2600-2699) so the output never changes.
|
||||
"""
|
||||
import math
|
||||
import random
|
||||
|
||||
from sound_kit import SR, TAU, add_noise, add_tone, bell, sbuf
|
||||
|
||||
|
||||
def scorch():
|
||||
"""A wingbeat, a long hissing breath in, then a roaring blast of fire that crackles away."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.05, 0.25, 0.5, a=0.01, d=0.08, lp0=0.08, seed=2600) # the wingbeat
|
||||
add_tone(b, 0.05, 0.2, 70, 50, 0.4, a=0.005, d=0.07)
|
||||
add_noise(b, 0.35, 0.4, 0.25, a=0.35, d=0.3, lp0=0.2, lp1=0.6, seed=2601) # the breath in
|
||||
add_noise(b, 0.72, 1.1, 0.8, a=0.02, d=0.6, lp0=0.35, lp1=0.12, seed=2602) # the blast
|
||||
add_noise(b, 0.72, 1.0, 0.3, a=0.01, d=0.4, lp0=0.9, lp1=0.5, seed=2603)
|
||||
add_tone(b, 0.72, 1.0, 82, 58, 0.45, a=0.03, d=0.5, shape="saw", vib=(9, 0.08)) # the roar
|
||||
add_tone(b, 0.72, 0.9, 123, 92, 0.2, a=0.03, d=0.4, shape="saw", vib=(7, 0.06))
|
||||
rng = random.Random(2604)
|
||||
for k in range(22): # crackles
|
||||
st = 1.0 + k * 0.042 + rng.uniform(0, 0.03)
|
||||
add_noise(b, st, 0.015, 0.25 * (1 - k / 26), a=0.0005, d=0.004, lp0=0.95, seed=2610 + k)
|
||||
return b
|
||||
|
||||
|
||||
def hydraulic():
|
||||
"""A diesel engine chugging, hydraulics whining, a crunching bite of earth, clods thudding, and a bright ta-da."""
|
||||
b = sbuf()
|
||||
ph = 0.0
|
||||
for k in range(len(b)): # the engine
|
||||
t = k / SR
|
||||
f = 38 + (8 if 0.25 < t < 1.0 else 0)
|
||||
ph += TAU * f / SR
|
||||
am = 0.55 + 0.45 * math.sin(TAU * 11 * t)
|
||||
b[k] += ((((ph / TAU) % 1.0) * 2 - 1) * 0.22) * am * min(1.0, t / 0.05) * min(1.0, (2.0 - t) / 0.3)
|
||||
add_tone(b, 0.0, 0.4, 320, 520, 0.08, a=0.05, d=0.4, shape="tri") # whine: down
|
||||
add_noise(b, 0.38, 0.25, 0.7, a=0.003, d=0.08, lp0=0.5, lp1=0.15, seed=2620) # the bite
|
||||
add_tone(b, 0.38, 0.15, 90, 50, 0.4, a=0.002, d=0.05)
|
||||
add_tone(b, 0.55, 0.45, 380, 700, 0.09, a=0.05, d=0.4, shape="tri") # whine: up
|
||||
rng = random.Random(2621)
|
||||
for k in range(6): # clods
|
||||
st = 0.7 + k * 0.08 + rng.uniform(0, 0.03)
|
||||
add_tone(b, st, 0.08, rng.uniform(110, 170), 60, 0.25, a=0.002, d=0.03)
|
||||
add_noise(b, st, 0.05, 0.15, a=0.001, d=0.015, lp0=0.3, seed=2622 + k)
|
||||
for k, f in enumerate((587, 784, 1175)): # the number: ta-da
|
||||
bell(b, 0.85 + k * 0.08, f, 0.2, 0.55)
|
||||
add_noise(b, 1.35, 0.4, 0.4, a=0.01, d=0.15, lp0=0.4, lp1=0.1, seed=2630) # the load dumped
|
||||
return b
|
||||
|
||||
|
||||
def gush():
|
||||
"""An underground rumble, gurgling bubbles, then a roaring rush of water and spray pattering down."""
|
||||
b = sbuf()
|
||||
add_tone(b, 0.0, 0.7, 45, 38, 0.5, a=0.2, d=0.5)
|
||||
add_noise(b, 0.0, 0.7, 0.4, a=0.2, d=0.4, lp0=0.03, seed=2640)
|
||||
rng = random.Random(2641)
|
||||
for k in range(9): # gurgles
|
||||
f = rng.uniform(180, 420)
|
||||
add_tone(b, 0.08 + k * 0.065, 0.06, f, f * 2.2, 0.22, a=0.004, d=0.03)
|
||||
add_tone(b, 0.62, 0.2, 60, 30, 0.6, a=0.002, d=0.08) # the burst
|
||||
add_noise(b, 0.62, 1.38, 0.75, a=0.04, d=0.7, lp0=0.25, lp1=0.65, seed=2642) # the rush
|
||||
add_noise(b, 0.66, 1.2, 0.25, a=0.1, d=0.6, lp0=0.95, seed=2643)
|
||||
for k in range(26): # spray falling back
|
||||
st = 1.0 + k * 0.035 + rng.uniform(0, 0.02)
|
||||
f = rng.uniform(1400, 3000)
|
||||
add_tone(b, st, 0.03, f, f * 0.7, 0.07, a=0.001, d=0.01)
|
||||
return b
|
||||
|
||||
|
||||
def quarry():
|
||||
"""Five heavy stone blocks thud down, each a little higher, a capstone clunks on, and a bright shining chord rings out."""
|
||||
b = sbuf()
|
||||
for k in range(5):
|
||||
st = 0.04 + k * 0.17
|
||||
add_tone(b, st, 0.2, 70 + k * 9, 40 + k * 6, 0.6, a=0.002, d=0.07)
|
||||
add_noise(b, st, 0.12, 0.45, a=0.001, d=0.03, lp0=0.12, seed=2650 + k)
|
||||
add_noise(b, st + 0.04, 0.12, 0.08, a=0.01, d=0.05, lp0=0.7, seed=2660 + k) # grit trickling
|
||||
add_tone(b, 0.98, 0.12, 300, 180, 0.4, a=0.001, d=0.04) # the capstone
|
||||
add_noise(b, 0.98, 0.06, 0.3, a=0.001, d=0.015, lp0=0.6, seed=2670)
|
||||
for k, f in enumerate((523, 659, 784, 1047)): # the blaze
|
||||
bell(b, 1.08 + k * 0.035, f, 0.18, 0.7)
|
||||
add_tone(b, 1.08, 0.9, 2093, amp=0.04, a=0.2, d=0.5, vib=(6, 0.01))
|
||||
return b
|
||||
|
||||
|
||||
def screech():
|
||||
"""Wind whistling past in a dive, a piercing raptor's scream, then great heavy wingbeats climbing away."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 0.45, 0.45, a=0.3, d=0.15, lp0=0.05, lp1=0.5, seed=2680) # the stoop
|
||||
for st, f0, f1, a in ((0.38, 2900, 1900, 0.3), (1.45, 2600, 1800, 0.14)): # the screams
|
||||
add_tone(b, st, 0.42, f0, f1, a, a=0.01, d=0.25, shape="saw", vib=(38, 0.035))
|
||||
add_tone(b, st, 0.42, f0 * 0.5, f1 * 0.5, a * 0.4, a=0.01, d=0.25, shape="tri", vib=(38, 0.035))
|
||||
for k in range(5): # the wingbeats
|
||||
st = 0.75 + k * 0.24
|
||||
add_noise(b, st, 0.16, 0.6 - k * 0.06, a=0.03, d=0.05, lp0=0.07, seed=2690 + k)
|
||||
add_tone(b, st, 0.12, 62, 48, 0.3 - k * 0.03, a=0.02, d=0.04)
|
||||
return b
|
||||
|
||||
|
||||
def clank():
|
||||
"""A chain paying out link by link, a thundering slam of timber, and a short brassy flourish."""
|
||||
b = sbuf()
|
||||
rng = random.Random(2697)
|
||||
st = 0.05
|
||||
for k in range(18): # the chain
|
||||
f = rng.uniform(1800, 2600)
|
||||
add_tone(b, st, 0.05, f, amp=0.22, a=0.001, d=0.012, shape="square")
|
||||
add_noise(b, st, 0.03, 0.15, a=0.001, d=0.006, lp0=0.9, seed=2698)
|
||||
st += 0.06 - k * 0.0012
|
||||
add_tone(b, 0.98, 0.35, 75, 40, 0.8, a=0.001, d=0.1) # the slam
|
||||
add_noise(b, 0.98, 0.3, 0.7, a=0.001, d=0.06, lp0=0.25, lp1=0.05, seed=2699)
|
||||
for st, chord, dur in ((1.3, (392, 523), 0.12), (1.44, (523, 659, 784), 0.55)): # ta-ra!
|
||||
for f in chord:
|
||||
add_tone(b, st, dur, f, amp=0.1, a=0.015, d=0.45, shape="saw", vib=(5, 0.005))
|
||||
return b
|
||||
|
||||
|
||||
def winch():
|
||||
"""A motor whines up with a ratchet clicking, the cable creaks, it clunks to a stop and the sign swings, ting."""
|
||||
b = sbuf()
|
||||
ph = 0.0
|
||||
for k in range(int(SR * 1.05)): # the motor
|
||||
t = k / SR
|
||||
f = 110 + 120 * min(1.0, t / 0.5) + 15 * math.sin(TAU * 3 * t)
|
||||
ph += TAU * f / SR
|
||||
loud = min(1.0, t / 0.08) * min(1.0, (1.05 - t) / 0.05)
|
||||
b[k] += ((((ph / TAU) % 1.0) * 2 - 1) * 0.16 + math.sin(ph * 2) * 0.08) * loud
|
||||
for k in range(16): # the ratchet
|
||||
add_noise(b, 0.1 + k * 0.058, 0.02, 0.22, a=0.0005, d=0.005, lp0=0.85, seed=2672 + k)
|
||||
add_tone(b, 0.55, 0.4, 340, 300, 0.07, a=0.1, d=0.3, shape="tri", vib=(17, 0.05)) # the creak
|
||||
add_tone(b, 1.05, 0.15, 140, 70, 0.6, a=0.001, d=0.05) # clunk
|
||||
add_noise(b, 1.05, 0.08, 0.4, a=0.001, d=0.02, lp0=0.4, seed=2689)
|
||||
for k, f in enumerate((1568, 2093)): # ting-ting
|
||||
bell(b, 1.25 + k * 0.18, f, 0.22, 0.45)
|
||||
add_tone(b, 1.3, 0.5, 260, 230, 0.05, a=0.1, d=0.3, shape="tri", vib=(12, 0.06)) # swaying creak
|
||||
return b
|
||||
|
||||
|
||||
def oarstroke():
|
||||
"""A rowing drum and the oars' swish, a wave crashing as the ship slams down, and a deep war horn."""
|
||||
b = sbuf()
|
||||
for k in range(3): # drum + stroke
|
||||
st = 0.03 + k * 0.28
|
||||
add_tone(b, st, 0.2, 110, 70, 0.6, a=0.002, d=0.08)
|
||||
add_noise(b, st + 0.06, 0.2, 0.25, a=0.08, d=0.06, lp0=0.4, lp1=0.1, seed=2676 + k)
|
||||
add_noise(b, 0.85, 0.9, 0.9, a=0.01, d=0.3, lp0=0.6, lp1=0.08, seed=2679) # the crash
|
||||
add_tone(b, 0.85, 0.3, 70, 40, 0.5, a=0.002, d=0.1)
|
||||
for f, a in ((147, 0.3), (294, 0.14), (441, 0.06)): # the horn
|
||||
add_tone(b, 1.05, 0.95, f * 0.97, f, a, a=0.12, d=1.2, shape="saw", vib=(4, 0.006))
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [scorch, hydraulic, gush, quarry, screech, clank, winch, oarstroke]
|
||||
@@ -0,0 +1,663 @@
|
||||
"""Streak level 7: a full year (365 days), and again every 100 days past it (465, 565, ...).
|
||||
|
||||
The summit: the biggest, rarest rewards in the app. Same rules as level0.py: fn(i, t) -> shapes,
|
||||
i = frame 0..23, t = 0..1; NUM(...) is where the number goes. This level is reused for 465, 565,
|
||||
..., so every number has room for 3 digits (num_width(h, 3)) and a 4th only spills a little past
|
||||
its frame instead of into the drawing. Sounds: level7_sounds.py, same names.
|
||||
"""
|
||||
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 tf(pts, ox, oy, sc=1.0, rot=0.0):
|
||||
"""Local points scaled by sc, turned rot, moved to (ox, oy)."""
|
||||
c, s = math.cos(rot), math.sin(rot)
|
||||
return [(ox + sc * (x * c - y * s), oy + sc * (x * s + y * c)) for x, y in pts]
|
||||
|
||||
|
||||
def tube(spine, w0, w1):
|
||||
"""A tapering band round a polyline: width w0 at its start, w1 at its end."""
|
||||
left, right = [], []
|
||||
n = len(spine)
|
||||
for k, (x, y) in enumerate(spine):
|
||||
px, py = spine[max(0, k - 1)]
|
||||
nx, ny = spine[min(n - 1, k + 1)]
|
||||
dx, dy = nx - px, ny - py
|
||||
d = math.hypot(dx, dy) or 1.0
|
||||
w = (w0 + (w1 - w0) * k / max(1, n - 1)) / 2
|
||||
left.append((x - dy / d * w, y + dx / d * w))
|
||||
right.append((x + dy / d * w, y - dx / d * w))
|
||||
return left + right[::-1]
|
||||
|
||||
|
||||
def lerp(a, b, u):
|
||||
return a + (b - a) * u
|
||||
|
||||
|
||||
# ── 1. phoenix ──
|
||||
|
||||
def flames(cx, base, half, hgt, i, n=7):
|
||||
"""A bed of flame tongues, n across, half wide either side of cx, about hgt tall."""
|
||||
out = []
|
||||
for k in range(n):
|
||||
x = cx - half + (k + 0.5) * 2 * half / n
|
||||
h = hgt * (0.65 + 0.35 * math.sin(k * 2.3 + i * 1.7)) * (1.0 if k in (n // 2 - 1, n // 2, n // 2 + 1) else 0.8)
|
||||
w = half / n * 1.5
|
||||
lean = 0.25 * math.sin(i * 1.1 + k)
|
||||
out.append(P([(x - w, base), (x - w * 0.6, base - h * 0.5), (x + lean, base - h), (x + w * 0.7, base - h * 0.45), (x + w, base)]))
|
||||
return out
|
||||
|
||||
|
||||
def phoenix(i, t):
|
||||
"""Embers in the box catch, flames roar up, and a phoenix bursts out of them, wings blazing open, and soars above the number burning in the fire below."""
|
||||
s = []
|
||||
cx = 1.0
|
||||
hgt = [0.3, 0.5, 0.8, 1.2, 1.7, 2.3][i] if i < 6 else 2.7 + 0.2 * math.sin(i * 1.3)
|
||||
s.append(K("yellow"))
|
||||
s += flames(cx, -0.45, 2.9, hgt, i, 9)
|
||||
s.append(K("red"))
|
||||
s += flames(cx, -0.45, 1.8, hgt * 0.45, i + 3, 5)
|
||||
if i < 6: # embers flying up
|
||||
s.append(K("red"))
|
||||
for k in range(5):
|
||||
s.append(C(cx - 1.2 + k * 0.6 + 0.2 * math.sin(i + k), -0.8 - ((i * 0.5 + k * 0.37) % 1.0) * 2.4, 0.09))
|
||||
return s
|
||||
if i in (6, 7): # the burst
|
||||
s.append(K("yellow"))
|
||||
s.append(P(star(cx, -2.6, 2.6 - (i - 6) * 0.5, 1.0, 12, i * 0.2)))
|
||||
s.append(K("red"))
|
||||
s.append(P(star(cx, -2.6, 1.4, 0.6, 8, i * 0.4)))
|
||||
if i >= 9:
|
||||
s.append(K("blue"))
|
||||
g = pop_scale(t, 9 / 23, 0.12, 1.25)
|
||||
s.append(NUM(cx, -1.75, 2.15 * g, w=0.4, rot=0.04 * math.sin(i * 1.5)))
|
||||
if i < 7:
|
||||
return s
|
||||
by = -2.6 - 3.6 * ease_out(min(1.0, (i - 7) / 6)) + 0.15 * math.sin(i * 1.4)
|
||||
sc = min(1.3, 0.6 + (i - 7) * 0.15)
|
||||
beat = [1.0, 0.2, -0.8, -0.2][i % 4] if i < 20 else 0.55
|
||||
sway = 0.2 * math.sin(i * 1.2)
|
||||
fan = [(-0.3, 0.5), (0.3, 0.5)] # a fanned tail of flame, below
|
||||
for m in range(7):
|
||||
x = 0.9 - m * 0.3 + sway
|
||||
fan.append((x, 1.9 + (0.45 if m % 2 == 0 else 0.0) - 0.1 * abs(m - 3)))
|
||||
s.append(K("yellow"))
|
||||
s.append(P(tf(fan, cx, by, sc)))
|
||||
s.append(K("red"))
|
||||
s.append(P(tf([(-0.2, 0.5), (0.2, 0.5), (0.35 + sway, 1.6), (sway, 1.95), (-0.35 + sway, 1.6)], cx, by, sc)))
|
||||
for side in (-1, 1): # the wings: long fanned feathers
|
||||
for m in range(7):
|
||||
a0 = -math.pi / 2 + side * (0.25 + m * 0.22 + beat * 0.35)
|
||||
ln = 2.1 + m * 0.22 - (m == 6) * 0.6
|
||||
root = (side * 0.3, -0.2)
|
||||
tip = (root[0] + ln * math.cos(a0), root[1] + ln * math.sin(a0))
|
||||
perp = (math.cos(a0 + math.pi / 2) * 0.3, math.sin(a0 + math.pi / 2) * 0.3)
|
||||
mid = (root[0] + 0.55 * (tip[0] - root[0]), root[1] + 0.55 * (tip[1] - root[1]))
|
||||
pts = [root, (mid[0] + perp[0], mid[1] + perp[1]), tip, (mid[0] - perp[0], mid[1] - perp[1])]
|
||||
s.append(K("red" if m % 2 == 0 else "yellow"))
|
||||
s.append(P(tf(pts, cx, by, sc)))
|
||||
s.append(K("red"))
|
||||
s.append(P(tf([(-0.55, -0.45), (0.55, -0.45), (0.4, 0.5), (0, 0.85), (-0.4, 0.5)], cx, by, sc))) # body
|
||||
s.append(P(tf([(-0.2, -0.4), (0.2, -0.4), (0.25, -0.8), (-0.25, -0.8)], cx, by, sc))) # neck
|
||||
s.append(P(tf(ring(0, -1.0, 0.4, 9, 0, 0.02), cx, by, sc))) # head
|
||||
for m in range(3): # its crest
|
||||
s.append(L(tf([(-0.1 + m * 0.1, -1.3), (-0.45 + m * 0.3, -1.95 - 0.15 * (m == 1))], cx, by, sc), 0.1))
|
||||
s.append(K("yellow"))
|
||||
s.append(P(tf([(0.3, -1.1), (0.85, -0.92), (0.3, -0.82)], cx, by, sc))) # beak
|
||||
s.append(C(*tf([(0.1, -1.08)], cx, by, sc)[0], 0.08))
|
||||
s.append(P(tf([(-0.3, -0.2), (0.3, -0.2), (0, 0.45)], cx, by, sc))) # breast flame
|
||||
if i >= 13: # sparks raining off the wings
|
||||
s.append(K("yellow"))
|
||||
for k in range(8):
|
||||
age = (i - 13 + k * 0.6) % 5
|
||||
side = 1 if k % 2 else -1
|
||||
x = cx + side * (1.8 + (k // 2) * 0.7) * sc
|
||||
s.append(P(star(x + 0.15 * math.sin(age * 2), by - 1.0 + age * 0.55, 0.16, 0.06, 4, age)))
|
||||
return s
|
||||
|
||||
|
||||
# ── 2. clocktower ──
|
||||
|
||||
def clocktower(i, t):
|
||||
"""A great clock tower rises over the box; its hands whirl round and round, a whole year spinning by, stop at twelve, and the bell tolls the number onto the clock face as pigeons scatter."""
|
||||
s = []
|
||||
gy = -0.55
|
||||
grow = [0.15, 0.45, 0.8, 1.06, 0.97, 1.0][i] if i < 6 else 1.0
|
||||
|
||||
def at(pts):
|
||||
return [(x, gy + (y - gy) * grow) for x, y in pts]
|
||||
cx, fy, fr = 1.0, -4.4, 1.95
|
||||
shake = 0.06 * math.sin(i * 3.0) if i in (14, 15, 19, 20) else 0.0
|
||||
s.append(P(at([(-1.25 + shake, gy), (3.25 + shake, gy), (3.25 + shake, -6.6), (-1.25 + shake, -6.6)]))) # the shaft
|
||||
s.append(P(at([(-1.55, -6.6), (3.55, -6.6), (3.55, -6.95), (-1.55, -6.95)]))) # the cornice
|
||||
s.append(P(at([(-0.95, -6.95), (2.95, -6.95), (2.95, -7.9), (-0.95, -7.9)]))) # the belfry
|
||||
s.append(P(at([(-1.25, -7.9), (3.25, -7.9), (cx, -9.6)]))) # the roof
|
||||
s.append(L(at([(cx, -9.6), (cx, -10.1)]), 0.1))
|
||||
s.append(K("yellow"))
|
||||
s.append(C(*at([(cx, -10.15)])[0], 0.15))
|
||||
for bx in (-0.35, 1.0, 2.35): # the belfry's openings
|
||||
s.append(P(at([(bx - 0.3, -7.05), (bx + 0.3, -7.05), (bx + 0.3, -7.5), (bx, -7.75), (bx - 0.3, -7.5)])))
|
||||
s.append(P(at([(cx - 0.55, gy), (cx + 0.55, gy), (cx + 0.55, -1.5), (cx, -1.9), (cx - 0.55, -1.5)]))) # the door
|
||||
for wx in (-0.6, 2.6):
|
||||
s.append(P(at([(wx - 0.12, -1.3), (wx + 0.12, -1.3), (wx + 0.12, -2.0), (wx - 0.12, -2.0)])))
|
||||
fcy = gy + (fy - gy) * grow
|
||||
s.append(P(ring(cx + shake, fcy, fr * min(1.0, grow), 20, 0, 0.03))) # the face
|
||||
s.append(K("blue"))
|
||||
s.append(P(ring(cx + shake, fcy, fr * min(1.0, grow), 20, 0, 0.03), 0.12))
|
||||
showing = i >= 14
|
||||
s.append(K("red"))
|
||||
for k in range(12): # the hour marks
|
||||
if showing and k not in (0, 6):
|
||||
continue
|
||||
a = -math.pi / 2 + k * math.pi / 6
|
||||
s.append(L([(cx + 1.55 * math.cos(a), fcy + 1.55 * math.sin(a)), (cx + 1.8 * math.cos(a), fcy + 1.8 * math.sin(a))], 0.1))
|
||||
if not showing and i >= 2: # the hands whirl, a year flying by
|
||||
if i < 13:
|
||||
u = (i - 2) / 11
|
||||
spin = (1 - (1 - u) ** 2) * 11
|
||||
am, ah = -math.pi / 2 + spin * 2 * math.pi, -math.pi / 2 + spin * 2 * math.pi / 12 + (1 - u) * 1.3
|
||||
else:
|
||||
am = ah = -math.pi / 2
|
||||
s.append(L([(cx, fcy), (cx + 1.0 * math.cos(ah), fcy + 1.0 * math.sin(ah))], 0.2))
|
||||
s.append(L([(cx, fcy), (cx + 1.55 * math.cos(am), fcy + 1.55 * math.sin(am))], 0.12))
|
||||
if i < 13 and i % 2: # motion arcs
|
||||
s.append(L([(cx + 1.3 * math.cos(am - d), fcy + 1.3 * math.sin(am - d)) for d in (0.0, 0.3, 0.6, 0.9)], 0.06))
|
||||
s.append(C(cx, fcy, 0.18))
|
||||
if showing:
|
||||
g = pop_scale(t, 14 / 23, 0.1, 1.2)
|
||||
s.append(NUM(cx + shake, fcy + 0.05, 1.42 * g, w=0.28, rot=0.0))
|
||||
for tb in (14, 19): # each toll rings out
|
||||
age = i - tb
|
||||
if 0 <= age < 5:
|
||||
s.append(K("yellow"))
|
||||
s += rays(cx, fcy, fr + 0.3 + age * 0.15, fr + 0.75 + age * 0.25, 12, 0.13, 0.1 - age * 0.012)
|
||||
s.append(K("blue"))
|
||||
for side in (-1, 1):
|
||||
for m in range(2):
|
||||
r = 2.3 + age * 0.3 + m * 0.4
|
||||
base = 0.0 if side > 0 else math.pi
|
||||
arc = [(cx + r * math.cos(base + a), -7.4 + r * math.sin(base + a)) for a in (-0.6, -0.3, 0, 0.3, 0.6)]
|
||||
s.append(L(arc, max(0.04, 0.12 - age * 0.02)))
|
||||
s.append(K("red"))
|
||||
for k in range(3): # pigeons scatter off the roof
|
||||
age = i - 14
|
||||
px, py = cx + (k - 1) * 0.8 + age * (0.3 + 0.1 * k) * (1 if k else -1), -9.0 - age * (0.18 + 0.04 * k)
|
||||
fl = 0.25 if (i + k) % 2 else -0.1
|
||||
s.append(L([(px - 0.35, py - fl), (px, py), (px + 0.35, py - fl)], 0.09))
|
||||
return s
|
||||
|
||||
|
||||
# ── 3. archway ──
|
||||
|
||||
def archway(i, t):
|
||||
"""A triumphal arch builds itself over the box: stones fly in from both sides one pair at a time, the keystone drops in with a thunderous clunk, and the number stands beneath it in glory."""
|
||||
s = []
|
||||
gy = -0.55
|
||||
cx, cy, r0, r1 = 1.0, -2.7, 2.65, 3.8
|
||||
pg = min(1.0, (i + 1) / 3) # the piers rise
|
||||
jolt = 0.12 if i == 12 else 0.0
|
||||
s.append(K("red"))
|
||||
for x0, x1 in ((cx - r1, cx - r0), (cx + r0, cx + r1)):
|
||||
top = gy + (cy - gy) * pg
|
||||
s.append(P([(x0, gy), (x1, gy), (x1, top + jolt), (x0, top + jolt)]))
|
||||
s.append(P([(x0 - 0.25, gy), (x1 + 0.25, gy), (x1 + 0.25, gy - 0.3), (x0 - 0.25, gy - 0.3)])) # plinths
|
||||
lands = {0: 3, 8: 3, 1: 5, 7: 5, 2: 7, 6: 7, 3: 9, 5: 9, 4: 12}
|
||||
for k in range(9):
|
||||
f = lands[k]
|
||||
if i < f - 1:
|
||||
continue
|
||||
a0, a1 = math.pi + k * math.pi / 9 + 0.02, math.pi + (k + 1) * math.pi / 9 - 0.02
|
||||
am = (a0 + a1) / 2
|
||||
ri, ro = r0 + 0.04, r1 - 0.04
|
||||
if k == 4:
|
||||
ro += 0.35
|
||||
pts = [(cx + ri * math.cos(a), cy + jolt + ri * math.sin(a)) for a in (a0, am, a1)] + \
|
||||
[(cx + ro * math.cos(a), cy + jolt + ro * math.sin(a)) for a in (a1, am, a0)]
|
||||
if i == f - 1: # still flying in
|
||||
if k == 4:
|
||||
pts = [(x, y - 2.2) for x, y in pts]
|
||||
else:
|
||||
side = -1 if k < 4 else 1
|
||||
pts = rotate([(x + side * 2.2, y - 1.0) for x, y in pts], side * 0.5, cx + side * 3.0, cy)
|
||||
s.append(K("yellow" if k == 4 else "red"))
|
||||
s.append(P(pts, 0, 0.03))
|
||||
if k == 4 and i >= f:
|
||||
s.append(K("red"))
|
||||
s.append(P(star(cx, cy + jolt - (r0 + ro) / 2, 0.4, 0.17, 5)))
|
||||
if i == 10: # the keystone waits high above
|
||||
s.append(K("yellow"))
|
||||
ri, ro = r0 + 0.04, r1 + 0.31
|
||||
a0, a1 = math.pi + 4 * math.pi / 9 + 0.02, math.pi + 5 * math.pi / 9 - 0.02
|
||||
pts = [(cx + ri * math.cos(a), cy - 4.0 + ri * math.sin(a)) for a in (a0, a1)] + [(cx + ro * math.cos(a), cy - 4.0 + ro * math.sin(a)) for a in (a1, a0)]
|
||||
s.append(P(pts))
|
||||
for k in range(9): # dust as each stone lands
|
||||
f = lands[k]
|
||||
if i == f:
|
||||
am = math.pi + (k + 0.5) * math.pi / 9
|
||||
x, y = cx + (r1 + 0.2) * math.cos(am), cy + (r1 + 0.2) * math.sin(am)
|
||||
s.append(K("red"))
|
||||
s.append(C(x, y, 0.22, 0.06))
|
||||
s.append(C(x + 0.35 * math.cos(am + 0.5), y + 0.35 * math.sin(am + 0.5), 0.15, 0.06))
|
||||
if i >= 12:
|
||||
s.append(K("yellow"))
|
||||
s += rays(cx, cy - r1 - 0.3, 0.9, 1.6 + 0.3 * (i % 2), 9, math.pi + 0.15, 0.1)
|
||||
g = pop_scale(t, 12 / 23, 0.1, 1.2)
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(cx, -2.15, 2.1 * g, w=0.38, rot=0.0))
|
||||
if i in (12, 13):
|
||||
s.append(K("red"))
|
||||
for side in (-1, 1):
|
||||
for m in range(3):
|
||||
s.append(C(cx + side * (r1 + 0.5 + m * 0.45), gy - 0.3 - m * 0.3, 0.25 + m * 0.06, 0.06))
|
||||
if i >= 14: # glints running round the arch
|
||||
s.append(K("yellow"))
|
||||
for k in range(2):
|
||||
a = math.pi + ((i - 14) * 0.45 + k * math.pi / 2) % math.pi
|
||||
rr = (r0 + r1) / 2
|
||||
s.append(P(star(cx + rr * math.cos(a), cy + rr * math.sin(a), 0.35, 0.1, 4, 0.0)))
|
||||
return s
|
||||
|
||||
|
||||
# ── 4. glacier ──
|
||||
|
||||
def glacier(i, t):
|
||||
"""A towering ice cliff stands over the sea by the box; cracks race down its face, a huge slab breaks off and crashes into the water, and the number bobs up on a gleaming iceberg."""
|
||||
s = []
|
||||
sea = -0.5
|
||||
s.append(K("blue"))
|
||||
cliff = [(-4.6, sea), (-4.6, -6.3), (-3.9, -7.0), (-3.1, -6.6), (-2.3, -7.3), (-1.4, -6.8), (-1.4, sea)]
|
||||
s.append(P(cliff, 0, 0.03))
|
||||
s.append(K("yellow"))
|
||||
for x, y0, y1 in ((-3.6, -6.2, -4.4), (-2.4, -6.4, -3.6)): # its old seams
|
||||
s.append(L([(x, y0), (x + 0.2, (y0 + y1) / 2), (x - 0.1, y1)], 0.06))
|
||||
slab = [(-1.4, sea), (-1.4, -6.8), (-0.6, -7.5), (0.4, -6.9), (0.65, -4.2), (0.25, -2.6), (0.55, sea)]
|
||||
if i < 8:
|
||||
sh = 0.07 * math.sin(i * 3.3) if i >= 4 else 0.0
|
||||
s.append(K("blue"))
|
||||
s.append(P([(x + sh, y) for x, y in slab], 0, 0.03))
|
||||
if i >= 1: # the crack racing down
|
||||
n = min(7, i + 1)
|
||||
pts = [(-1.4 + 0.18 * (m % 2) - 0.09, -7.0 + m * 0.95) for m in range(n)]
|
||||
s.append(K("yellow"))
|
||||
s.append(L(pts, 0.1))
|
||||
if i >= 3: # chips falling
|
||||
for k in range(2):
|
||||
s.append(C(-0.9 + k * 0.6, -6.5 + ((i - 3) * 1.2 + k * 2) % 6, 0.1))
|
||||
elif i < 12:
|
||||
a = [0.12, 0.42, 0.85, 1.2][i - 8]
|
||||
dn = [0.0, 0.3, 1.4, 3.2][i - 8]
|
||||
s.append(K("blue"))
|
||||
s.append(P(rotate([(x, y + dn) for x, y in slab], a, 0.55, sea + dn), 0, 0.03))
|
||||
if 10 <= i <= 18: # the splash
|
||||
k = i - 10
|
||||
s.append(K("blue"))
|
||||
sx = 3.0
|
||||
if k < 4:
|
||||
s.append(P([(sx - 1.6, sea), (sx - 0.9, sea - 2.0 - k), (sx - 0.3, sea - 1.2 - k * 0.8), (sx, sea - 3.2 - k * 1.1),
|
||||
(sx + 0.4, sea - 1.4 - k * 0.8), (sx + 1.0, sea - 2.4 - k), (sx + 1.8, sea)]))
|
||||
for m in range(11):
|
||||
ang = -math.pi / 2 + (m - 5) * 0.27
|
||||
r = 1.2 + k * 0.75
|
||||
x = sx + r * math.cos(ang) * 0.9
|
||||
y = sea - 0.4 + r * math.sin(ang) * 1.4 + k * k * 0.12
|
||||
if y < sea:
|
||||
s.append(C(x, y, max(0.07, 0.24 - k * 0.02)))
|
||||
s.append(K("blue"))
|
||||
for row in range(2): # the sea
|
||||
y = sea + 0.15 + row * 0.45
|
||||
amp = 0.18 + (0.35 if 11 <= i <= 16 and row == 0 else 0.0)
|
||||
s.append(L([(-5.0 + m * 0.6, y + amp * math.sin(i * 0.9 + row * 1.4 + m * 0.9)) for m in range(19)], 0.12))
|
||||
if i >= 13: # the iceberg bobs up
|
||||
up = [0.4, 0.85, 1.12, 0.95, 1.03][i - 13] if i < 18 else 1.0 + 0.03 * math.sin((i - 18) * 1.3)
|
||||
bx, base = 3.0, sea + 0.1
|
||||
berg = [(0.3 - bx, 0), (0.75 - bx, -2.0), (1.6 - bx, -3.25), (2.7 - bx, -3.6), (4.0 - bx, -3.15), (5.0 - bx, -2.1), (5.7 - bx, 0)]
|
||||
tilt = 0.04 * math.sin(i * 1.1)
|
||||
pts = rotate([(bx + x, base + y * up) for x, y in berg], tilt, bx, base)
|
||||
s.append(K("blue"))
|
||||
s.append(P(pts, 0, 0.03))
|
||||
s.append(K("yellow"))
|
||||
s.append(L(rotate([(bx - 1.0, base - 3.3 * up), (bx - 0.3, base - 3.55 * up)], tilt, bx, base), 0.1)) # its gleam
|
||||
if i >= 14:
|
||||
g = pop_scale(t, 14 / 23, 0.1, 1.2)
|
||||
s.append(K("red"))
|
||||
s.append(NUM(bx, base - 1.55 * up, 1.75 * g, w=0.34, rot=tilt))
|
||||
if i >= 17: # it sparkles
|
||||
s.append(K("yellow"))
|
||||
for k in range(3):
|
||||
if (i + k) % 3:
|
||||
ang = k * 2.1 + 0.5
|
||||
s.append(P(star(bx + 3.0 * math.cos(ang), base - 2.0 + 1.8 * math.sin(ang), 0.4, 0.1, 4, 0.0)))
|
||||
return s
|
||||
|
||||
|
||||
# ── 5. pegasus ──
|
||||
|
||||
def horse(x, y, sc, rot, legs, wing):
|
||||
"""A winged horse, side on, facing right. legs: 0..1 through a gallop (or None: tucked in flight);
|
||||
wing: -1 = raised high, 1 = swept down."""
|
||||
s = []
|
||||
|
||||
def at(pts):
|
||||
return tf(pts, x, y, sc, rot)
|
||||
s.append(K("blue")) # the far wing, behind
|
||||
wa = -1.9 + wing * 0.9
|
||||
s.append(P(at([(0.1, -0.4), (-0.3, -0.5), (-0.3 + 2.6 * math.cos(wa - 0.4), -0.5 + 2.6 * math.sin(wa - 0.4)), (0.4 + 1.9 * math.cos(wa - 0.2), -0.4 + 1.9 * math.sin(wa - 0.2))])))
|
||||
s.append(K("yellow"))
|
||||
if legs is None:
|
||||
poses = [((0.85, 0.35), (1.5, 0.6), (1.7, 1.0)), ((0.6, 0.35), (1.1, 0.75), (1.5, 0.9)),
|
||||
((-0.85, 0.35), (-1.6, 0.6), (-2.1, 0.8)), ((-0.6, 0.35), (-1.3, 0.8), (-1.8, 1.1))]
|
||||
else:
|
||||
ph = legs * 2 * math.pi
|
||||
poses = []
|
||||
for k, (hx, off) in enumerate(((0.85, 0.0), (0.6, 0.5), (-0.85, 2.0), (-0.6, 2.5))):
|
||||
a = 0.6 * math.sin(ph + off)
|
||||
kx, ky = hx + 0.75 * math.sin(a), 0.35 + 0.75 * math.cos(a)
|
||||
b = a + (0.7 if hx > 0 else -0.5) * max(0.0, math.sin(ph + off + 1.0))
|
||||
poses.append(((hx, 0.35), (kx, ky), (kx + 0.75 * math.sin(b) * (1 if hx > 0 else 1), ky + 0.75 * math.cos(b))))
|
||||
for p0, p1, p2 in poses:
|
||||
s.append(L(at([p0, p1, p2]), 0.2))
|
||||
s.append(P(at(ring(0, 0, 1.0, 14, 0, 0.03)))) # body (squashed below)
|
||||
s.append(P(at([(-1.15, -0.25), (1.15, -0.35), (1.25, 0.15), (0.6, 0.55), (-0.7, 0.55), (-1.25, 0.15)])))
|
||||
s.append(P(at([(0.65, -0.45), (1.25, -0.15), (1.95, -1.25), (1.45, -1.55)]))) # neck
|
||||
s.append(P(at([(1.4, -1.55), (1.8, -1.75), (2.65, -1.15), (2.55, -0.9), (2.0, -0.95), (1.6, -1.0)]))) # head
|
||||
s.append(P(at([(1.55, -1.6), (1.6, -2.0), (1.8, -1.68)]))) # ear
|
||||
s.append(K("red"))
|
||||
s.append(L(at([(1.5, -1.65), (1.2, -1.3), (1.15, -0.9), (0.85, -0.6), (0.7, -0.35)]), 0.16)) # mane
|
||||
s.append(L(at([(-1.15, -0.15), (-1.7, -0.25), (-2.1, 0.15), (-2.3, 0.65)]), 0.2)) # tail
|
||||
s.append(C(*at([(2.05, -1.35)])[0], 0.07 * sc))
|
||||
s.append(K("blue")) # the near wing, in front
|
||||
s.append(P(at([(0.3, -0.35), (-0.4, -0.35), (-0.5 + 2.9 * math.cos(wa), -0.4 + 2.9 * math.sin(wa)),
|
||||
(-0.1 + 2.5 * math.cos(wa + 0.15), -0.4 + 2.5 * math.sin(wa + 0.15)),
|
||||
(0.2 + 2.0 * math.cos(wa + 0.3), -0.35 + 2.0 * math.sin(wa + 0.3))])))
|
||||
return s
|
||||
|
||||
|
||||
def pegasus(i, t):
|
||||
"""A winged horse gallops up to the box, leaps, and soars in a great arc over it, leaving a trail of stars around the number that blazes up inside the arc."""
|
||||
s = []
|
||||
ncx, ncy, rr = 1.0, -3.6, 4.1 # the number, and the arc round it
|
||||
if i < 7:
|
||||
x, y = -4.6 + i * 0.45, -2.0 + (0.25 if i == 6 else 0.0)
|
||||
rot, legs, wing = 0.0, (i % 4) / 4, 0.6 if i % 2 else 0.2
|
||||
if i == 6:
|
||||
rot = -0.2
|
||||
else:
|
||||
u = min(1.0, (i - 7) / 10)
|
||||
a = math.pi - 0.08 + u * (math.pi - 0.38)
|
||||
x, y = ncx + rr * math.cos(a), ncy + rr * math.sin(a)
|
||||
rot = max(-0.95, min(0.55, a + math.pi / 2 - 2 * math.pi))
|
||||
legs, wing = None, [-1.0, 0.0, 1.0][i % 3]
|
||||
if i >= 18:
|
||||
rot, wing = -0.45 + 0.05 * math.sin(i), [-1.0, -0.2, 0.8, -0.2][i % 4]
|
||||
legs = None
|
||||
trail = []
|
||||
for k in range(1, 12): # the trail of stars behind it
|
||||
uu = u - k * 0.08
|
||||
if uu < 0:
|
||||
break
|
||||
aa = math.pi - 0.08 + uu * (math.pi - 0.38)
|
||||
trail.append((ncx + (rr - 0.3) * math.cos(aa), ncy + (rr - 0.3) * math.sin(aa) + 0.3, k))
|
||||
for tx, ty, k in trail:
|
||||
s.append(K("red" if k % 2 else "blue"))
|
||||
r = 0.3 if (k + i) % 3 else 0.42
|
||||
s.append(P(star(tx, ty, r, r * 0.4, 5, i * 0.3 + k)))
|
||||
if i >= 12:
|
||||
g = pop_scale(t, 12 / 23, 0.12, 1.3)
|
||||
s.append(K("red"))
|
||||
s.append(NUM(ncx, ncy, 2.15 * g, w=0.4, rot=0.05 * math.sin(i * 0.8)))
|
||||
if i in (12, 13, 14):
|
||||
s.append(K("yellow"))
|
||||
s += rays(ncx, ncy, 2.7, 3.2, 12, i * 0.2, 0.09)
|
||||
if i < 7 and i >= 1: # hoof dust
|
||||
s.append(K("red"))
|
||||
s.append(C(x - 1.8, -0.7 - 0.1 * (i % 2), 0.2 + 0.05 * (i % 3), 0.06))
|
||||
s += horse(x, y, 0.95, rot, legs, wing)
|
||||
return s
|
||||
|
||||
|
||||
# ── 6. waterfall ──
|
||||
|
||||
def waterfall(i, t):
|
||||
"""A mighty waterfall thunders down a gorge over the box; the falling water splits apart at the lip and the number shines out of the glowing cave behind it."""
|
||||
s = []
|
||||
top, gy = -7.4, -0.55
|
||||
x0, x1 = -2.6, 4.6
|
||||
cx = (x0 + x1) / 2
|
||||
fall = min(1.0, (i + 1) / 5)
|
||||
yb = top + (gy - top) * fall
|
||||
part = 0.0 if i < 10 else ease_out(min(1.0, (i - 9) / 4))
|
||||
if i >= 4:
|
||||
s.append(K("yellow")) # the cave behind the water
|
||||
s.append(P([(x0 + 0.5, gy), (x1 - 0.5, gy), (x1 - 0.4, -4.4), (cx + 2.0, -6.2), (cx, -6.7), (cx - 2.0, -6.2),
|
||||
(x0 + 0.4, -4.4)], 0, 0.03))
|
||||
s.append(K("red")) # the gorge's rocky sides
|
||||
s.append(P([(x0 - 2.0, gy), (x0 + 0.15, gy), (x0 + 0.35, -1.6), (x0 - 0.05, -2.9), (x0 + 0.3, -4.3), (x0 - 0.1, -5.6),
|
||||
(x0 + 0.2, top), (x0 - 0.7, top - 0.6), (x0 - 1.5, top - 0.2), (x0 - 1.6, -5.3), (x0 - 2.3, -4.6), (x0 - 2.1, -2.2)]))
|
||||
s.append(P([(x1 - 0.15, gy), (x1 + 2.0, gy), (x1 + 2.2, -2.6), (x1 + 1.7, -3.4), (x1 + 2.0, -5.5), (x1 + 1.2, top - 0.5),
|
||||
(x1 + 0.5, top - 0.1), (x1 - 0.2, top), (x1 + 0.1, -5.0), (x1 - 0.25, -3.5), (x1 + 0.05, -2.1)]))
|
||||
s.append(K("yellow"))
|
||||
for x, y in ((x0 - 1.0, -3.5), (x1 + 1.0, -4.3), (x1 + 0.9, -1.6)): # ledges
|
||||
s.append(L([(x - 0.4, y), (x + 0.3, y + 0.1)], 0.07))
|
||||
s.append(K("blue"))
|
||||
s.append(L([(x0 - 0.4, top - 0.05), (x1 + 0.4, top - 0.05)], 0.32)) # the river's lip
|
||||
n = 10
|
||||
for k in range(n):
|
||||
f = (k + 0.5) / n
|
||||
bx = x0 + (x1 - x0) * f
|
||||
side = -1 if bx < cx else 1
|
||||
edge = x0 + 0.5 if side < 0 else x1 - 0.5 # parted, the water hugs the cliffs
|
||||
dest = edge + (bx - (x0 if side < 0 else x1)) * 0.18 - side * 0.0
|
||||
bx2 = bx + (dest - bx) * part
|
||||
w = (x1 - x0) / n * 0.62 * (1 - 0.55 * part)
|
||||
pts = []
|
||||
for m in range(7):
|
||||
y = top + (yb - top) * m / 6
|
||||
sway = 0.08 * math.sin(i * 2.1 + k * 1.3 + m)
|
||||
pts.append((bx2 + sway, y))
|
||||
poly = [(x - w / 2, y) for x, y in pts] + [(x + w / 2, y) for x, y in pts[::-1]]
|
||||
s.append(P(poly, 0, 0.03))
|
||||
if i >= 3: # the plunge pool, its mist and spray
|
||||
for k in range(7):
|
||||
mx = x0 - 0.2 + k * 1.25
|
||||
r = 0.35 + 0.12 * ((i + k) % 3)
|
||||
s.append(C(mx, gy - 0.2 - 0.1 * ((i + k) % 2), r, 0.08))
|
||||
s.append(L([(x0 - 2.0 + m * 0.55, gy + 0.2 + 0.12 * math.sin(i * 1.4 + m)) for m in range(21)], 0.12))
|
||||
for k in range(6):
|
||||
age = (i * 0.4 + k * 0.35) % 1.4
|
||||
sx = cx + (k - 2.5) * 1.4 + (k - 2.5) * age * 0.5
|
||||
s.append(C(sx, gy - 0.5 - age * 1.3 + age * age * 0.6, 0.1))
|
||||
if i >= 12:
|
||||
g = pop_scale(t, 12 / 23, 0.12, 1.25)
|
||||
s.append(K("red"))
|
||||
s.append(NUM(cx, -3.5, 2.15 * g, w=0.4, rot=0.0))
|
||||
s.append(K("blue"))
|
||||
if i in (12, 13, 14):
|
||||
s += rays(cx, -3.5, 2.7, 3.1, 10, 0.1, 0.08)
|
||||
if i >= 16: # glints in the cave
|
||||
for k in range(2):
|
||||
if (i + k) % 2:
|
||||
s.append(P(star(cx - 1.9 + k * 3.8, -5.4 + k * 0.3, 0.35, 0.1, 4, 0.0)))
|
||||
return s
|
||||
|
||||
|
||||
# ── 7. titan ──
|
||||
|
||||
def titan(i, t):
|
||||
"""The ground splits by the box and boulders fly up out of it, stacking themselves into a stone giant; its eyes kindle, and it heaves the number high over its head in both hands."""
|
||||
s = []
|
||||
gy, cx = -0.55, 1.0
|
||||
crack = min(1.0, (i + 1) / 3)
|
||||
s.append(K("yellow")) # the crack in the ground
|
||||
s.append(L([(cx - 3.0 * crack, gy), (cx - 2.0 * crack, gy - 0.15), (cx - 1.0 * crack, gy + 0.1), (cx, gy - 0.12),
|
||||
(cx + 1.0 * crack, gy + 0.1), (cx + 2.0 * crack, gy - 0.15), (cx + 3.0 * crack, gy)], 0.12))
|
||||
if i < 3:
|
||||
s.append(K("red"))
|
||||
for k in range(4):
|
||||
s.append(C(cx - 1.5 + k, gy - 0.3 - 0.4 * ((i + k) % 2), 0.13))
|
||||
# the giant's blocks: (land frame, polygon)
|
||||
blocks = [
|
||||
(3, [(cx - 1.25, gy), (cx - 0.25, gy), (cx - 0.3, -2.4), (cx - 1.15, -2.4)]), # legs
|
||||
(3, [(cx + 0.25, gy), (cx + 1.25, gy), (cx + 1.15, -2.4), (cx + 0.3, -2.4)]),
|
||||
(4, [(cx - 1.45, -2.3), (cx + 1.45, -2.3), (cx + 1.35, -3.2), (cx - 1.35, -3.2)]), # hips
|
||||
(5, [(cx - 1.4, -3.1), (cx + 1.4, -3.1), (cx + 2.1, -5.5), (cx - 2.1, -5.5)]), # chest
|
||||
(7, [(cx - 0.65, -5.6), (cx + 0.65, -5.6), (cx + 0.75, -6.8), (cx + 0.2, -7.05), (cx - 0.75, -6.8)]), # head
|
||||
]
|
||||
for f, poly in blocks:
|
||||
if i < f - 2:
|
||||
continue
|
||||
if i < f: # flying up out of the crack
|
||||
u = (i - (f - 2) + 1) / 3
|
||||
mx = sum(p[0] for p in poly) / len(poly)
|
||||
my = sum(p[1] for p in poly) / len(poly)
|
||||
sx, sy = cx + (mx - cx) * u, gy + (my - gy) * u + 1.2 * (1 - u)
|
||||
poly = rotate([(sx + (x - mx) * (0.5 + 0.5 * u), sy + (y - my) * (0.5 + 0.5 * u)) for x, y in poly], (1 - u) * 1.5, sx, sy)
|
||||
s.append(K("red"))
|
||||
s.append(P(poly, 0, 0.04))
|
||||
if i == f: # a thud of dust
|
||||
s.append(K("yellow"))
|
||||
mx = sum(p[0] for p in poly) / len(poly)
|
||||
s += rays(mx, max(p[1] for p in poly), 0.3, 0.8, 5, math.pi * 0.1, 0.07)
|
||||
if i >= 5: # glowing seams in its chest
|
||||
s.append(K("yellow"))
|
||||
s.append(L([(cx - 0.9, -4.9), (cx - 0.3, -4.4), (cx + 0.2, -4.7), (cx + 0.9, -4.1)], 0.08))
|
||||
s.append(L([(cx - 0.5, -3.5), (cx, -3.9), (cx + 0.6, -3.6)], 0.07))
|
||||
if i >= 8:
|
||||
# the arms: down at its sides, then heaved up overhead
|
||||
up = 0.0 if i < 10 else min(1.0, (i - 9) / 4)
|
||||
up = ease_out(up)
|
||||
for side in (-1, 1):
|
||||
sx, sy = cx + side * 2.0, -5.3
|
||||
hx = lerp(cx + side * 2.6, cx + side * 2.85, up)
|
||||
hy = lerp(-2.6, -8.6, up)
|
||||
ex, ey = lerp(cx + side * 2.9, cx + side * 3.5, up), lerp(-3.9, -6.6, up)
|
||||
s.append(K("red"))
|
||||
s.append(P(tube([(sx, sy), (ex, ey)], 1.0, 0.85)))
|
||||
s.append(P(tube([(ex, ey), (hx, hy)], 0.85, 0.75)))
|
||||
s.append(P(ring(hx, hy, 0.55, 8, side, 0.05)))
|
||||
s.append(C(ex, ey, 0.5))
|
||||
if 8 <= i:
|
||||
s.append(K("yellow")) # its eyes kindle
|
||||
r = 0.17 if (i in (8, 9) or i % 7) else 0.06
|
||||
s.append(C(cx - 0.3, -6.3, r))
|
||||
s.append(C(cx + 0.3, -6.3, r))
|
||||
s.append(L([(cx - 0.35, -5.85), (cx + 0.35, -5.85)], 0.07))
|
||||
if i >= 13:
|
||||
g = pop_scale(t, 13 / 23, 0.1, 1.25)
|
||||
s.append(K("blue"))
|
||||
s.append(NUM(cx, -8.6, 1.95 * g, w=0.38, rot=0.04 * math.sin(i * 0.9)))
|
||||
s.append(K("yellow"))
|
||||
if i in (13, 14, 15):
|
||||
s += rays(cx, -8.6, 2.7, 3.3, 12, 0.1, 0.09)
|
||||
for k in range(4): # grit shaken loose
|
||||
age = i - 13 - k
|
||||
if 0 <= age < 7:
|
||||
side = 1 if k % 2 else -1
|
||||
s.append(C(cx + side * (2.4 + 0.15 * age), -7.6 + age * 0.9 + age * age * 0.08, 0.12))
|
||||
if i in (13, 14): # the ground jolts
|
||||
s.append(K("red"))
|
||||
for side in (-1, 1):
|
||||
s.append(C(cx + side * 2.3, gy - 0.35, 0.3, 0.07))
|
||||
s.append(C(cx + side * 2.9, gy - 0.65, 0.22, 0.07))
|
||||
return s
|
||||
|
||||
|
||||
# ── 8. genie ──
|
||||
|
||||
def genie(i, t):
|
||||
"""A brass lamp by the box jiggles, smoke curls out of its spout and swirls up into a genie, who flings out his arms: in a whirl of sparkles, the number appears, granted."""
|
||||
s = []
|
||||
lx, ly = -2.6, -0.95 # the lamp
|
||||
jig = 0.15 * math.sin(i * 2.4) if i < 4 else 0.0
|
||||
s.append(K("yellow"))
|
||||
lamp = [(-1.0, 0.4), (1.0, 0.4), (1.3, 0.0), (1.9, -0.3), (2.3, -0.35), (2.0, -0.15), (1.1, 0.25 - 0.3), (0.7, -0.3),
|
||||
(-0.7, -0.3), (-1.2, 0.0)]
|
||||
s.append(P(rotate([(lx + x, ly + y) for x, y in lamp], jig, lx, ly + 0.4)))
|
||||
s.append(P(rotate([(lx - 0.35, ly - 0.3), (lx + 0.35, ly - 0.3), (lx + 0.15, ly - 0.6), (lx - 0.15, ly - 0.6)], jig, lx, ly + 0.4)))
|
||||
s.append(L(rotate([(lx - 1.1, ly - 0.05), (lx - 1.6, ly - 0.15), (lx - 1.55, ly + 0.3), (lx - 1.0, ly + 0.25)], jig, lx, ly + 0.4), 0.1))
|
||||
s.append(K("red"))
|
||||
s.append(C(*rotate([(lx, ly - 0.7)], jig, lx, ly + 0.4)[0], 0.13))
|
||||
sx, sy = rotate([(lx + 2.3, ly - 0.4)], jig, lx, ly + 0.4)[0] # the spout's tip
|
||||
if i < 4: # rubbed: glints
|
||||
s.append(K("red"))
|
||||
s.append(P(star(lx - 0.5 + i * 0.4, ly - 0.9 - (i % 2) * 0.3, 0.35, 0.1, 4, 0.0)))
|
||||
gx, gw = -0.4, -3.9 # the genie's waist
|
||||
path = [(sx, sy), (sx + 0.6, sy - 0.5), (sx + 0.7, sy - 1.2), (sx + 0.1, sy - 1.6), (gx - 0.3, gw + 0.9), (gx, gw + 0.3), (gx, gw)]
|
||||
if i >= 3:
|
||||
nshow = min(len(path), 2 + (i - 3))
|
||||
s.append(K("blue"))
|
||||
s.append(P(tube(path[:nshow], 0.25, 0.25 + 0.15 * nshow)))
|
||||
for k in range(min(4, i - 3)): # curls of smoke round the stream
|
||||
px, py = path[min(nshow - 1, k + 1)]
|
||||
s.append(C(px + 0.45 * math.cos(i * 0.9 + k * 2), py + 0.3 * math.sin(i * 0.9 + k * 2), 0.18, 0.06))
|
||||
if i < 8:
|
||||
return s
|
||||
g = min(1.0, 0.35 + (i - 8) * 0.22)
|
||||
if g > 1.0:
|
||||
g = 1.0
|
||||
|
||||
def at(pts):
|
||||
return [(gx + x * g, gw + y * g) for x, y in pts]
|
||||
s.append(K("blue"))
|
||||
s.append(P(at([(-0.6, 0.2), (0.6, 0.2), (1.3, -1.9), (0.7, -2.2), (-0.7, -2.2), (-1.3, -1.9)]))) # torso
|
||||
s.append(P(at(ring(0, -2.85, 0.6, 12, 0, 0.03)))) # head
|
||||
s.append(K("red"))
|
||||
s.append(P(at([(-0.65, -3.0), (0.65, -3.0), (0.55, -3.55), (0.0, -3.75), (-0.55, -3.55)]))) # turban
|
||||
s.append(P(at(star(0, -3.75, 0.25, 0.1, 5))))
|
||||
s.append(P(at([(-0.2, -2.55), (0.2, -2.55), (0.0, -2.05)]))) # beard
|
||||
s.append(K("yellow"))
|
||||
s.append(C(*at([(-0.2, -2.95)])[0], 0.07))
|
||||
s.append(C(*at([(0.2, -2.95)])[0], 0.07))
|
||||
s.append(P(at([(-0.95, -1.95), (0.95, -1.95), (0.85, -1.65), (-0.85, -1.65)]))) # the vest's edge
|
||||
s.append(K("blue"))
|
||||
if i < 13: # arms folded
|
||||
s.append(P(at([(-1.1, -1.5), (1.1, -1.5), (1.05, -1.0), (-1.05, -1.0)])))
|
||||
else: # flung out wide
|
||||
for side in (-1, 1):
|
||||
hx, hy = side * 2.4, -3.4 + (0.3 if side > 0 else 0.0)
|
||||
s.append(P(at(tube([(side * 1.0, -1.9), (side * 1.8, -2.4), (hx, hy)], 0.5, 0.4))))
|
||||
s.append(P(at(ring(hx, hy - 0.1, 0.3, 7, side, 0.03))))
|
||||
if i >= 13: # the number, granted
|
||||
ncx, ncy = 3.65, -4.9
|
||||
u = min(1.0, (i - 13) / 5)
|
||||
gg = pop_scale(t, 13 / 23, 0.2, 1.2)
|
||||
s.append(K("red"))
|
||||
s.append(NUM(ncx, ncy, 2.1 * gg, w=0.4, rot=(1 - ease_out(u)) * -2 * math.pi))
|
||||
s.append(K("yellow"))
|
||||
for k in range(9): # the whirl of sparkles
|
||||
a = k * 2 * math.pi / 9 + i * 0.55
|
||||
r = 3.6 - 1.0 * u + 0.25 * math.sin(i + k)
|
||||
sz = 0.3 if (k + i) % 3 else 0.45
|
||||
s.append(P(star(ncx + r * math.cos(a), ncy + r * 0.62 * math.sin(a), sz, sz * 0.35, 4, a)))
|
||||
if i in (13, 14):
|
||||
s.append(K("blue"))
|
||||
for k in range(5):
|
||||
s.append(C(ncx - 1.5 + k * 0.75, ncy + 1.4 - (k % 2) * 0.4, 0.4, 0.07))
|
||||
return s
|
||||
|
||||
|
||||
ANIMS = [
|
||||
(phoenix, "red", "ignite"), (clocktower, "blue", "toll"),
|
||||
(archway, "red", "keystone"), (glacier, "blue", "calving"),
|
||||
(pegasus, "yellow", "gallop"), (waterfall, "blue", "cascade"),
|
||||
(titan, "red", "quake"), (genie, "blue", "wisp"),
|
||||
]
|
||||
@@ -0,0 +1,155 @@
|
||||
"""Streak level 7's sounds: 2 s each, one per animation in level7.py (same names as its ANIMS).
|
||||
|
||||
Each fn() returns a buf from tools/sound_kit.py; gen_sounds.py normalises and writes it as
|
||||
<name>.wav. Every random source is seeded (level 7: 2700-2799) so the output never changes.
|
||||
"""
|
||||
import math
|
||||
import random
|
||||
|
||||
from sound_kit import SR, TAU, add_noise, add_pluck, add_tone, bell, sbuf
|
||||
|
||||
|
||||
def ignite():
|
||||
"""Embers ticking, a great WHOOMPH of flame, a soaring bird's cry over the roar, and a shimmering chord."""
|
||||
b = sbuf()
|
||||
rng = random.Random(2700)
|
||||
for k in range(10): # embers
|
||||
add_noise(b, 0.02 + k * 0.045 + rng.uniform(0, 0.02), 0.012, 0.2, a=0.0005, d=0.004, lp0=0.95, seed=2701 + k)
|
||||
add_noise(b, 0.3, 0.3, 0.3, a=0.25, d=0.2, lp0=0.05, lp1=0.4, seed=2711) # the flames rise
|
||||
add_noise(b, 0.55, 1.45, 0.75, a=0.01, d=0.5, lp0=0.4, lp1=0.1, seed=2712) # WHOOMPH
|
||||
add_tone(b, 0.55, 0.5, 70, 40, 0.6, a=0.005, d=0.2)
|
||||
add_tone(b, 0.68, 0.7, 900, 1800, 0.18, a=0.06, d=0.6, vib=(9, 0.03)) # the cry, soaring
|
||||
add_tone(b, 0.68, 0.7, 1800, 3600, 0.05, a=0.06, d=0.5, vib=(9, 0.03))
|
||||
for k, f in enumerate((587, 740, 880, 1175)): # the shimmer
|
||||
bell(b, 1.05 + k * 0.06, f, 0.16, 0.7)
|
||||
add_tone(b, 1.05, 0.95, 1760, amp=0.04, a=0.2, d=0.6, vib=(7, 0.012))
|
||||
return b
|
||||
|
||||
|
||||
def toll():
|
||||
"""Clockwork whirring faster and faster, a click as the hands stop, then a great deep bell tolls twice."""
|
||||
b = sbuf()
|
||||
st, gap = 0.12, 0.09
|
||||
while st < 1.04: # the hands racing
|
||||
add_tone(b, st, 0.02, 3200, amp=0.12, a=0.0005, d=0.005, shape="square")
|
||||
add_noise(b, st, 0.015, 0.1, a=0.0005, d=0.004, lp0=0.9, seed=int(st * 1000) % 50 + 2720)
|
||||
st += gap
|
||||
gap = max(0.028, gap * 0.9)
|
||||
add_tone(b, 1.08, 0.04, 1500, 900, 0.4, a=0.0005, d=0.01) # click: stopped
|
||||
for st, f, a in ((1.17, 196, 0.5), (1.58, 196, 0.32)): # BONG ... BONG
|
||||
for ratio, amp, d in ((0.5, 0.6, 1.2), (1, 1.0, 0.9), (1.19, 0.45, 0.7), (1.5, 0.3, 0.6), (2.0, 0.35, 0.5), (2.74, 0.2, 0.35)):
|
||||
add_tone(b, st, 2.0 - st, f * ratio, amp=a * amp, a=0.003, d=d)
|
||||
add_noise(b, st, 0.05, 0.2 * a, a=0.0005, d=0.01, lp0=0.5, seed=2780 + int(st * 10))
|
||||
return b
|
||||
|
||||
|
||||
def keystone():
|
||||
"""Stones clacking into place, pair by pair and rising in pitch, the keystone's huge thud, and a swelling brass chord."""
|
||||
b = sbuf()
|
||||
for k, st in enumerate((0.25, 0.42, 0.58, 0.75)):
|
||||
for d in (0.0, 0.03):
|
||||
add_tone(b, st + d, 0.08, 500 + k * 90, 300 + k * 60, 0.3, a=0.001, d=0.025)
|
||||
add_noise(b, st + d, 0.05, 0.25, a=0.001, d=0.012, lp0=0.6, seed=2730 + k * 2 + int(d * 100))
|
||||
add_noise(b, 0.85, 0.15, 0.2, a=0.1, d=0.05, lp0=0.3, lp1=0.6, seed=2740) # it whistles down
|
||||
add_tone(b, 1.0, 0.4, 85, 38, 0.9, a=0.001, d=0.13) # the keystone: THUD
|
||||
add_noise(b, 1.0, 0.35, 0.7, a=0.001, d=0.07, lp0=0.25, lp1=0.04, seed=2741)
|
||||
for f in (262, 330, 392, 523): # the glory chord
|
||||
add_tone(b, 1.12, 0.88, f, amp=0.09, a=0.15, d=0.9, shape="saw", vib=(5, 0.005))
|
||||
return b
|
||||
|
||||
|
||||
def calving():
|
||||
"""Ice cracking like gunshots, a long groan, a colossal splash, then glassy chimes as the iceberg bobs up."""
|
||||
b = sbuf()
|
||||
for k, st in enumerate((0.08, 0.22, 0.31, 0.47, 0.55)): # cracks
|
||||
add_noise(b, st, 0.05, 0.6, a=0.0005, d=0.01, lp0=0.95, seed=2750 + k)
|
||||
add_tone(b, st, 0.04, 1200, 400, 0.2, a=0.0005, d=0.012)
|
||||
add_tone(b, 0.4, 0.5, 90, 55, 0.25, a=0.1, d=0.4, shape="saw", vib=(6, 0.05)) # the groan
|
||||
add_noise(b, 0.85, 1.15, 0.9, a=0.008, d=0.35, lp0=0.55, lp1=0.06, seed=2756) # the splash
|
||||
add_tone(b, 0.85, 0.5, 60, 32, 0.6, a=0.003, d=0.2)
|
||||
rng = random.Random(2757)
|
||||
for k in range(14): # falling spray
|
||||
st = 1.0 + k * 0.03 + rng.uniform(0, 0.02)
|
||||
add_noise(b, st, 0.02, 0.15, a=0.001, d=0.006, lp0=0.8, seed=2760 + k)
|
||||
for k, f in enumerate((2093, 2637, 3136, 2349)): # glassy ice chimes
|
||||
bell(b, 1.2 + k * 0.13, f, 0.14, 0.4)
|
||||
return b
|
||||
|
||||
|
||||
def gallop():
|
||||
"""Galloping hooves, a leap, great wingbeats and a whinny, then a long glittering run of stars."""
|
||||
b = sbuf()
|
||||
for k in range(3): # ba-da-dum, ba-da-dum
|
||||
for d in (0.0, 0.06, 0.12):
|
||||
st = 0.03 + k * 0.19 + d
|
||||
add_tone(b, st, 0.06, 240 - d * 400, 130, 0.35, a=0.001, d=0.02)
|
||||
add_noise(b, st, 0.03, 0.25, a=0.001, d=0.008, lp0=0.4, seed=2765 + k)
|
||||
add_noise(b, 0.58, 0.3, 0.35, a=0.1, d=0.1, lp0=0.1, lp1=0.5, seed=2768) # the leap
|
||||
for k in range(3): # wingbeats
|
||||
add_noise(b, 0.7 + k * 0.25, 0.15, 0.4, a=0.03, d=0.05, lp0=0.08, seed=2769 + k)
|
||||
add_tone(b, 0.75, 0.55, 900, 500, 0.15, a=0.03, d=0.35, shape="saw", vib=(14, 0.06)) # the whinny
|
||||
add_tone(b, 0.75, 0.55, 1350, 750, 0.05, a=0.03, d=0.3, vib=(14, 0.06))
|
||||
scale = (784, 880, 988, 1175, 1319, 1568, 1760, 1976, 2349, 2637)
|
||||
for k, f in enumerate(scale): # stars
|
||||
bell(b, 1.0 + k * 0.06, f, 0.12, 0.35)
|
||||
return b
|
||||
|
||||
|
||||
def cascade():
|
||||
"""The thunder of falling water swelling up, a harp sweep as the curtain parts, and a bright chord ringing out."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 2.0, 0.6, a=0.35, d=1.2, lp0=0.3, lp1=0.45, seed=2780) # the roar
|
||||
add_noise(b, 0.0, 2.0, 0.25, a=0.3, d=1.2, lp0=0.04, seed=2781)
|
||||
rng = random.Random(2782)
|
||||
for k in range(18): # droplets
|
||||
f = rng.uniform(700, 1600)
|
||||
add_tone(b, 0.25 + k * 0.08 + rng.uniform(0, 0.04), 0.04, f, f * 1.5, 0.06, a=0.002, d=0.015)
|
||||
harp = (196, 247, 294, 392, 494, 587, 784, 988, 1175)
|
||||
for k, f in enumerate(harp): # the curtain parts
|
||||
add_pluck(b, 0.82 + k * 0.035, f, dur=1.1, amp=0.25, seed=2783 + k, damp=0.997)
|
||||
for f in (392, 494, 587, 784): # and it shines
|
||||
bell(b, 1.12, f, 0.13, 0.7)
|
||||
return b
|
||||
|
||||
|
||||
def quake():
|
||||
"""A deep rumble, boulders thudding together one by one, a grinding heave, then an enormous boom and a low triumphant horn."""
|
||||
b = sbuf()
|
||||
add_noise(b, 0.0, 1.2, 0.5, a=0.15, d=0.8, lp0=0.03, seed=2785) # the rumble
|
||||
add_tone(b, 0.0, 1.0, 40, 33, 0.4, a=0.15, d=0.7)
|
||||
for k, st in enumerate((0.25, 0.33, 0.42, 0.58)): # blocks landing
|
||||
add_tone(b, st, 0.15, 110 - k * 8, 50, 0.55, a=0.001, d=0.05)
|
||||
add_noise(b, st, 0.1, 0.4, a=0.001, d=0.025, lp0=0.25, seed=2786 + k)
|
||||
add_tone(b, 0.8, 0.3, 70, 110, 0.15, a=0.05, d=0.2, shape="saw", vib=(18, 0.08)) # the heave
|
||||
add_noise(b, 1.08, 0.92, 0.9, a=0.002, d=0.25, lp0=0.4, lp1=0.03, seed=2790) # BOOM
|
||||
add_tone(b, 1.08, 0.6, 60, 28, 0.9, a=0.002, d=0.25)
|
||||
for f, a in ((110, 0.22), (165, 0.14), (220, 0.1)): # the horn
|
||||
add_tone(b, 1.2, 0.8, f, amp=a, a=0.08, d=0.8, shape="saw", vib=(4, 0.006))
|
||||
return b
|
||||
|
||||
|
||||
def wisp():
|
||||
"""Three quick rubs on brass, a swirling whoosh of smoke, and a twinkling, exotic run of bells as the wish is granted."""
|
||||
b = sbuf()
|
||||
for k in range(3): # rub, rub, rub
|
||||
add_tone(b, 0.05 + k * 0.1, 0.07, 1400, 1700, 0.12, a=0.01, d=0.03, shape="tri")
|
||||
add_noise(b, 0.05 + k * 0.1, 0.07, 0.12, a=0.01, d=0.03, lp0=0.8, seed=2792 + k)
|
||||
ph = 0.0
|
||||
rng = random.Random(2795)
|
||||
y = 0.0
|
||||
for k in range(int(SR * 0.85)): # the swirl of smoke
|
||||
t = k / SR
|
||||
c = 0.06 + 0.25 * (0.5 + 0.5 * math.sin(TAU * 4 * t))
|
||||
y += c * (rng.uniform(-1, 1) - y)
|
||||
loud = min(1.0, t / 0.25) * min(1.0, (0.85 - t) / 0.2)
|
||||
b[int(0.3 * SR) + k] += y * 0.6 * loud
|
||||
ph += TAU * (300 + 500 * t / 0.85) / SR
|
||||
b[int(0.3 * SR) + k] += math.sin(ph) * 0.06 * loud
|
||||
run = (587, 622, 740, 784, 880, 932, 1109, 1175, 1480) # a hijaz-ish run
|
||||
for k, f in enumerate(run):
|
||||
bell(b, 1.08 + k * 0.05, f, 0.15, 0.4)
|
||||
add_tone(b, 1.08, 0.9, 2349, amp=0.05, a=0.1, d=0.5, vib=(8, 0.015))
|
||||
return b
|
||||
|
||||
|
||||
SOUNDS = [ignite, toll, keystone, calving, gallop, cascade, quake, wisp]
|
||||
Reference in New Issue
Block a user