diff --git a/apps/atlas/dragons.js b/apps/atlas/dragons.js index 6d37509..420fc62 100644 --- a/apps/atlas/dragons.js +++ b/apps/atlas/dragons.js @@ -231,5 +231,78 @@ // one path per part: parts wind in different directions, so a single combined path would punch holes return `${p.d.map((d) => ``).join("")}`; } - return { svg, poses: Object.keys(POSES) }; + /* ---------- 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 `${fcache[name].map((d) => ``).join("")}`; + } + + return { svg, figure, poses: Object.keys(POSES), figures: Object.keys(FIGURES) }; }); diff --git a/apps/atlas/explorer.js b/apps/atlas/explorer.js index e51fc46..2199385 100644 --- a/apps/atlas/explorer.js +++ b/apps/atlas/explorer.js @@ -235,6 +235,30 @@ }); } + /* ---------- the people (and the thorn) of the valley ---------- */ + const SCENERY = [ + { at: "bully", fig: "defender", dx: 6, sc: 0.42, tip: "The bully fight", text: "Your squadmate holds off two cadets who have bullied them since Parapet. Help them, or walk away." }, + { at: "bully", fig: "lunging", dx: 30, sc: 0.42, tip: "The bully fight", text: "The bigger cadet swings a sword; the smaller one has a dagger ready to throw." }, + { at: "bully", fig: "throwing", dx: 58, sc: 0.42, tip: "The bully fight", text: "Assess first, even the numbers, or put yourself in the middle. Then decide the bullies' fate." }, + { at: "wounded", fig: "lying", dx: -72, dy: 4, sc: 0.56, tip: "The wounded cadet", text: "Ignore the scream and you find a badly wounded cadet. Tie a tourniquet, leave them, or take their weapons." }, + { at: "hour", fig: "thorns", dx: -66, dy: 6, sc: 0.44, tip: "An hour's walk", text: "No dragon for an hour, and a thorn cuts the back of your hand. Then: climb the tallest tree, or walk on to the valley centre." }, + ]; + function drawScenery(g, onRoute) { + SCENERY.forEach((sc) => { + const P = L[sc.at]; + if (!P) return; + const faded = st.colour && !onRoute.has(sc.at); + const x = P.x + (sc.dx || 0) - 50 * sc.sc, y = P.y + (sc.dy || 0) - 136 * sc.sc; + const gg = el("g", { class: "ex-scene", transform: `translate(${x} ${y}) scale(${sc.sc})`, opacity: faded ? 0.35 : 0.88 }, g); + gg.innerHTML = D.figure(sc.fig, { fill: sc.fig === "thorns" ? "#4a3a22" : PAPER.ink, flip: !!sc.flip }); + el("rect", { x: 0, y: 0, width: 100, height: 140, fill: "transparent" }, gg); + const html = `${esc(sc.tip)}
${esc(sc.text)}`; + gg.addEventListener("mouseenter", (e) => showTip(e, html)); + gg.addEventListener("mousemove", (e) => moveTip(e)); + gg.addEventListener("mouseleave", hideTip); + }); + } + function drawLandmarks(g, onRoute) { const ids = new Set(LANDMARKS); onRoute.forEach((id) => { if (L[id] && L[id].kind !== "dragon") ids.add(id); }); @@ -455,7 +479,7 @@ el("rect", { x: 0, y: 0, width: 1000, height: 790, fill: "#f6e6c4", "fill-opacity": st.colour ? 0.32 : 0.12 }, svg); const gTraffic = el("g", { filter: "url(#ex-brush)" }, svg); const gRoute = el("g", { filter: "url(#ex-brush)" }, svg); - const gLand = el("g", {}, svg), gDrag = el("g", {}, svg), gLab = el("g", {}, svg); + const gLand = el("g", {}, svg), gScene = el("g", {}, svg), gDrag = el("g", {}, svg), gLab = el("g", {}, svg); if (st.traffic) drawTraffic(gTraffic); let routes = [], onRoute = new Set(); if (st.colour && st.policy) { @@ -468,6 +492,7 @@ onRoute = drawRoutes(gRoute, gLab, routes); } drawLandmarks(gLand, onRoute); + drawScenery(gScene, onRoute); drawDragons(gDrag, !!st.colour); // the paper texture and vignette go on top const fin = document.createElementNS(NS, "svg");