Files
threshing-atlas/apps/atlas/dragons.js
T
ekcSchianoandClaude Opus 5.5 2eace69d7d Valley map: cadets at the bully fight, the wounded cadet, and the thorn bush
Original silhouettes built from the same parts as the dragons: your squadmate
with a raised sword facing the two bullies (sword and dagger), the wounded
cadet on the ground, and a thorny bush at the hour's walk. Each has a short
hover note and fades when a chosen route does not pass it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
2026-11-02 16:19:58 +00:00

309 lines
18 KiB
JavaScript

/* dragons.js — original dragon silhouettes for the valley map.
* Each pose is built from simple parts (tapered tubes, a scalloped wing membrane, a head with horns, spines,
* a spaded tail), so every dragon is drawn the same way but stands differently. Drawn facing right in a
* 200 x 160 box; flip with scale(-1, 1). Works in the browser (window.DragonArt) and in Node. */
(function (root, factory) {
if (typeof module === "object" && module.exports) module.exports = factory();
else root.DragonArt = factory();
})(typeof self !== "undefined" ? self : this, function () {
"use strict";
const f = (n) => Math.round(n * 10) / 10;
const lerp = (a, b, t) => a + (b - a) * t;
/** Points along a cubic Bezier given as [p0, c1, c2, p1] (each [x, y]). */
function bez(P, n = 28) {
const out = [];
for (let i = 0; i <= n; i++) {
const t = i / n, u = 1 - t;
out.push([
u * u * u * P[0][0] + 3 * u * u * t * P[1][0] + 3 * u * t * t * P[2][0] + t * t * t * P[3][0],
u * u * u * P[0][1] + 3 * u * u * t * P[1][1] + 3 * u * t * t * P[2][1] + t * t * t * P[3][1],
]);
}
return out;
}
/** A tube along a Bezier whose half-width goes from r0 to r1 (r can also be a function of t). */
function tube(P, r0, r1, n = 28) {
const pts = bez(P, n), L = [], R = [];
pts.forEach((p, i) => {
const a = pts[Math.max(0, i - 1)], b = pts[Math.min(pts.length - 1, i + 1)];
let dx = b[0] - a[0], dy = b[1] - a[1];
const len = Math.hypot(dx, dy) || 1;
dx /= len; dy /= len;
const t = i / n, r = typeof r0 === "function" ? r0(t) : lerp(r0, r1, t);
L.push([p[0] - dy * r, p[1] + dx * r]);
R.push([p[0] + dy * r, p[1] - dx * r]);
});
const ring = L.concat(R.reverse());
return "M" + ring.map((p) => `${f(p[0])} ${f(p[1])}`).join(" L") + " Z";
}
const poly = (pts) => "M" + pts.map((p) => `${f(p[0])} ${f(p[1])}`).join(" L") + " Z";
const ell = (cx, cy, rx, ry, rot = 0) => {
const pts = [];
for (let i = 0; i < 36; i++) {
const a = (i / 36) * Math.PI * 2, x = rx * Math.cos(a), y = ry * Math.sin(a), c = Math.cos(rot), s = Math.sin(rot);
pts.push([cx + x * c - y * s, cy + x * s + y * c]);
}
return poly(pts);
};
/**
* Wing membrane: a leading-edge bone shoulder -> wrist -> tip, finger tips along the trailing edge, and
* scalloped membrane between them, back to the root on the body.
*/
function wing({ shoulder, wrist, tip, fingers, root, bow = 0.28, bone = 4 }) {
const d = [tube([shoulder, [lerp(shoulder[0], wrist[0], 0.4), lerp(shoulder[1], wrist[1], 0.4) - 6], [lerp(shoulder[0], wrist[0], 0.8), lerp(shoulder[1], wrist[1], 0.8)], wrist], bone, bone * 0.8),
tube([wrist, [lerp(wrist[0], tip[0], 0.3), lerp(wrist[1], tip[1], 0.3)], [lerp(wrist[0], tip[0], 0.7), lerp(wrist[1], tip[1], 0.7)], tip], bone * 0.8, 0.8)];
const edge = [tip].concat(fingers, [root]);
let m = `M${f(shoulder[0])} ${f(shoulder[1])} L${f(wrist[0])} ${f(wrist[1])} L${f(tip[0])} ${f(tip[1])}`;
for (let i = 1; i < edge.length; i++) {
const a = edge[i - 1], b = edge[i];
// scallop: control point pulled toward the wrist
const mx = (a[0] + b[0]) / 2, my = (a[1] + b[1]) / 2;
const cx = lerp(mx, wrist[0], bow), cy = lerp(my, wrist[1], bow);
m += ` Q${f(cx)} ${f(cy)} ${f(b[0])} ${f(b[1])}`;
}
m += ` L${f(shoulder[0])} ${f(shoulder[1])} Z`;
d.push(m);
// finger bones from the wrist (thin, add texture at the edge)
fingers.forEach((p) => d.push(tube([wrist, [lerp(wrist[0], p[0], 0.33), lerp(wrist[1], p[1], 0.33)], [lerp(wrist[0], p[0], 0.66), lerp(wrist[1], p[1], 0.66)], p], 1.6, 0.6, 10)));
return d;
}
/** Head pointing along `ang` (radians, 0 = right) from the neck end, with horns and an open or closed jaw. */
function head({ at, ang = 0, size = 1, open = 0, horns = 2 }) {
const c = Math.cos(ang), s = Math.sin(ang);
const T = (x, y) => [at[0] + (x * c - y * s) * size, at[1] + (x * s + y * c) * size];
const d = [];
// skull and upper snout
d.push(poly([T(-8, 2), T(-6, -9), T(4, -12), T(14, -8), T(26, -5), T(31, -2), T(30, 1), T(18, 2 + open * 0.3), T(8, 6)]));
// jaw (drops when open)
d.push(poly([T(-6, 3), T(10, 4), T(28, 3 + open), T(26, 6 + open), T(12, 10 + open * 0.4), T(-4, 9)]));
// horns sweeping back
for (let i = 0; i < horns; i++) {
const y0 = -9 + i * 4, len = 18 - i * 6;
d.push(tube([T(2 - i * 3, y0), T(-6 - i * 2, y0 - 6), T(-14 - i * 3, y0 - 8 - i), T(-12 - len * 0.6 - i * 3, y0 - 14 + i * 3)], 2.6 * size - i * 0.4, 0.4, 10));
}
// brow spike and cheek frill
d.push(poly([T(-4, 4), T(-14, 8), T(-5, 8)]));
return { d, eye: T(8, -5), eyeR: 1.9 * size };
}
/** Small triangular spines along a list of points (pointing away from `side` normal). */
function spines(pts, size, side = -1, every = 2) {
const d = [];
for (let i = 1; i < pts.length - 1; i += every) {
const a = pts[i - 1], b = pts[i + 1], p = pts[i];
let dx = b[0] - a[0], dy = b[1] - a[1];
const len = Math.hypot(dx, dy) || 1;
dx /= len; dy /= len;
const nx = -dy * side, ny = dx * side, k = typeof size === "function" ? size(i / pts.length) : size;
d.push(poly([[p[0] - dx * k * 0.6, p[1] - dy * k * 0.6], [p[0] + nx * k * 1.5 - dx * k * 0.5, p[1] + ny * k * 1.5 - dy * k * 0.5], [p[0] + dx * k * 0.6, p[1] + dy * k * 0.6]]));
}
return d;
}
/** Tail as a tapering tube ending in a spade. */
function tail(P, r0) {
const d = [tube(P, (t) => Math.max(0.9, r0 * (1 - t) ** 1.1), null, 36)];
const pts = bez(P, 36), a = pts[pts.length - 3], b = pts[pts.length - 1];
let dx = b[0] - a[0], dy = b[1] - a[1];
const len = Math.hypot(dx, dy) || 1;
dx /= len; dy /= len;
const nx = -dy, ny = dx, k = Math.max(4, r0 * 0.9);
d.push(poly([[b[0] - dx * k * 0.6, b[1] - dy * k * 0.6], [b[0] + nx * k, b[1] + ny * k], [b[0] + dx * k * 1.6, b[1] + dy * k * 1.6], [b[0] - nx * k, b[1] - ny * k]]));
return { d, pts };
}
/** Leg: hip -> knee -> foot with three claws. */
function leg(hip, knee, foot, r, toe = 1) {
const d = [tube([hip, [lerp(hip[0], knee[0], 0.6), lerp(hip[1], knee[1], 0.6)], knee, [lerp(knee[0], foot[0], 0.5), lerp(knee[1], foot[1], 0.5)]], r, r * 0.6, 14),
tube([[lerp(knee[0], foot[0], 0.4), lerp(knee[1], foot[1], 0.4)], [lerp(knee[0], foot[0], 0.6), lerp(knee[1], foot[1], 0.6)], [lerp(knee[0], foot[0], 0.85), lerp(knee[1], foot[1], 0.85)], foot], r * 0.6, r * 0.45, 10)];
for (let i = -1; i <= 1; i++) d.push(poly([[foot[0] - 2, foot[1] - 2], [foot[0] + toe * (6 + i * 1.5), foot[1] + 1 + i * 2.2], [foot[0] + 1, foot[1] + 2.5]]));
return d;
}
/* ---------- poses ---------- */
const POSES = {
// seated and watchful, one wing raised, tail curled round the feet
sitting() {
const d = [];
d.push(...wing({ shoulder: [88, 74], wrist: [62, 18], tip: [24, 30], fingers: [[14, 66], [30, 98], [56, 116]], root: [76, 112], bow: 0.3 }));
d.push(ell(92, 104, 26, 36, -0.25));
d.push(tube([[90, 80], [96, 58], [110, 42], [116, 34]], 13, 7));
const t = tail([[76, 132], [56, 150], [110, 158], [168, 150]], 9);
d.push(...t.d);
d.push(...leg([84, 120], [70, 136], [86, 152], 12, 1));
d.push(...leg([102, 104], [110, 124], [114, 150], 7, 1));
const h = head({ at: [114, 34], ang: -0.05, size: 1.05 });
d.push(...h.d);
d.push(...spines(bez([[86, 84], [84, 62], [100, 44], [110, 36]], 10), 4, -1, 2));
d.push(...spines(t.pts.slice(0, 26), (u) => 4 * (1 - u), 1, 3));
return { d, eye: h.eye, eyeR: h.eyeR };
},
// low and stalking, head forward, wings folded
prowling() {
const d = [];
d.push(...wing({ shoulder: [92, 92], wrist: [70, 64], tip: [118, 52], fingers: [[136, 70], [130, 90]], root: [104, 100], bow: 0.25, bone: 3.4 }));
d.push(ell(96, 108, 38, 18, 0.05));
d.push(tube([[124, 104], [140, 98], [152, 92], [162, 94]], 11, 7));
const t = tail([[62, 108], [36, 106], [22, 128], [6, 120]], 11);
d.push(...t.d);
d.push(...leg([72, 112], [60, 128], [70, 146], 11));
d.push(...leg([84, 116], [94, 130], [92, 146], 8));
d.push(...leg([118, 112], [126, 128], [124, 146], 8));
d.push(...leg([128, 110], [140, 126], [146, 146], 7));
const h = head({ at: [160, 94], ang: 0.12, size: 1 });
d.push(...h.d);
d.push(...spines(bez([[66, 92], [90, 84], [130, 86], [156, 88]], 14), 3.6, -1, 2));
d.push(...spines(t.pts.slice(0, 26), (u) => 3.6 * (1 - u), -1, 3));
return { d, eye: h.eye, eyeR: h.eyeR };
},
// in flight, both wings spread
flying() {
const d = [];
d.push(...wing({ shoulder: [96, 84], wrist: [70, 36], tip: [40, 6], fingers: [[30, 40], [44, 66], [70, 80]], root: [92, 94], bow: 0.32 }));
d.push(...wing({ shoulder: [110, 84], wrist: [140, 30], tip: [190, 14], fingers: [[178, 52], [160, 76], [134, 90]], root: [114, 96], bow: 0.32 }));
d.push(ell(104, 96, 30, 13, 0.2));
d.push(tube([[128, 92], [142, 86], [150, 76], [158, 72]], 9, 6));
const t = tail([[78, 92], [54, 98], [40, 120], [12, 116]], 8);
d.push(...t.d);
d.push(...leg([94, 102], [96, 116], [108, 124], 6));
d.push(...leg([116, 102], [122, 114], [132, 118], 5));
const h = head({ at: [156, 72], ang: -0.2, size: 0.9, open: 2 });
d.push(...h.d);
return { d, eye: h.eye, eyeR: h.eyeR };
},
// reared up and roaring, wings half open
roaring() {
const d = [];
d.push(...wing({ shoulder: [94, 68], wrist: [52, 40], tip: [30, 2], fingers: [[16, 46], [34, 78], [66, 96]], root: [90, 98], bow: 0.3 }));
d.push(ell(98, 100, 22, 40, 0.2));
d.push(tube([[104, 70], [112, 50], [126, 34], [136, 24]], 13, 7));
const t = tail([[86, 136], [60, 156], [30, 150], [14, 132]], 10);
d.push(...t.d);
d.push(...leg([90, 124], [104, 138], [96, 154], 12));
d.push(...leg([108, 86], [124, 92], [132, 82], 6, 1));
d.push(...leg([102, 92], [116, 104], [126, 98], 6, 1));
const h = head({ at: [134, 24], ang: -0.55, size: 1.05, open: 7 });
d.push(...h.d);
d.push(...spines(bez([[94, 86], [100, 60], [116, 40], [130, 28]], 10), 4, -1, 2));
return { d, eye: h.eye, eyeR: h.eyeR };
},
// coiled, as if wrapped around something, head lifted
coiled() {
const d = [];
const t = tail([[100, 120], [30, 150], [20, 80], [80, 74]], 15);
d.push(...t.d);
d.push(tube([[100, 120], [150, 130], [170, 96], [140, 70]], 16, 12));
d.push(tube([[140, 70], [124, 52], [128, 34], [146, 26]], 12, 7));
d.push(...wing({ shoulder: [134, 76], wrist: [106, 36], tip: [72, 26], fingers: [[64, 52], [80, 70], [104, 82]], root: [124, 90], bow: 0.28, bone: 3.4 }));
d.push(...leg([150, 116], [164, 126], [170, 142], 8));
d.push(...leg([116, 124], [114, 138], [122, 150], 8));
const h = head({ at: [144, 26], ang: 0.1, size: 1 });
d.push(...h.d);
d.push(...spines(t.pts, (u) => 3.5 * (1 - u * 0.7), -1, 3));
return { d, eye: h.eye, eyeR: h.eyeR };
},
// lying down at rest, head up
resting() {
const d = [];
d.push(...wing({ shoulder: [90, 108], wrist: [66, 84], tip: [112, 70], fingers: [[134, 88], [124, 108]], root: [100, 118], bow: 0.25, bone: 3.2 }));
d.push(ell(92, 126, 42, 18, 0));
d.push(tube([[124, 120], [140, 112], [146, 92], [158, 82]], 12, 7));
const t = tail([[54, 130], [24, 140], [20, 152], [70, 152]], 11);
d.push(...t.d);
d.push(...leg([120, 132], [132, 142], [150, 146], 8));
d.push(...leg([70, 134], [82, 144], [96, 148], 10));
const h = head({ at: [156, 84], ang: 0.05, size: 1 });
d.push(...h.d);
d.push(...spines(bez([[60, 112], [90, 104], [130, 106], [152, 88]], 14), 3.4, -1, 2));
return { d, eye: h.eye, eyeR: h.eyeR };
},
};
const cache = {};
/** SVG markup for one dragon: <g> with the silhouette in `fill` and a small eye in `eyeFill`. */
function svg(pose, { fill = "#2a2230", eyeFill = "#f6e6c4", flip = false } = {}) {
if (!cache[pose]) cache[pose] = POSES[pose]();
const p = cache[pose];
const tf = flip ? ' transform="translate(200 0) scale(-1 1)"' : "";
// one path per part: parts wind in different directions, so a single combined path would punch holes
return `<g${tf}><g fill="${fill}">${p.d.map((d) => `<path d="${d}"/>`).join("")}</g><circle cx="${f(p.eye[0])}" cy="${f(p.eye[1])}" r="${p.eyeR}" fill="${eyeFill}"/></g>`;
}
/* ---------- cadets and the thorn bush (same building blocks, 100 x 140 box, feet near y = 132) ---------- */
const line = (a, b, r0, r1 = r0) => tube([a, [lerp(a[0], b[0], 0.33), lerp(a[1], b[1], 0.33)], [lerp(a[0], b[0], 0.66), lerp(a[1], b[1], 0.66)], b], r0, r1, 8);
/** A cadet from joint positions; `cloak` adds a short flying cape, weapons are drawn from the hands. */
function cadet(j, { cloak = true, sword = null, dagger = null, size = 1 } = {}) {
const d = [];
if (cloak) d.push(poly([j.neck, [j.neck[0] - 4, j.neck[1] + 2], [j.hip[0] - 14 * (j.face || 1), j.hip[1] + 16], [j.hip[0] - 2 * (j.face || 1), j.hip[1] + 8], [j.neck[0] + 3, j.neck[1] + 4]]));
d.push(line(j.neck, j.hip, 7.5 * size, 6.5 * size)); // torso
d.push(line(j.hip, j.lKnee, 4.6 * size, 4 * size), line(j.lKnee, j.lFoot, 3.8 * size, 3 * size));
d.push(line(j.hip, j.rKnee, 4.6 * size, 4 * size), line(j.rKnee, j.rFoot, 3.8 * size, 3 * size));
d.push(poly([[j.lFoot[0] - 3, j.lFoot[1] - 2], [j.lFoot[0] + 7 * (j.face || 1), j.lFoot[1] - 1], [j.lFoot[0] + 7 * (j.face || 1), j.lFoot[1] + 2], [j.lFoot[0] - 3, j.lFoot[1] + 2]]));
d.push(poly([[j.rFoot[0] - 3, j.rFoot[1] - 2], [j.rFoot[0] + 7 * (j.face || 1), j.rFoot[1] - 1], [j.rFoot[0] + 7 * (j.face || 1), j.rFoot[1] + 2], [j.rFoot[0] - 3, j.rFoot[1] + 2]]));
const sh = [j.neck[0], j.neck[1] + 3];
d.push(line(sh, j.lElbow, 3.4 * size, 3), line(j.lElbow, j.lHand, 3, 2.4));
d.push(line(sh, j.rElbow, 3.4 * size, 3), line(j.rElbow, j.rHand, 3, 2.4));
d.push(ell(j.head[0], j.head[1], 7.2 * size, 8 * size, 0)); // head
d.push(ell(j.head[0] - 2 * (j.face || 1), j.head[1] - 3, 7 * size, 5 * size, 0)); // hair
d.push(line([(j.neck[0] + j.head[0]) / 2, (j.neck[1] + j.head[1]) / 2 + 2], j.neck, 3.2, 3.6)); // neck
const blade = (hand, ang, len, w) => {
const tip = [hand[0] + Math.cos(ang) * len, hand[1] + Math.sin(ang) * len];
const nx = -Math.sin(ang), ny = Math.cos(ang);
return [poly([[hand[0] + nx * w, hand[1] + ny * w], [tip[0] + nx * w * 0.4, tip[1] + ny * w * 0.4], [tip[0] + Math.cos(ang) * 4, tip[1] + Math.sin(ang) * 4], [tip[0] - nx * w * 0.4, tip[1] - ny * w * 0.4], [hand[0] - nx * w, hand[1] - ny * w]]),
line([hand[0] + nx * 6, hand[1] + ny * 6], [hand[0] - nx * 6, hand[1] - ny * 6], 1.4)];
};
if (sword) d.push(...blade(j[sword.hand], sword.ang, sword.len || 44, 1.9));
if (dagger) d.push(...blade(j[dagger.hand], dagger.ang, dagger.len || 16, 1.6));
return d;
}
const FIGURES = {
// your squadmate, braced, sword raised high
defender: () => cadet({ face: 1, head: [42, 30], neck: [44, 42], hip: [46, 84], lKnee: [36, 106], lFoot: [28, 130], rKnee: [58, 104], rFoot: [64, 130],
lElbow: [56, 50], lHand: [62, 34], rElbow: [56, 56], rHand: [62, 38] }, { sword: { hand: "lHand", ang: -1.15, len: 46 } }),
// the bigger bully, lunging with a sword
lunging: () => cadet({ face: -1, head: [56, 34], neck: [54, 46], hip: [58, 86], lKnee: [42, 104], lFoot: [30, 130], rKnee: [70, 108], rFoot: [82, 130],
lElbow: [40, 56], lHand: [26, 60], rElbow: [44, 60], rHand: [30, 64] }, { sword: { hand: "lHand", ang: Math.PI + 0.12, len: 42 }, size: 1.12 }),
// the smaller bully, dagger raised to throw
throwing: () => cadet({ face: -1, head: [50, 46], neck: [50, 57], hip: [52, 92], lKnee: [42, 110], lFoot: [36, 130], rKnee: [62, 110], rFoot: [68, 130],
lElbow: [40, 66], lHand: [36, 80], rElbow: [64, 52], rHand: [70, 38] }, { dagger: { hand: "rHand", ang: -0.9 }, size: 0.88 }),
// the wounded cadet, lying on the ground, a belt tied above the knee
lying: () => {
const d = cadet({ face: 1, head: [16, 118], neck: [26, 120], hip: [62, 122], lKnee: [80, 116], lFoot: [96, 126], rKnee: [80, 126], rFoot: [84, 128],
lElbow: [34, 108], lHand: [40, 96], rElbow: [38, 128], rHand: [52, 130] }, { cloak: false });
d.push(poly([[2, 132], [98, 132], [96, 136], [4, 136]])); // the ground line
return d;
},
// a thorn bush: arching branches with thorns and a few leaves
thorns: () => {
const d = [], R = (() => { let s = 7; return () => ((s = (s * 1103515245 + 12345) % 2147483648) / 2147483648); })();
// a low mound of leaves, then arching thorny canes
[[22, 128, 18, 9], [50, 124, 24, 12], [78, 128, 18, 9], [36, 118, 14, 8], [64, 118, 14, 8]].forEach(([x, y, rx, ry]) => d.push(ell(x, y, rx, ry, 0)));
for (let k = 0; k < 11; k++) {
const a = Math.PI * (0.08 + 0.84 * (k / 10)) + (R() - 0.5) * 0.2, len = 50 + R() * 34;
const sx = 50 + (R() - 0.5) * 24, sy = 124;
const ex = sx - Math.cos(a) * len, ey = sy - Math.sin(a) * len * 0.95;
const b = [[sx, sy], [sx - Math.cos(a) * len * 0.35, sy - Math.sin(a) * len * 0.75], [ex + Math.cos(a) * 6, ey - 10], [ex, ey + 4]];
d.push(tube(b, 2.6, 0.8, 18));
bez(b, 12).slice(2, -1).forEach((p, i) => {
const side = i % 2 ? 1 : -1, l = 3.5 + R() * 3;
d.push(poly([[p[0] - 1.2, p[1]], [p[0] + side * l, p[1] - l * 0.7], [p[0] + 1.2, p[1]]]));
if (i % 3 === 1) d.push(ell(p[0] - side * 5, p[1] - 1, 4.2, 2.2, side * 0.6));
});
}
return d;
},
};
const fcache = {};
/** SVG markup for a figure (cadets, the thorn bush) in one ink colour. */
function figure(name, { fill = "#3b2416", flip = false } = {}) {
if (!fcache[name]) fcache[name] = FIGURES[name]();
const tf = flip ? ' transform="translate(100 0) scale(-1 1)"' : "";
return `<g${tf}><g fill="${fill}">${fcache[name].map((d) => `<path d="${d}"/>`).join("")}</g></g>`;
}
return { svg, figure, poses: Object.keys(POSES), figures: Object.keys(FIGURES) };
});