A drawing app built for agent/human collaboration
Rust
The courier and the ruin become samples; the courier's idle and run in the README
Indicode BV2242bb91dcab
diff --git a/README.md b/README.mdindex 570b108..93bc573 100644--- a/README.md+++ b/README.md@@ -24,6 +24,16 @@ klad arcs creature.draw --track 'lines:near leg' --clip walk --checkklad export creature.draw --godot ../game/art```+ ++The courier in `samples/courier` is drawn from shapes on every frame: a pose function places the body, legs and lantern, and the CLI fills, lights and inks them on thirteen layers. Its 16 drawings play as an idle and a run at 12 frames a second and export to Godot with that timing.++```sh+klad fill courier.draw flats --shape shell-4 --color shell --frame 4+klad light courier.draw --from shell-4 --light -0.6,-0.8 --shade shade --rim rim --frame 4+klad ink courier.draw lines --from shell-4,head-4,near-leg-4 --weight 5 --frame 4+```+## StatusEarly, and open for testing. What works today:@@ -41,7 +51,7 @@ There are no downloads yet; build it from source (about ten minutes the first ti1. Install Rust with [rustup](https://rustup.rs) and [`just`](https://github.com/casey/just) (`brew install just`, or `cargo install just`). On Linux also `pkg-config`, `libfreetype-dev` and `libfontconfig1-dev`.2. `git clone https://github.com/klad-app/klad && cd klad`, then `just build` makes the `klad` binary in `target/release/` (on Linux in `target/linux/release/`).3. On a Mac, `target/release/klad open` starts the editor on its start window: make a drawing and start painting.-4. `just samples` builds the sample drawings in `samples/` (a lantern, a walking creature, painted solids, a bowl of lemons, a bouncing ball, ink examples); open one with `target/release/klad open samples/lantern/lantern.draw`.+4. `just samples` builds the sample drawings in `samples/` (a lantern, a walking creature, a running courier, an underground ruin, painted solids, a bowl of lemons, a bouncing ball, ink examples); open one with `target/release/klad open samples/lantern/lantern.draw`.## Drawing with an agentdiff --git a/docs/images/courier-idle.gif b/docs/images/courier-idle.gifnew file mode 100644index 0000000..0d7eca0Binary files /dev/null and b/docs/images/courier-idle.gif differdiff --git a/docs/images/courier-run.gif b/docs/images/courier-run.gifnew file mode 100644index 0000000..4e7dac1Binary files /dev/null and b/docs/images/courier-run.gif differdiff --git a/justfile b/justfileindex 560d11a..a679326 100644--- a/justfile+++ b/justfile@@ -19,7 +19,7 @@ lint:cargo clippy --workspace --all-targets -- -D warningssamples: build- for s in lantern ink-shapes bounce creature solids lemons; do FORCE=1 bash samples/$s/build.sh >/dev/null && echo "samples/$s/$s.draw"; done+ for s in lantern ink-shapes bounce creature courier solids lemons ruin; do FORCE=1 bash samples/$s/build.sh >/dev/null && echo "samples/$s/$s.draw"; donenotices:bash licenses/notices.shdiff --git a/samples/README.md b/samples/README.mdindex d04eb77..cc8c5a9 100644--- a/samples/README.md+++ b/samples/README.md@@ -8,6 +8,8 @@ Drawings made from scratch with the `klad` CLI, each from a generator that print| `ink-shapes` | The ink options side by side: weight from the light, breaks, gaps, wobble, tapers || `bounce` | Frame-by-frame timing: keys, holds, a clip and the exports || `creature` | A walk and an idle from keys with named parts, in-betweened, coloured from the first drawing, with arcs checked |+| `courier` | A game character drawn from shapes on every frame: a pose function moves the body, legs and lantern, then fill, light and ink make the drawing; an idle and a run as clips, exported to Godot |+| `ruin` | A game background lit by one lantern: stone blocks with chalk and dry-brush tool marks, relief per pillar facing the lamp, depth planes in fog, glow || `lemons` | Painting by form with `klad paint` on locked flats, and a shadow colour: lavender shadows instead of brown ones (`PLAIN=1`: without it; `RELIEF=1`: with a relief effect on every object, lighting the thickness of the oil strokes) || `solids` | Painting stroke by stroke: a sphere, a cube and a cylinder built in 3D with `docs/skill/drawkit.py`, lit, painted with natural strokes |diff --git a/samples/courier/build.sh b/samples/courier/build.shnew file mode 100755index 0000000..affc19d--- /dev/null+++ b/samples/courier/build.sh@@ -0,0 +1,25 @@+#!/usr/bin/env bash+set -euo pipefail+here="$(cd "$(dirname "$0")" && pwd)"+root="$(cd "$here/../.." && pwd)"+case "$(uname -s)" in+ Darwin) built=target ;;+ Linux) built=target/linux ;;+ *) built=target/windows ;;+esac+klad="${KLAD:-$root/${KLAD_TARGET_DIR:-$built}/release/klad}"+out="${1:-$here/courier.draw}"+if [ -e "$out" ] && [ "${FORCE:-0}" != 1 ]; then+ echo "$out exists and may hold edits made in the editor; give another path, or FORCE=1 to rebuild it from generate.py" >&2+ exit 1+fi+rm -rf "$out"+"$klad" new "$out" --width 640 --height 560 --layers 0 --fps 12 --frames 16 >/dev/null+python3 "$here/generate.py" | "$klad" apply "$out" >/dev/null+"$klad" clip "$out" --add idle --from 0 --to 7 --loop >/dev/null+"$klad" clip "$out" --add run --from 8 --to 15 --loop >/dev/null+"$klad" timeline "$out" --origin 300,500 >/dev/null+"$klad" render "$out" --sheet idle --drawings --cell 280 -o "${out%.draw}-idle.png"+"$klad" render "$out" --sheet run --drawings --cell 280 -o "${out%.draw}-run.png"+"$klad" hash "$out" --all --no-cache+"$klad" export "$out" --godot "${out%.draw}-godot" >/dev/nulldiff --git a/samples/courier/generate.py b/samples/courier/generate.pynew file mode 100644index 0000000..d8ce0a7--- /dev/null+++ b/samples/courier/generate.py@@ -0,0 +1,255 @@+import json+import math++W, H = 640, 560+GROUND = 500.0+IDLE, RUN = 8, 8+LIGHT = [-0.6, -0.8]+COLOURS = {"ink": "#121319", "shell": "#33405a", "shell far": "#232b3c", "belly": "#5c6a80", "face": "#a9b4c2",+ "eye": "#ffb24a", "iron": "#262c38", "glow": "#ffd27a", "shade": "#2a2f4a", "rim": "#cfe0f0",+ "warm rim": "#ffbf6a", "ground": "#8c86a8"}+++def lerp(a, b, t):+ return a + (b - a) * t+++def pose(frame):+ if frame < IDLE:+ t = frame / IDLE+ breath = math.sin(2 * math.pi * t)+ return {"x": 300, "y": 388 + 3 * breath, "lean": 0.0, "sx": 1 + 0.015 * breath, "sy": 1 - 0.02 * breath,+ "antenna": 4 * math.sin(2 * math.pi * t + 1.0), "swing": 6 * math.sin(2 * math.pi * t - 0.9) + 4,+ "near": (312, GROUND), "far": (291, GROUND - 2), "lift": (0, 0), "blink": 1.0 if frame == 5 else 0.0,+ "run": 0.0, "t": t}+ t = (frame - IDLE) / RUN+ bob = 8 * math.cos(4 * math.pi * t)++ def foot(phase):+ p = phase % 1.0+ if p < 0.5:+ u = p / 0.5+ return (300 + lerp(46, -50, u), GROUND), 0.0+ u = (p - 0.5) / 0.5+ return (300 + lerp(-50, 46, u * u * (3 - 2 * u)), GROUND - 34 * math.sin(math.pi * u) ** 0.8), math.sin(math.pi * u)++ near, near_lift = foot(t)+ far, far_lift = foot(t + 0.5)+ return {"x": 306, "y": 380 + bob, "lean": -9 + 2.5 * math.sin(4 * math.pi * t), "sx": 1 + 0.03 * math.cos(4 * math.pi * t),+ "sy": 1 - 0.035 * math.cos(4 * math.pi * t), "antenna": -22 + 9 * math.sin(4 * math.pi * t - 1.2),+ "swing": 24 + 16 * math.sin(2 * math.pi * t - 1.4), "near": near, "far": far, "lift": (near_lift, far_lift),+ "blink": 0.0, "run": 1.0, "t": t}+++def body(p):+ a = math.radians(p["lean"])+ ca, sa = math.cos(a), math.sin(a)++ def world(u, v):+ x, y = u * p["sx"], v * p["sy"]+ return (p["x"] + x * ca - y * sa, p["y"] + x * sa + y * ca)++ return world+++def top(u):+ k = min(1.0, abs(u) / 112)+ return -96 * (1 - k ** 2.6) ** (1 / 2.6) - 6 * (u / 112)+++def bottom(u):+ return 34 * (1 - (u / 112) ** 2)+++def path(points, closed=True):+ d = "M" + " L".join(f"{x:.1f} {y:.1f}" for x, y in points)+ return d + (" Z" if closed else "")+++def shell(world):+ us = [-112 + 224 * i / 48 for i in range(49)]+ return [world(u, top(u)) for u in us] + [world(u, bottom(u)) for u in reversed(us)]+++def belly(world):+ us = [-104 + 208 * i / 32 for i in range(33)]+ return [world(u, bottom(u) - 15 * (1 - (u / 112) ** 2) ** 0.5) for u in us] + [world(u, bottom(u)) for u in reversed(us)]+++def ellipse(world, cx, cy, rx, ry, turn=0.0, steps=36):+ a = math.radians(turn)+ return [world(cx + rx * math.cos(s) * math.cos(a) - ry * math.sin(s) * math.sin(a),+ cy + rx * math.cos(s) * math.sin(a) + ry * math.sin(s) * math.cos(a))+ for s in [2 * math.pi * i / steps for i in range(steps)]]+++def ik(hip, foot, upper, lower):+ dx, dy = foot[0] - hip[0], foot[1] - hip[1]+ d = min(math.hypot(dx, dy), upper + lower - 0.5)+ base = math.atan2(dy, dx)+ bend = math.acos(max(-1, min(1, (upper * upper + d * d - lower * lower) / (2 * upper * d))))+ knee_a = base - bend+ return (hip[0] + upper * math.cos(knee_a), hip[1] + upper * math.sin(knee_a))+++def capsule(points, widths):+ left, right = [], []+ for i, (x, y) in enumerate(points):+ a = points[max(0, i - 1)]+ b = points[min(len(points) - 1, i + 1)]+ dx, dy = b[0] - a[0], b[1] - a[1]+ n = math.hypot(dx, dy) or 1+ nx, ny = -dy / n, dx / n+ w = widths[i] / 2+ left.append((x + nx * w, y + ny * w))+ right.append((x - nx * w, y - ny * w))+ return left + list(reversed(right))+++def bezier(a, c, b, steps=12):+ return [((1 - t) ** 2 * a[0] + 2 * (1 - t) * t * c[0] + t * t * b[0], (1 - t) ** 2 * a[1] + 2 * (1 - t) * t * c[1] + t * t * b[1])+ for t in [i / steps for i in range(steps + 1)]]+++def head(world):+ points = []+ for i in range(48):+ a = 2 * math.pi * i / 48+ bump = 0.32 * math.exp(-((math.atan2(math.sin(a - 0.55), math.cos(a - 0.55))) ** 2) / 0.12)+ r = 1 + bump+ points.append(world(106 + 42 * r * math.cos(a), 16 + 34 * r * math.sin(a) * (0.9 if math.sin(a) < 0 else 1)))+ return points+++def leg(world, hip_uv, foot, lift):+ hip = world(*hip_uv)+ ankle = (foot[0], foot[1] - 10)+ knee = ik(hip, ankle, 41, 41)+ thigh = [(lerp(hip[0], knee[0], k), lerp(hip[1], knee[1], k)) for k in [i / 6 for i in range(7)]]+ shin = [(lerp(knee[0], ankle[0], k), lerp(knee[1], ankle[1], k)) for k in [i / 6 for i in range(1, 7)]]+ line = thigh + shin+ widths = [lerp(26, 17, i / 6) for i in range(7)] + [lerp(17, 10, i / 6) for i in range(1, 7)]+ toe = (ankle[0] + 18, foot[1] - 3 - 8 * lift)+ a = math.degrees(math.atan2(toe[1] - ankle[1], toe[0] - ankle[0]))+ return capsule(line, widths), ellipse(lambda u, v: (u, v), (ankle[0] + toe[0]) / 2 + 2, (ankle[1] + toe[1]) / 2 + 2, 17, 8, a, 24)+++def antenna(world, base_uv, angle, length, curl):+ base = world(*base_uv)+ a = math.radians(angle - 50)+ tip = (base[0] + length * math.cos(a), base[1] + length * math.sin(a))+ mid = (lerp(base[0], tip[0], 0.5) - curl * math.sin(a), lerp(base[1], tip[1], 0.5) + curl * math.cos(a))+ return bezier(base, mid, tip, 14), tip+++def shapes(f):+ p = pose(f)+ world = body(p)+ s = {}+ s["shell"] = shell(world)+ s["belly"] = belly(world)+ s["head"] = head(world)+ blink = p["blink"]+ s["eye"] = ellipse(world, 124, 6, 7.5, 7.5 * (1 - 0.85 * blink), 0, 20)+ s["near leg"], s["near foot"] = leg(world, (18, 34), p["near"], p["lift"][0])+ s["far leg"], s["far foot"] = leg(world, (-20, 30), p["far"], p["lift"][1])+ hook_base = world(-52, -86)+ hook = world(-140, -174)+ swing = math.radians(p["swing"])+ hang = (hook[0] + 34 * math.sin(swing), hook[1] + 34 * math.cos(swing))+ turn = -p["swing"] * 0.6+ s["lantern"] = ellipse(lambda u, v: (u, v), hang[0], hang[1] + 6, 20, 25, turn, 30)+ s["window"] = ellipse(lambda u, v: (u, v), hang[0], hang[1] + 8, 11, 15, turn, 24)+ s["cap"] = ellipse(lambda u, v: (u, v), hang[0] - 22 * math.sin(math.radians(turn)), hang[1] - 18, 11, 6, turn, 16)+ lines = {+ "pole": bezier(hook_base, world(-66, -136), world(-82, -178), 10) + bezier(world(-82, -178), world(-100, -206), world(-132, -192), 8)[1:]+ + bezier(world(-132, -192), world(-142, -186), world(-140, -174), 4)[1:],+ "chain": [hook, (lerp(hook[0], hang[0], 0.5), lerp(hook[1], hang[1], 0.5) - 2), (hang[0] - 22 * math.sin(math.radians(turn)), hang[1] - 22)],+ }+ seams, lips = [], []+ for u in (-78, -46, -14, 18, 50, 80):+ line = [world(u - 16 * k * k + 6 * (1 - k), lerp(top(u), bottom(u) - 14, k)) for k in [i / 10 for i in range(11)]]+ seams.append(line)+ lips.append([world(u + 5 - 16 * k * k + 6 * (1 - k), lerp(top(u + 5), bottom(u) - 16, k)) for k in [i / 10 for i in range(8)]])+ near_antenna, near_tip = antenna(world, (122, -12), p["antenna"], 92, -16)+ far_antenna, far_tip = antenna(world, (106, -16), p["antenna"] - 14, 82, -14)+ mouth = [world(150, 40), world(140, 44), world(130, 43)]+ return p, s, lines, (seams, lips), (near_antenna, near_tip, far_antenna, far_tip), mouth, hang+++def layer(id, kind, **extra):+ return {"op": "add", "layer": {"id": id, "kind": kind, "name": id, "cels": [{"id": f"{id.replace(' ', '-')}0", "frame": 0, "hold": 1}], **extra}}+++def node(f, id, points, layer_id="sketch"):+ return {"op": "add", "node": {"id": f"{id.replace(' ', '-')}-{f}", "type": "path", "d": path(points)}, "in": layer_id, "frame": f}+++def sid(f, name):+ return f"{name.replace(' ', '-')}-{f}"+++def frame_ops(f):+ p, s, lines, (seams, lips), ants, mouth, hang = shapes(f)+ out = [node(f, k, v) for k, v in s.items()]+ flats = [("far leg", "shell far", "far"), ("far foot", "shell far", "far"), ("shell", "shell", "flats"), ("belly", "belly", "flats"),+ ("head", "face", "front"), ("eye", "eye", "front"),+ ("near leg", "shell", "flats"), ("near foot", "shell", "flats"),+ ("lantern", "iron", "flats"), ("cap", "iron", "flats"), ("window", "glow", "flats")]+ out += [{"op": "fill", "layer": lay, "shape": sid(f, k), "color": c, "expand": 1.5, "frame": f} for k, c, lay in flats]+ out.append({"op": "light", "from": [sid(f, "shell")], "light": LIGHT, "shade": "shade", "rim": "rim", "depth": 34, "soft": 3,+ "shadeColor": COLOURS["shade"], "rimColor": COLOURS["rim"], "rimWidth": 5, "shadeOpacity": 0.85, "frame": f})+ out.append({"op": "light", "from": [sid(f, "near leg"), sid(f, "belly")], "light": LIGHT, "shade": "shade",+ "rim": "rim", "depth": 12, "soft": 2, "shadeColor": COLOURS["shade"], "rimColor": COLOURS["rim"], "rimWidth": 3,+ "shadeOpacity": 0.7, "frame": f})+ out.append({"op": "light", "from": [sid(f, "head")], "light": LIGHT, "shade": "front-shade", "rim": "front-rim", "depth": 14,+ "soft": 2, "shadeColor": COLOURS["shade"], "rimColor": COLOURS["rim"], "rimWidth": 3, "shadeOpacity": 0.7, "frame": f})+ out.append({"op": "light", "from": [sid(f, "shell")], "lamp": [hang[0], hang[1] + 6, 40], "rim": "rim",+ "rimColor": COLOURS["warm rim"], "rimWidth": 4, "rimOpacity": 0.75, "frame": f})+ ink = lambda **kw: {"op": "ink", "layer": "lines", "light": LIGHT, "color": "ink", "frame": f, **kw}+ out.append(ink(**{"from": [sid(f, "far leg"), sid(f, "far foot")], "weight": 5, "seed": 3 + f}))+ out.append(ink(**{"from": [sid(f, "shell"), sid(f, "near leg"), sid(f, "near foot")], "weight": 7, "seed": 11 + f}))+ out.append(ink(**{"from": [sid(f, "head")], "weight": 7, "seed": 13 + f, "layer": "front-lines"}))+ out.append(ink(**{"from": [sid(f, "eye")], "weight": 3.2, "seed": 17 + f, "layer": "front-lines"}))+ out.append(ink(**{"from": [sid(f, "lantern"), sid(f, "cap")], "weight": 3.2, "seed": 19 + f}))+ out.append(ink(path=path(lines["pole"], False), weight=7, seed=23 + f, taper=[4, 6], **{"break": 170, "wobble": 0.3}))+ out.append(ink(path=path(lines["chain"], False), weight=2.4, seed=29 + f))+ out += [ink(path=path(seam, False), weight=3.6, seed=31 + f + i, taper=[4, 18]) for i, seam in enumerate(seams)]+ out += [{"op": "stroke", "layer": "rim", "frame": f, "brush": "ink", "size": 3.2, "color": "rim", "opacity": 0.45,+ "path": path(lip, False), "pressure": [0.3, 1, 0.6, 0.1], "taper": [6, 24]} for lip in lips]+ near_antenna, near_tip, far_antenna, far_tip = ants+ out.append(ink(path=path(far_antenna, False), weight=4.2, seed=41 + f, taper=[2, 0], wobble=0))+ out.append(ink(path=path(near_antenna, False), weight=5.2, seed=43 + f, taper=[2, 0], wobble=0))+ out.append(ink(path=path(mouth, False), weight=2.2, seed=47 + f, taper=[3, 4], layer="front-lines"))+ out += [{"op": "add", "node": {"type": "ellipse", "cx": round(tip[0], 1), "cy": round(tip[1], 1), "rx": r, "ry": r, "fill": COLOURS["ink"]},+ "in": "tips", "frame": f} for tip, r in ((near_tip, 6), (far_tip, 5))]+ squash = 1 - 0.25 * (GROUND - (p["y"] + 112)) / 40+ out.append({"op": "add", "node": {"type": "ellipse", "cx": round(p["x"] - 6, 1), "cy": GROUND + 3, "rx": round(96 * squash, 1), "ry": 11,+ "fill": "#0b0b1870", "blur": 6}, "in": "ground", "frame": f})+ halo = {"radial": {"center": [round(hang[0], 1), round(hang[1] + 6, 1)], "radius": 150,+ "stops": [[0, "#ffc06a55"], [0.4, "#ff9d4a1c"], [1, "#ff8a3a00"]]}}+ core = {"radial": {"center": [round(hang[0], 1), round(hang[1] + 6, 1)], "radius": 26,+ "stops": [[0, "#fff6dcff"], [0.55, "#ffd27a77"], [1, "#ffb24a00"]]}}+ out.append({"op": "add", "node": {"type": "ellipse", "cx": round(hang[0], 1), "cy": round(hang[1] + 6, 1), "rx": 150, "ry": 150, "fill": halo},+ "in": "halo", "frame": f})+ out.append({"op": "add", "node": {"type": "ellipse", "cx": round(hang[0], 1), "cy": round(hang[1] + 6, 1), "rx": 26, "ry": 26, "fill": core},+ "in": "light", "frame": f})+ return out+++def ops():+ out = [{"op": "palette", "add": c, "name": n} for n, c in COLOURS.items()]+ out += [layer("sketch", "vector", visible=False), layer("ground", "vector"), layer("halo", "vector", blend="screen"),+ layer("far", "paint"), layer("flats", "paint"), layer("shade", "paint", blend="multiply", opacity=0.85, clip=True),+ layer("rim", "paint", clip=True), layer("lines", "paint"), layer("tips", "vector"), layer("front", "paint"),+ layer("front-shade", "paint", blend="multiply", opacity=0.85, clip=True), layer("front-rim", "paint", clip=True),+ layer("front-lines", "paint"), layer("light", "vector", blend="add")]+ names = ["sketch", "ground", "halo", "far", "flats", "shade", "rim", "lines", "tips", "front", "front-shade", "front-rim",+ "front-lines", "light"]+ out += [{"op": "cel", "new": n, "frame": f, "hold": 1, "id": f"{n.replace(' ', '-')}{f}"} for f in range(1, IDLE + RUN) for n in names]+ for f in range(IDLE + RUN):+ out += frame_ops(f)+ return out+++print("\n".join(json.dumps(o) for o in ops()))diff --git a/samples/ruin/build.sh b/samples/ruin/build.shnew file mode 100755index 0000000..717faf3--- /dev/null+++ b/samples/ruin/build.sh@@ -0,0 +1,20 @@+#!/usr/bin/env bash+set -euo pipefail+here="$(cd "$(dirname "$0")" && pwd)"+root="$(cd "$here/../.." && pwd)"+case "$(uname -s)" in+ Darwin) built=target ;;+ Linux) built=target/linux ;;+ *) built=target/windows ;;+esac+klad="${KLAD:-$root/${KLAD_TARGET_DIR:-$built}/release/klad}"+out="${1:-$here/ruin.draw}"+if [ -e "$out" ] && [ "${FORCE:-0}" != 1 ]; then+ echo "$out exists and may hold edits made in the editor; give another path, or FORCE=1 to rebuild it from generate.py" >&2+ exit 1+fi+rm -rf "$out"+"$klad" new "$out" --width 1920 --height 1080 --layers 0 --background '#1c2232' >/dev/null+python3 "$here/generate.py" | "$klad" apply "$out" >/dev/null+"$klad" render "$out" -o "${out%.draw}.png"+"$klad" hash "$out" --no-cache | head -1diff --git a/samples/ruin/generate.py b/samples/ruin/generate.pynew file mode 100644index 0000000..8e9afc9--- /dev/null+++ b/samples/ruin/generate.py@@ -0,0 +1,495 @@+import json+import math+import random++W, H = 1920, 1080+FLOOR = 822.0+LAMP = (1142.0, 438.0)+COLOURS = {+ "deep top": "#161c2c", "deep": "#273148", "far": "#3f4c66", "back": "#1b2232", "stone": "#5b6477",+ "stone dark": "#3a4153", "floor": "#4d5466", "floor front": "#222834", "near": "#090c13", "ink": "#0d1018",+ "root": "#141821", "moss": "#4d6158", "iron": "#22252c", "amber": "#ffbf6e", "key": "#ffc983",+ "fill": "#6276a3", "shadow": "#4c5a86", "mote": "#ffd9a8",+}+++SKETCH_CENTRES = {}+SKETCH_CORNERS = {}+++def noise(seed, octaves=3):+ rnd = random.Random(seed)+ tables = [[rnd.uniform(-1, 1) for _ in range(512)] for _ in range(octaves)]++ def at(t):+ total, amp, norm = 0.0, 1.0, 0.0+ for o in range(octaves):+ x = t * (2 ** o)+ i = math.floor(x)+ f = x - i+ f = f * f * (3 - 2 * f)+ a, b = tables[o][i % 512], tables[o][(i + 1) % 512]+ total += (a + (b - a) * f) * amp+ norm += amp+ amp *= 0.5+ return total / norm++ return at+++def path(points, closed=True):+ d = "M" + " L".join(f"{x:.1f} {y:.1f}" for x, y in points)+ return d + (" Z" if closed else "")+++def layer(id, kind, into=None, **extra):+ op = {"op": "add", "layer": {"id": id, "kind": kind, "name": id, **extra}}+ return {**op, "in": into} if into else op+++def node(into, id, points, **extra):+ n = {"type": "path", "d": path(points), **extra}+ if id:+ n["id"] = id+ return {"op": "add", "node": n, "in": into}+++def radial(center, radius, stops):+ return {"radial": {"center": [round(center[0], 1), round(center[1], 1)], "radius": radius, "stops": stops}}+++def linear(a, b, stops):+ return {"linear": {"from": list(a), "to": list(b), "stops": stops}}+++def edge(a, b, steps, amp, seed, freq=0.08):+ n = noise(seed)+ length = math.hypot(b[0] - a[0], b[1] - a[1]) or 1+ nx, ny = -(b[1] - a[1]) / length, (b[0] - a[0]) / length+ out = []+ for i in range(steps + 1):+ t = i / steps+ d = n(t * length * freq) * amp * math.sin(math.pi * t) ** 0.3+ out.append((a[0] + (b[0] - a[0]) * t + nx * d, a[1] + (b[1] - a[1]) * t + ny * d))+ return out+++def chipped(corners, seed, chip=7.0, amp=1.4):+ rnd = random.Random(seed)+ out = []+ count = len(corners)+ for i in range(count):+ a, b = corners[i], corners[(i + 1) % count]+ length = math.hypot(b[0] - a[0], b[1] - a[1])+ cut_a = min(length * 0.3, rnd.uniform(1.5, chip))+ cut_b = min(length * 0.3, rnd.uniform(1.5, chip))+ ux, uy = (b[0] - a[0]) / length, (b[1] - a[1]) / length+ start = (a[0] + ux * cut_a, a[1] + uy * cut_a)+ end = (b[0] - ux * cut_b, b[1] - uy * cut_b)+ steps = max(2, int(length / 9))+ line = edge(start, end, steps, amp, seed * 31 + i, 0.15)+ if length > 40 and rnd.random() < 0.35:+ k = rnd.randint(1, steps - 1)+ nx, ny = -uy, ux+ depth = rnd.uniform(2.5, 6.0)+ line[k] = (line[k][0] - nx * depth, line[k][1] - ny * depth)+ out += line+ return out+++def blocks_column(x0, x1, top, seed, broken=False):+ rnd = random.Random(seed)+ out = []+ y = FLOOR+ row = 0+ while y > top + 20:+ h = rnd.uniform(34, 70) if row else rnd.uniform(56, 72)+ y_top = max(top, y - h)+ kind = rnd.random()+ if kind < 0.4:+ cuts = [x0 + rnd.uniform(-5, 4), x1 + rnd.uniform(-4, 5)]+ elif kind < 0.85:+ m = rnd.uniform(0.3, 0.7)+ cuts = [x0 + rnd.uniform(-4, 3), x0 + (x1 - x0) * m, x1 + rnd.uniform(-3, 4)]+ else:+ cuts = [x0 + rnd.uniform(-3, 3), x0 + (x1 - x0) * rnd.uniform(0.22, 0.38), x0 + (x1 - x0) * rnd.uniform(0.6, 0.78), x1 + rnd.uniform(-3, 3)]+ for i in range(len(cuts) - 1):+ a, b = cuts[i] + 2, cuts[i + 1] - 2+ lean = rnd.uniform(-2, 2)+ sag = rnd.uniform(-2.5, 2.5)+ corners = [(a + lean, y_top + 2 + sag), (b + lean, y_top + 2 - sag), (b, y - 2), (a, y - 2)]+ out.append(corners)+ y = y_top+ row += 1+ if broken:+ last = out.pop()+ x_a, x_b = last[3][0], last[2][0]+ base_y = last[3][1]+ for k in range(4):+ w = (x_b - x_a) * rnd.uniform(0.22, 0.4)+ x = x_a + (x_b - x_a - w) * rnd.uniform(0, 1)+ h = rnd.uniform(14, 34)+ out.append([(x, base_y - h * rnd.uniform(0.6, 1)), (x + w * rnd.uniform(0.5, 0.8), base_y - h), (x + w, base_y - h * 0.4), (x + w, base_y - 1), (x, base_y - 1)])+ return out+++def voussoirs(centre, inner, outer, a0, a1, count, seed):+ rnd = random.Random(seed)+ out = []+ span = (a1 - a0) / count+ for i in range(count):+ s, e = a0 + span * i + 0.6 / inner * 57.3 * 0.03, a0 + span * (i + 1) - 0.6 / inner * 57.3 * 0.03+ s, e = math.radians(s), math.radians(e)+ r_out = outer + rnd.uniform(-6, 8)+ pts = [(centre[0] + inner * math.cos(s), centre[1] - inner * math.sin(s)),+ (centre[0] + r_out * math.cos(s), centre[1] - r_out * math.sin(s)),+ (centre[0] + r_out * math.cos(e), centre[1] - r_out * math.sin(e)),+ (centre[0] + inner * math.cos(e), centre[1] - inner * math.sin(e))]+ out.append(pts)+ return out+++def settle(points, x):+ cx = sum(p[0] for p in points) / len(points)+ low = max(p[1] for p in points)+ return [(px - cx + x, py - low + FLOOR + 5) for px, py in points]+++def turned(points, centre, degrees, shift):+ a = math.radians(degrees)+ ca, sa = math.cos(a), math.sin(a)+ return [(centre[0] + (x - centre[0]) * ca - (y - centre[1]) * sa + shift[0],+ centre[1] + (x - centre[0]) * sa + (y - centre[1]) * ca + shift[1]) for x, y in points]+++def tower(x, w, h, base, seed):+ rnd = random.Random(seed)+ top = base - h+ left = edge((x, base), (x + rnd.uniform(-6, 6), top + rnd.uniform(0, 30)), 24, 3, seed)+ broken = []+ steps = 10+ for i in range(steps + 1):+ t = i / steps+ bx = x + w * t+ by = top + rnd.uniform(-14, 26) + (40 if 0.35 < t < 0.65 and rnd.random() < 0.8 else 0)+ broken.append((bx, by))+ right = edge((x + w + rnd.uniform(-6, 6), broken[-1][1]), (x + w, base), 24, 3, seed + 1)+ return left + broken + right+++def far():+ out = [node("deep", None, [(0, 0), (W, 0), (W, H), (0, H)],+ fill=linear((0, 0), (0, H), [[0, COLOURS["deep top"]], [0.55, COLOURS["deep"]], [1, "#222a3e"]]))]+ out.append({"op": "add", "node": {"type": "ellipse", "cx": LAMP[0], "cy": LAMP[1] + 40, "rx": 900, "ry": 640,+ "fill": radial((LAMP[0], LAMP[1] + 40), 900, [[0, "#56668466"], [0.5, "#3a486230"], [1, "#27314800"]])},+ "in": "deep"})+ rnd = random.Random(4)+ for i, (x, w, h) in enumerate([(120, 120, 430), (420, 90, 300), (690, 140, 380), (1560, 110, 340), (1760, 150, 470)]):+ out.append(node("far-v", f"tower{i}", tower(x, w, h, 860, 40 + i), fill=COLOURS["far"], blur=1.2))+ for k in range(rnd.randint(1, 3)):+ wx, wy = x + w * rnd.uniform(0.3, 0.6), 860 - h * rnd.uniform(0.4, 0.8)+ out.append({"op": "add", "node": {"type": "path", "d": path([(wx - 9, wy + 26), (wx - 9, wy), (wx - 5, wy - 9), (wx, wy - 11),+ (wx + 5, wy - 9), (wx + 9, wy), (wx + 9, wy + 26)]),+ "fill": "#4a5772", "blur": 0.8}, "in": "far-v"})+ ceiling = [(0, 0), (W, 0)]+ n = noise(9)+ band = [(W - x, 120 + 40 * n(x * 0.004) + (60 * max(0, math.sin(x * 0.021 + 1)) ** 6)) for x in range(0, W + 1, 12)]+ out.append(node("far-v", "far-ceiling", ceiling + band, fill="#4b5873", blur=1.5))+ out.append(node("far-v", "far-floor", [(0, 870)] + [(x, 850 + 16 * n(x * 0.006 + 30)) for x in range(0, W + 1, 16)] + [(W, H), (0, H)],+ fill="#55627c", blur=1))+ return out+++def spike(x, top, length, width, seed, lean=0.0):+ rnd = random.Random(seed)+ left = [(x - width / 2 + rnd.uniform(-2, 2), top)]+ right = [(x + width / 2 + rnd.uniform(-2, 2), top)]+ steps = 9+ for i in range(1, steps + 1):+ t = i / steps+ w = width / 2 * (1 - t) ** 1.25 * (1 + 0.25 * math.sin(t * 7 + seed))+ cx = x + lean * t * t * length+ left.append((cx - w + rnd.uniform(-1.5, 1.5), top + length * t))+ right.append((cx + w + rnd.uniform(-1.5, 1.5), top + length * t))+ return left + list(reversed(right))+++def back():+ out = []+ n = noise(21)+ left = [(0, 0), (520, 0)]+ for i in range(41):+ t = i / 40+ y = t * H+ x = 380 + 120 * n(t * 3.0) + 90 * math.sin(t * 5.2) - 140 * t+ left.append((x, y))+ left += [(0, H)]+ out.append(node("back-v", "left-wall", left, fill=COLOURS["back"], blur=0.6))+ right = [(W, 0), (1500, 0)]+ for i in range(41):+ t = i / 40+ right.append((1600 - 80 * n(t * 3.3 + 7) + 120 * t + 40 * math.sin(t * 6.1), t * H))+ right += [(W, H)]+ out.append(node("back-v", "right-wall", right, fill=COLOURS["back"], blur=0.6))+ roof = [(0, 0), (W, 0)] + [(W - x, 150 + 34 * n(x * 0.005 + 50) + 30 * math.sin(x * 0.011)) for x in range(0, W + 1, 12)]+ out.append(node("back-v", "roof", roof, fill=COLOURS["back"], blur=0.6))+ rnd = random.Random(23)+ for i in range(16):+ x = rnd.uniform(380, 1700)+ top = 120 + 30 * n(x * 0.005 + 50)+ out.append(node("back-v", None, spike(x, top, rnd.uniform(60, 200), rnd.uniform(22, 52), 100 + i, rnd.uniform(-0.08, 0.08)),+ fill=COLOURS["back"], blur=0.5))+ for i in range(6):+ x = rnd.uniform(420, 1650)+ out.append(node("back-v", None, chipped([(x, 868), (x + rnd.uniform(60, 140), 868 - rnd.uniform(4, 10)),+ (x + rnd.uniform(70, 150), 870 + rnd.uniform(26, 60)), (x - 10, 870 + rnd.uniform(26, 60))],+ 300 + i, 14, 3), fill="#2d3649", blur=0.5))+ for i, (cx, span, height, keep) in enumerate(((560, 150, 300, 0.85), (1720, 120, 250, 0.55), (300, 110, 220, 0.4))):+ arch_pts = []+ for k in range(25):+ a = math.pi * (1 - k / 24 * keep)+ arch_pts.append((cx + span * math.cos(a), 868 - height - span * 0.9 * math.sin(a)))+ inner = [(cx + (span - 40) * math.cos(math.pi * (1 - k / 24 * keep)), 868 - height - (span - 40) * 0.9 * math.sin(math.pi * (1 - k / 24 * keep)))+ for k in range(24, -1, -1)]+ left_leg = [(cx - span, 868), (cx - span, 868 - height)]+ out.append(node("back-v", None, left_leg + arch_pts + inner + [(cx - span + 40, 868 - height), (cx - span + 40, 868)],+ fill="#222a3c", blur=0.8))+ if keep > 0.8:+ out.append(node("back-v", None, [(cx + span - 40, 868), (cx + span - 40, 868 - height), (cx + span, 868 - height), (cx + span, 868)],+ fill="#222a3c", blur=0.8))+ out.append(node("back-v", "back-floor", [(0, 900)] + [(x, 872 + 12 * n(x * 0.01 + 80)) for x in range(0, W + 1, 20)] + [(W, H), (0, H)],+ fill="#2b3446", blur=0.5))+ return out+++def gate():+ out, sketch = [], []+ left_blocks = blocks_column(862, 992, 336, 7)+ right_blocks = blocks_column(1292, 1422, 452, 8, broken=True)+ centre, inner, outer = (1142, 340), 150, 236+ arch = voussoirs(centre, inner, outer, 180, 62, 9, 11)+ fallen = [turned(v, (sum(p[0] for p in v) / 4, sum(p[1] for p in v) / 4), a, s)+ for v, a, s in zip(voussoirs(centre, inner, outer, 62, 0, 3, 12), (78, -32, 128), ((0, 0), (0, 0), (0, 0)))]+ fallen = [settle(v, x) for v, x in zip(fallen, (1488, 1578, 1690))]+ pieces = {"left": left_blocks, "right": right_blocks, "arch": arch, "fallen": fallen}+ ids = {}+ for name, polys in pieces.items():+ ids[name] = []+ for i, corners in enumerate(polys):+ sid = f"{name}{i}"+ SKETCH_CENTRES[sid] = (sum(p[0] for p in corners) / len(corners), sum(p[1] for p in corners) / len(corners))+ SKETCH_CORNERS[sid] = corners+ sketch.append(node("sketch", sid, chipped(corners, sum(map(ord, sid)) * 7 + i, 8 if name != "fallen" else 12, 1.6)))+ ids[name].append(sid)+ floor_top = [(-20, FLOOR + 8)] + [(x, FLOOR - 4 + 6 * noise(70)(x * 0.01)) for x in range(0, W + 41, 24)] + [(W + 20, FLOOR + 40), (-20, FLOOR + 40)]+ floor_front = [(-20, FLOOR + 34)] + [(x, FLOOR + 30 + 8 * noise(71)(x * 0.008)) for x in range(0, W + 41, 24)] + [(W + 20, H + 20), (-20, H + 20)]+ sketch += [node("sketch", "floor-top", floor_top), node("sketch", "floor-front", floor_front)]+ out += sketch+ paint = lambda lay, shapes, colour, seed, **kw: {"op": "paint", "layer": lay, "in": shapes, "color": colour, "lamp": [LAMP[0], LAMP[1], 110],+ "key": COLOURS["key"], "fill": COLOURS["fill"], "fillStrength": 0.28,+ "bounce": "#6b5a4a", "bounceStrength": 0.1, "shadow": COLOURS["shadow"], "shadowMix": 0.6,+ "seed": seed, **kw}+ for lay, shapes, colour in (("floor", ["floor-top"], "floor"), ("floor", ["floor-front"], "floor front"),+ ("left-pillar", ids["left"], "stone"), ("right-pillar", ids["right"], "stone"),+ ("arch", ids["arch"], "stone"), ("fallen", ids["fallen"], "stone dark")):+ out += [{"op": "fill", "layer": lay, "shape": s, "color": colour, "expand": 0.5} for s in shapes]+ for lay in ("floor", "left-pillar", "right-pillar", "arch", "fallen"):+ out.append({"op": "set", "id": lay, "lockAlpha": True})+ out.append(paint("floor", ["floor-top"], "floor", 5, form="flat", facing=[0, -1, 0.35], angle=1, weight=16, decisive=0.7))+ lip = [(x, FLOOR + 30 + 8 * noise(71)(x * 0.008)) for x in range(700, 1600, 12)]+ out.append({"op": "stroke", "layer": "floor-rocks", "brush": "soft", "size": 7, "color": "#e0a868", "opacity": 0.5,+ "path": path(lip, False), "pressure": [0.05, 0.6, 1, 0.6, 0.05]})+ out.append(paint("floor", ["floor-front"], "floor front", 6, form="flat", facing=[0, 0.2, 1], angle=88, weight=18, decisive=0.3, brush="dry-brush"))+ stone = dict(brush="chalk", bold="dry-brush", vary=0.07)+ out.append(paint("left-pillar", ids["left"], "stone", 7, form="flat", facing=[0, 0, 1], angle=38, weight=8, decisive=1, **stone))+ out.append(paint("right-pillar", ids["right"], "stone", 8, form="flat", facing=[0, 0, 1], angle=-36, weight=8, decisive=1, **stone))+ out.append(paint("arch", ids["arch"], "stone", 9, form="flat", facing=[0, 0.4, 1], angle=62, weight=8, decisive=1, **stone))+ out.append(paint("fallen", ids["fallen"], "stone dark", 10, form="flat", facing=[0, -0.6, 1], angle=24, weight=7, decisive=0.8, **stone))+ for lay in ("floor", "left-pillar", "right-pillar", "arch", "fallen"):+ out.append({"op": "set", "id": lay, "lockAlpha": False})+ reliefs = {"left-pillar": [1, -0.25], "right-pillar": [-1, -0.25], "arch": [0, 1], "fallen": [-0.6, -0.8], "floor": [0, -1]}+ out += [{"op": "set", "id": lay, "effects": [{"relief": {"light": light, "strength": 1.6, "highlight": "#ffd9a0", "shade": "#141826"}}]}+ for lay, light in reliefs.items()]+ near = lambda s: math.hypot(*(a - b for a, b in zip(centre_of(s), LAMP)))+ for name in ("left", "right", "arch"):+ out.append({"op": "light", "from": ids[name], "lamp": [LAMP[0], LAMP[1], 60], "shade": f"{name}-shade",+ "depth": 7, "soft": 2, "shadeColor": "#2c3046", "shadeOpacity": 0.9})+ for lo, hi, strength in ((0, 230, 0.65), (230, 380, 0.38), (380, 9999, 0.16)):+ band = [s for s in ids[name] if lo <= near(s) < hi]+ if band:+ out.append({"op": "light", "from": band, "lamp": [LAMP[0], LAMP[1], 60], "rim": f"{name}-rim", "rimColor": "#ffb867",+ "rimWidth": 4 if lo == 0 else 3, "rimOpacity": strength})+ rnd = random.Random(808)+ for sid in [s for name in ("left", "right", "arch") for s in ids[name] if near(s) < 300]:+ if rnd.random() < 0.45:+ cx, cy = centre_of(sid)+ x, y = cx + rnd.uniform(-30, 30), cy + rnd.uniform(-12, 12)+ pts = [(x, y)]+ a = rnd.uniform(0, 2 * math.pi)+ for k in range(rnd.randint(3, 6)):+ a += rnd.uniform(-0.9, 0.9)+ step = rnd.uniform(5, 11)+ x, y = x + step * math.cos(a), y + step * math.sin(a)+ pts.append((x, y))+ out.append({"op": "stroke", "layer": "gate-ink", "brush": "ink", "size": rnd.uniform(1.6, 2.6), "color": "ink",+ "path": path(pts, False), "pressure": [0.3, 1, 0.7, 0.1], "taper": [3, 10]})+ for sid in [s for s in ids["left"] + ids["right"]]:+ cx, cy = centre_of(sid)+ if rnd.random() < 0.55:+ top_y = min(p[1] for p in SKETCH_CORNERS[sid])+ width = (max(p[0] for p in SKETCH_CORNERS[sid]) - min(p[0] for p in SKETCH_CORNERS[sid])) * rnd.uniform(0.3, 0.8)+ x0 = cx - width / 2 + rnd.uniform(-10, 10)+ out.append({"op": "add", "node": {"type": "rect", "id": f"moss-{sid}", "x": round(x0, 1), "y": round(top_y - 3, 1),+ "w": round(width, 1), "h": 5}, "in": "sketch"})+ out.append({"op": "scatter", "layer": "moss", "in": [f"moss-{sid}"], "mark": "M0 0 Q 2 -5 1 -10", "count": int(width / 6),+ "size": [0.6, 1.3], "turn": [-40, 40], "weight": 3, "color": "moss", "seed": int(cx + cy)})+ focus = [s for name in ("left", "right", "arch") for s in ids[name]]+ out.append({"op": "ink", "layer": "gate-ink", "from": [s for s in focus if near(s) < 330], "weight": 4.4,+ "light": [0, -1], "color": "ink", "seed": 3, "break": 50, "gap": 2})+ out.append({"op": "ink", "layer": "gate-ink", "from": [s for s in focus if near(s) >= 330] + ids["fallen"], "weight": 3, "light": [0, -1],+ "color": "ink", "seed": 4, "opacity": 0.75, "break": 50, "gap": 3})+ return out, ids+++def centre_of(sid):+ return SKETCH_CENTRES[sid]+++def lantern():+ out = []+ chain = [(LAMP[0], 196), (LAMP[0] + 2, 260), (LAMP[0] - 1, 340), (LAMP[0], LAMP[1] - 40)]+ hook = [(LAMP[0] - 7, 188), (LAMP[0] - 7, 200), (LAMP[0], 206), (LAMP[0] + 7, 200), (LAMP[0] + 7, 188)]+ out.append({"op": "ink", "layer": "lantern-ink", "path": path(hook, False), "weight": 4, "color": "ink", "seed": 29})+ out.append({"op": "ink", "layer": "lantern-ink", "path": path(chain, False), "weight": 3, "color": "ink", "seed": 30, "wobble": 0.6})+ for k, y in enumerate(range(214, int(LAMP[1] - 44), 22)):+ out.append({"op": "add", "node": {"type": "ellipse", "cx": LAMP[0] + (k % 2) * 1.5, "cy": y, "rx": 3.6 if k % 2 else 1.8, "ry": 6,+ "fill": "none", "stroke": {"paint": COLOURS["iron"], "width": 2.2}}, "in": "lantern-v"})+ cage = [(LAMP[0] - 30, LAMP[1] - 20), (LAMP[0] - 20, LAMP[1] - 40), (LAMP[0] + 20, LAMP[1] - 40), (LAMP[0] + 30, LAMP[1] - 20),+ (LAMP[0] + 26, LAMP[1] + 34), (LAMP[0] + 12, LAMP[1] + 46), (LAMP[0] - 12, LAMP[1] + 46), (LAMP[0] - 26, LAMP[1] + 34)]+ out.append({"op": "add", "node": {"type": "path", "d": path(cage), "fill": "#ffe2b0"}, "in": "lantern-v"})+ for dx in (-16, 0, 16):+ out.append({"op": "ink", "layer": "lantern-ink", "path": path([(LAMP[0] + dx * 0.8, LAMP[1] - 40), (LAMP[0] + dx * 1.3, LAMP[1] - 8),+ (LAMP[0] + dx * 0.9, LAMP[1] + 44)], False),+ "weight": 3.2, "color": "ink", "seed": 31 + dx})+ out.append({"op": "ink", "layer": "lantern-ink", "path": path(cage), "weight": 4, "color": "ink", "seed": 34, "light": [0, -1]})+ cap = [(LAMP[0] - 34, LAMP[1] - 38), (LAMP[0] - 10, LAMP[1] - 54), (LAMP[0] + 10, LAMP[1] - 54), (LAMP[0] + 34, LAMP[1] - 38)]+ out.append({"op": "add", "node": {"type": "path", "d": path(cap), "fill": COLOURS["iron"]}, "in": "lantern-v"})+ return out+++def roots():+ out = []+ rnd = random.Random(55)+ for i in range(5):+ a = math.radians(rnd.uniform(100, 172))+ x0, y0 = 1142 + 146 * math.cos(a), 340 - 146 * math.sin(a) - 4+ length = rnd.uniform(70, 190)+ sway = rnd.uniform(8, 20)+ pts = [(x0 + sway * math.sin(k * 0.5 + i) * (k / 10) ** 1.3, y0 + length * k / 10) for k in range(11)]+ out.append({"op": "stroke", "layer": "roots", "brush": "ink", "size": rnd.uniform(3, 6.5), "color": "root",+ "path": path(pts, False), "pressure": [0.9, 0.8, 0.5, 0.15], "taper": [0, length * 0.6]})+ return out+++def near():+ out = []+ n = noise(91)+ rock = [(-20, H + 20), (-20, 860)]+ for i in range(30):+ t = i / 29+ x = t * 520+ rock.append((x, 900 - 90 * math.sin(t * math.pi) ** 0.7 + 22 * n(t * 6) - 40 * (1 - t)))+ rock += [(560, H + 20)]+ out.append(node("near-v", "near-left", rock, fill=COLOURS["near"]))+ rock2 = [(W + 20, H + 20), (W + 20, 820)]+ for i in range(30):+ t = i / 29+ rock2.append((W - t * 380, 860 - 60 * math.sin(t * math.pi) ** 0.6 + 18 * n(t * 5 + 9) + 60 * t))+ rock2 += [(W - 420, H + 20)]+ out.append(node("near-v", "near-right", rock2, fill=COLOURS["near"]))+ hang = [(-20, -20), (460, -20)]+ for i in range(40):+ t = i / 39+ x = 460 - t * 480+ y = 40 + 30 * n(t * 7 + 3) + 220 * max(0, math.sin(t * 9.0)) ** 3 * (1 - t * 0.4) + 160 * t+ hang.append((x, y))+ out.append(node("near-v", "near-roof", hang, fill=COLOURS["near"]))+ rnd = random.Random(92)+ for i in range(5):+ x = rnd.uniform(40, 420)+ out.append(node("near-v", None, spike(x, 40 + 20 * n(x * 0.01), rnd.uniform(120, 300), rnd.uniform(26, 50), 500 + i,+ rnd.uniform(-0.1, 0.1)), fill=COLOURS["near"]))+ out.append({"op": "add", "node": {"type": "rect", "id": "tuft-left", "x": 40, "y": 836, "w": 460, "h": 30}, "in": "sketch"})+ out.append({"op": "add", "node": {"type": "rect", "id": "tuft-right", "x": W - 380, "y": 812, "w": 340, "h": 40}, "in": "sketch"})+ out += [{"op": "scatter", "layer": "near-ink", "in": [tuft], "mark": mark, "count": count, "size": [0.7, 1.7], "turn": turn,+ "weight": 6, "color": "near", "seed": 60 + i}+ for i, (tuft, mark, turn, count) in enumerate([("tuft-left", "M0 0 Q 4 -40 14 -84", [-35, 20], 34),+ ("tuft-right", "M0 0 Q -4 -40 -14 -84", [-20, 35], 26)])]+ return out+++def light():+ out = []+ out.append({"op": "add", "node": {"type": "ellipse", "cx": LAMP[0], "cy": LAMP[1], "rx": 620, "ry": 620,+ "fill": radial(LAMP, 620, [[0, "#ffb25e66"], [0.25, "#e9944a2a"], [0.6, "#8a6a7a10"], [1, "#00000000"]])},+ "in": "halo"})+ out.append({"op": "add", "node": {"type": "ellipse", "cx": LAMP[0], "cy": FLOOR + 6, "rx": 360, "ry": 46,+ "fill": radial((LAMP[0], FLOOR + 6), 360, [[0, "#ffc27a55"], [1, "#ffb05a00"]]), "blur": 8},+ "in": "halo"})+ out.append({"op": "add", "node": {"type": "ellipse", "cx": LAMP[0], "cy": LAMP[1] + 8, "rx": 70, "ry": 70,+ "fill": radial((LAMP[0], LAMP[1] + 8), 70, [[0, "#fff4dcff"], [0.35, "#ffd08acc"], [1, "#ffb05a00"]])},+ "in": "light"})+ rnd = random.Random(77)+ for i in range(34):+ a = rnd.uniform(0, 2 * math.pi)+ r = rnd.uniform(70, 420) ** 1.0+ x, y = LAMP[0] + r * math.cos(a) * 1.3, LAMP[1] + r * math.sin(a) * 0.8+ s = rnd.uniform(1.4, 3.8) * (1.2 - r / 520)+ out.append({"op": "add", "node": {"type": "ellipse", "cx": round(x, 1), "cy": round(y, 1), "rx": round(s, 2), "ry": round(s, 2),+ "fill": COLOURS["mote"], "blur": round(s * 0.6, 2), "opacity": round(0.4 + 0.6 * (1 - r / 420), 2)},+ "in": "light"})+ return out+++def ops():+ out = [{"op": "palette", "add": c, "name": n} for n, c in COLOURS.items()]+ out.append({"op": "atmosphere", "color": "#4f6080", "top": "#2a3550", "density": 0.3, "blur": 0.9, "desaturate": 0.12})+ out += [+ layer("sketch", "vector", visible=False),+ layer("far-plane", "group", depth=2.6),+ layer("deep", "vector", into="far-plane"),+ layer("far-v", "vector", into="far-plane"),+ layer("back-plane", "group", depth=1.3),+ layer("back-v", "vector", into="back-plane"),+ layer("gate-plane", "group", depth=0.25),+ layer("floor", "paint", into="gate-plane"),+ layer("floor-rocks", "paint", into="gate-plane"),+ layer("fallen", "paint", into="gate-plane"),+ layer("left-pillar", "paint", into="gate-plane"),+ layer("left-shade", "paint", into="gate-plane", clip=True, blend="multiply"),+ layer("left-rim", "paint", into="gate-plane", clip=True, blend="screen"),+ layer("right-pillar", "paint", into="gate-plane"),+ layer("right-shade", "paint", into="gate-plane", clip=True, blend="multiply"),+ layer("right-rim", "paint", into="gate-plane", clip=True, blend="screen"),+ layer("arch", "paint", into="gate-plane"),+ layer("arch-shade", "paint", into="gate-plane", clip=True, blend="multiply"),+ layer("arch-rim", "paint", into="gate-plane", clip=True, blend="screen"),+ layer("moss", "paint", into="gate-plane"),+ layer("roots", "paint", into="gate-plane"),+ layer("gate-ink", "paint", into="gate-plane"),+ layer("lantern-v", "vector", into="gate-plane"),+ layer("lantern-ink", "paint", into="gate-plane"),+ layer("halo", "vector", blend="screen"),+ layer("near-plane", "group"),+ layer("near-v", "vector", into="near-plane"),+ layer("near-ink", "paint", into="near-plane"),+ layer("light", "vector", blend="add"),+ ]+ out += far() + back()+ g, ids = gate()+ out += g + lantern() + roots() + near() + light()+ return out+++if __name__ == "__main__":+ print("\n".join(json.dumps(o) for o in ops()))