Files

185 lines
16 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* valley.js — the watercolour valley map.
* Places, the painted ground, and their names; explorer.js draws routes and traffic on top. How many riders
* reached each place and walked each step is counted in Python (analysis/stats/site_stats.py). */
(function () {
"use strict";
const $ = (q, el = document) => el.querySelector(q);
const $$ = (q, el = document) => [...el.querySelectorAll(q)];
const NS = "http://www.w3.org/2000/svg";
const cssVar = (n) => getComputedStyle(document.documentElement).getPropertyValue(n).trim();
const esc = (x) => String(x ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]));
const pct = (p, d = 0) => (p === null || p === undefined || isNaN(p) ? "–" : (p * 100).toFixed(d) + "%");
const DV = { Red: "--dr-red", Green: "--dr-green", Orange: "--dr-orange", Brown: "--dr-brown", Blue: "--dr-blue", Black: "--dr-black" };
// painted-map dragon inks (darker than the UI tones so they read on gold paper)
// chosen so every pair stays distinguishable under common colour-vision deficiencies (docs/COLOURS.md)
const INK = { Red: "#cc3346", Green: "#2f8f6f", Orange: "#e08a2a", Brown: "#4e3020", Blue: "#2a58b8", Black: "#22182a" };
const PAPER = { ink: "#3b2416", halo: "#f6e6c4", trailLow: "#8a6446", death: "#c4471c" };
function el(tag, attrs = {}, parent) {
const e = document.createElementNS(NS, tag);
for (const [k, v] of Object.entries(attrs)) if (v !== null && v !== undefined) e.setAttribute(k, v);
if (parent) parent.appendChild(e);
return e;
}
function rgb(c) {
c = (c || "").trim();
if (c.startsWith("#")) { const h = c.length === 4 ? [...c.slice(1)].map((x) => x + x).join("") : c.slice(1); return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16)); }
const m = c.match(/\d+(\.\d+)?/g); return m ? m.slice(0, 3).map(Number) : [128, 128, 128];
}
const mix = (a, b, t) => { const A = rgb(a), B = rgb(b); return `rgb(${A.map((v, i) => Math.round(v + (B[i] - v) * t)).join(",")})`; };
function rng(seed) { let s = seed >>> 0; return () => ((s = (s * 1664525 + 1013904223) >>> 0) / 4294967296); }
// ------------------------------------------------------------ places
// kind: start | way (a choice point) | dragon (a dragon is met here) | small (a choice made here)
const L = {
"comp:Alone": { x: 500, y: 736, name: "Alone", kind: "start", lab: "below", desc: "Enter the valley alone. The most common start, and the one that survives most often." },
"comp:1 Squadmate": { x: 380, y: 740, name: "One squadmate", kind: "start", lab: "below", desc: "Enter with one squadmate. You can later leave them and go on alone." },
"comp:2 Squadmates": { x: 620, y: 740, name: "Two squadmates", kind: "start", lab: "below", desc: "Enter with two squadmates. The first dragon is often deadlier for a group." },
"dir:West": { x: 190, y: 662, name: "West", sub: "toward the scent", kind: "way", lab: "left", desc: "Follow a scent west. A Brown, Green or Red finds you first." },
"dir:Center": { x: 500, y: 668, name: "Forest centre", kind: "way", lab: "right", desc: "Straight into the forest. Alone, a Red or a Brown finds you first." },
"dir:East": { x: 810, y: 662, name: "East", sub: "toward the roar", kind: "way", lab: "right", desc: "Toward the roar. Alone, a Red or an Orange finds you first. With one squadmate, a Green or an Orange." },
// first sightings (game roll)
"see:West:Red": { x: 110, y: 598, colour: "Red", kind: "dragon", first: true },
"see:West:Brown": { x: 185, y: 584, colour: "Brown", kind: "dragon", first: true },
"see:West:Green": { x: 262, y: 598, colour: "Green", kind: "dragon", first: true },
"see:Center:Red": { x: 448, y: 600, colour: "Red", kind: "dragon", first: true },
"see:Center:Brown": { x: 552, y: 600, colour: "Brown", kind: "dragon", first: true },
"see:East:Red": { x: 738, y: 598, colour: "Red", kind: "dragon", first: true },
"see:East:Orange": { x: 815, y: 584, colour: "Orange", kind: "dragon", first: true },
"see:East:Green": { x: 892, y: 598, colour: "Green", kind: "dragon", first: true },
scream: { x: 500, y: 512, name: "The scream", kind: "way", lab: "right", desc: "A scream in the trees. Help the squadmate fighting two cadets, walk away, or ignore it." },
bully: { x: 318, y: 462, name: "The bully fight", kind: "way", lab: "left", desc: "A squadmate is cornered by two cadets. Assess, even the numbers, or put yourself in the middle." },
"res:Killed the bullies yourself": { x: 222, y: 410, name: "Kill them", kind: "small", lab: "left", desc: "End the bullies yourself." },
"res:Squadmate's revenge": { x: 312, y: 398, name: "Squadmate's revenge", kind: "small", lab: "above", desc: "Let your squadmate take revenge." },
"res:Left bullies to the dragons": { x: 404, y: 410, name: "Dragons decide", kind: "small", lab: "right", desc: "Leave the bullies to the dragons." },
away: { x: 500, y: 440, name: "Walked away", kind: "small", lab: "right", desc: "Investigated the scream, then left them to it." },
wounded: { x: 684, y: 462, name: "The wounded cadet", kind: "way", lab: "right", desc: "Ignore the scream and you trip over a cadet missing a leg." },
"res:Tourniquet": { x: 616, y: 410, name: "Tourniquet", kind: "small", lab: "left", desc: "Use their belt as a tourniquet." },
"res:Left injured cadet": { x: 690, y: 398, name: "Leave them", kind: "small", lab: "above", desc: "Leave them to die." },
"res:Took their weapons": { x: 780, y: 410, name: "Take their weapons", kind: "small", lab: "right", desc: "Take their weapons and go." },
"fork:West": { x: 196, y: 336, name: "West fork", kind: "way", lab: "left", desc: "After the fight, the path splits: west." },
"fork:Forest": { x: 318, y: 318, name: "Deeper in", kind: "way", lab: "above", desc: "After the fight: deeper into the forest. Most recorded shadows came after this choice." },
"fork:East": { x: 432, y: 336, name: "East fork", kind: "way", lab: "right", desc: "After the fight, the path splits: east." },
hour: { x: 520, y: 272, name: "An hour's walk", sub: "the thorn", kind: "way", lab: "right", desc: "An hour of walking, and a thorn draws blood. No dragon bonds before this point." },
tree: { x: 316, y: 204, name: "The tallest tree", kind: "way", lab: "right", desc: "Climb for a view: a Red below, two Greens in a clearing and, very rarely, a shadow moving west." },
valley: { x: 694, y: 204, name: "Valley centre", kind: "way", lab: "left", desc: "Walk on to the valley centre." },
treeRed: { x: 168, y: 250, name: "The Red below", colour: "Red", kind: "dragon", lab: "left", desc: "Descend quickly onto a Red prowling under the tree. The hardest bond in the game." },
greens: { x: 124, y: 140, name: "Two Greens", colour: "Green", kind: "dragon", lab: "below", desc: "Two Greens in a clearing test you. A wrong answer sometimes brings an Orange or Brown to the rescue." },
stream: { x: 372, y: 142, name: "The shadow", sub: "a stream, a claw print", kind: "way", lab: "right", desc: "The rare third option at the tree. Follow the shadow west, past a stream and a claw print." },
redwood: { x: 452, y: 84, name: "Blue at the redwood", colour: "Blue", kind: "dragon", lab: "above", desc: "A Blue coiled around a redwood. Hold still and let it pass to reach the Black." },
black: { x: 262, y: 70, name: "Behind you", colour: "Black", kind: "dragon", lab: "left", desc: "A branch snaps behind you. Turn to face the threat." },
valleyRed: { x: 846, y: 250, name: "The valley Red", colour: "Red", kind: "dragon", lab: "below", desc: "A Red that has just incinerated another cadet. Most who choose to bond it succeed. Say it isn't your dragon to walk on to the meadow." },
meadow: { x: 742, y: 146, name: "The meadow", kind: "way", lab: "below", desc: "A meadow where an Orange and a Brown wait. Sometimes a Blue joins them." },
"meadow:Orange": { x: 652, y: 100, name: "Orange", colour: "Orange", kind: "dragon", lab: "left", desc: "The meadow Orange." },
"meadow:Brown": { x: 744, y: 80, name: "Brown", colour: "Brown", kind: "dragon", lab: "above", desc: "The meadow Brown." },
"meadow:Blue": { x: 836, y: 100, name: "Meadow Blue", colour: "Blue", kind: "dragon", lab: "right", desc: "The rare meadow Blue. Most riders who approach it are burned, even with the community's best answers." },
};
// routes described by the community that the form does not record
// the routes runs take through these places are counted in Python (analysis/stats/site_stats.py, place_path)
function defs(svg) {
const d = el("defs", {}, svg);
d.innerHTML = `
<linearGradient id="vm-sky" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="#f3d69c"/><stop offset="0.35" stop-color="#e9c88f"/><stop offset="0.7" stop-color="#d9b07a"/><stop offset="1" stop-color="#c8955f"/>
</linearGradient>
<radialGradient id="vm-sun" cx="0.62" cy="0.12" r="0.55"><stop offset="0" stop-color="#fff3d1" stop-opacity="0.9"/><stop offset="1" stop-color="#fff3d1" stop-opacity="0"/></radialGradient>
<radialGradient id="vm-vignette" cx="0.5" cy="0.5" r="0.72"><stop offset="0.6" stop-color="#2a0f1c" stop-opacity="0"/><stop offset="1" stop-color="#2a0f1c" stop-opacity="0.55"/></radialGradient>
<filter id="vm-wash" x="-10%" y="-10%" width="120%" height="120%">
<feTurbulence type="fractalNoise" baseFrequency="0.022" numOctaves="3" seed="4" result="n"/>
<feDisplacementMap in="SourceGraphic" in2="n" scale="16" xChannelSelector="R" yChannelSelector="G" result="d"/>
<feGaussianBlur in="d" stdDeviation="0.7"/>
</filter>
<filter id="vm-wash2" x="-10%" y="-10%" width="120%" height="120%">
<feTurbulence type="fractalNoise" baseFrequency="0.05" numOctaves="2" seed="9" result="n"/>
<feDisplacementMap in="SourceGraphic" in2="n" scale="8" xChannelSelector="R" yChannelSelector="G"/>
</filter>
<filter id="vm-brush" x="-5%" y="-5%" width="110%" height="110%">
<feTurbulence type="fractalNoise" baseFrequency="0.09" numOctaves="2" seed="3" result="n"/>
<feDisplacementMap in="SourceGraphic" in2="n" scale="4" xChannelSelector="R" yChannelSelector="G"/>
</filter>
<filter id="vm-paper" x="0" y="0" width="100%" height="100%">
<feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2" seed="1" result="g"/>
<feColorMatrix in="g" type="matrix" values="0 0 0 0 0.36 0 0 0 0 0.24 0 0 0 0 0.14 0 0 0 0.55 -0.18"/>
</filter>
<filter id="vm-haze"><feGaussianBlur stdDeviation="10"/></filter>`;
}
function blob(g, x, y, r, fill, op, R) {
// irregular canopy blob from a few overlapping circles
for (let i = 0; i < 3; i++) el("circle", { cx: x + (R() - 0.5) * r * 0.9, cy: y + (R() - 0.5) * r * 0.6, r: r * (0.6 + R() * 0.45), fill, "fill-opacity": op }, g);
}
function paint(svg) {
const R = rng(21);
el("rect", { x: 0, y: 0, width: 1000, height: 780, fill: "url(#vm-sky)" }, svg);
el("rect", { x: 0, y: 0, width: 1000, height: 780, fill: "url(#vm-sun)" }, svg);
// far ridge and hazy hills
const far = el("g", { filter: "url(#vm-wash)" }, svg);
let d = "M-20 120";
for (let x = -20; x <= 1020; x += 60) d += ` Q${x + 30} ${40 + R() * 40} ${x + 60} ${90 + R() * 40}`;
el("path", { d: d + " L1020 -10 L-20 -10 Z", fill: "#c99a72", "fill-opacity": 0.55 }, far);
el("path", { d: "M-20 150 Q200 90 420 140 T820 120 T1020 150 L1020 200 L-20 200 Z", fill: "#d4a677", "fill-opacity": 0.45 }, far);
// forest: three depth tiers of canopy washes, kept out of the clearings
const clear = [[742, 100, 150, 85], [124, 140, 92, 58], [694, 205, 80, 44], [520, 272, 70, 32], [846, 250, 70, 40], [500, 740, 190, 46], [318, 455, 120, 60], [684, 455, 120, 60], [500, 660, 80, 30]];
const inClear = (x, y) => clear.some(([cx, cy, rx, ry]) => ((x - cx) / rx) ** 2 + ((y - cy) / ry) ** 2 < 1);
const tiers = [
{ y0: 120, y1: 330, n: 150, r: [10, 20], cols: ["#b39a63", "#a99158"], op: 0.32 },
{ y0: 300, y1: 560, n: 170, r: [12, 24], cols: ["#8e8a54", "#7f7e4b"], op: 0.4 },
{ y0: 520, y1: 780, n: 170, r: [14, 30], cols: ["#6c6b40", "#5b5c37", "#6b5a35"], op: 0.45 },
];
tiers.forEach((t, ti) => {
const g = el("g", { filter: "url(#vm-wash)" }, svg);
// tall pale trunks, like a sunlit wood
for (let i = 0; i < t.n * 0.25; i++) {
const x = R() * 1000, y = t.y0 + R() * (t.y1 - t.y0);
if (inClear(x, y)) continue;
el("rect", { x, y: y - 50 - ti * 10, width: 2 + ti * 1.5, height: 60 + ti * 14, fill: "#7a5c3c", "fill-opacity": 0.18 + ti * 0.07 }, g);
}
for (let i = 0; i < t.n; i++) {
const x = R() * 1000, y = t.y0 + R() * (t.y1 - t.y0);
if (inClear(x, y)) continue;
blob(g, x, y, t.r[0] + R() * (t.r[1] - t.r[0]), t.cols[Math.floor(R() * t.cols.length)], t.op, R);
}
});
// clearings: warm ochre light
const cg = el("g", { filter: "url(#vm-wash)" }, svg);
clear.forEach(([cx, cy, rx, ry]) => el("ellipse", { cx, cy, rx: rx * 0.85, ry: ry * 0.8, fill: "#f0cf93", "fill-opacity": 0.55 }, cg));
// mist bands
const mg = el("g", { filter: "url(#vm-haze)" }, svg);
[[230, 0.35], [380, 0.2], [560, 0.18]].forEach(([y, o]) => el("rect", { x: -40, y, width: 1080, height: 26, fill: "#fbe9c4", "fill-opacity": o }, mg));
// the stream
const sg = el("g", { filter: "url(#vm-wash2)" }, svg);
const stream = "M560 -10 C 520 40, 470 70, 420 112 S 330 170, 270 150 S 170 120, 110 220 S 40 320, -10 350";
el("path", { d: stream, fill: "none", stroke: "#7fa3a6", "stroke-width": 13, "stroke-opacity": 0.65, "stroke-linecap": "round" }, sg);
el("path", { d: stream, fill: "none", stroke: "#cfe1dc", "stroke-width": 3, "stroke-opacity": 0.6, "stroke-linecap": "round" }, sg);
// rock outcrop for the valley Red, standing stones by the meadow
const rk = el("g", { filter: "url(#vm-wash2)" }, svg);
el("path", { d: "M800 272 L826 236 L862 230 L892 262 L880 284 L812 288 Z", fill: "#6e5c63", "fill-opacity": 0.75 }, rk);
el("path", { d: "M826 236 L862 230 L870 246 L834 252 Z", fill: "#9b8790", "fill-opacity": 0.6 }, rk);
// the tallest tree and the redwood
const big = el("g", { filter: "url(#vm-wash2)" }, svg);
el("rect", { x: 312, y: 150, width: 9, height: 70, fill: "#5a3f28", "fill-opacity": 0.85 }, big);
[[316, 150, 30], [302, 172, 22], [332, 168, 22], [316, 124, 22]].forEach(([x, y, r]) => el("circle", { cx: x, cy: y, r, fill: "#46502e", "fill-opacity": 0.75 }, big));
el("rect", { x: 446, y: 40, width: 11, height: 56, fill: "#8a4430", "fill-opacity": 0.85 }, big);
[[452, 40, 20], [440, 54, 14], [464, 54, 14]].forEach(([x, y, r]) => el("circle", { cx: x, cy: y, r, fill: "#3f4a2b", "fill-opacity": 0.7 }, big));
}
function overlay(svg) {
el("rect", { x: 0, y: 0, width: 1000, height: 780, filter: "url(#vm-paper)", opacity: 0.45, style: "mix-blend-mode:multiply", "pointer-events": "none" }, svg);
el("rect", { x: 0, y: 0, width: 1000, height: 780, fill: "url(#vm-vignette)", "pointer-events": "none" }, svg);
}
// tiny original winged glyph for dragon places
const WING = "M50 30 L18 6 L27 21 L3 16 L25 32 Z M50 30 L82 6 L73 21 L97 16 L75 32 Z M37 30 Q50 23 63 30 Q50 37 37 30 Z M63 30 L76 26 L80 28 L73 31 Z M37 30 Q24 37 10 34 Q22 33 36 31 Z";
// ------------------------------------------------------------ rendering
function curve(A, B, bend) {
const mx = (A.x + B.x) / 2, my = (A.y + B.y) / 2, dx = B.x - A.x, dy = B.y - A.y;
return `M${A.x} ${A.y} Q${mx - dy * bend} ${my + dx * bend} ${B.x} ${B.y}`;
}
function name(id) {
const P = L[id];
if (!P) return id;
if (P.first) { const [, d, c] = id.split(":"); return `${c} dragon (first sighting, ${d === "Center" ? "forest centre" : d.toLowerCase()})`; }
return P.name;
}
const paintBase = (svg) => { defs(svg); paint(svg); };
window.ValleyMap = { places: L, paintBase, finish: overlay, name, curve, INK, PAPER, WING };
})();