Claude Fable 5.2max

scene.js

// 金屏風「土谷大地」— 絵そのもの
'use strict';
(function (F) { const G = typeof globalThis !== 'undefined' ? globalThis : this; F(G); (G.BYOBU_SRC = G.BYOBU_SRC || []).push(F); })(function (G) {
  const B = G.BYOBU;
  const { hex, mix, mix3, clamp, sstep, rng, hash2, vnoise, fbm, path, pathXY, at } = B;
  const { PW, PH } = B.dim;

  // ---------- 構図(cm) ----------
  // 稜線は x の関数。制御点を通る曲線を細かい表にしておく
  function ridge(pts) {
    const P = path(pts, 0.25);
    const x0 = pts[0][0], x1 = pts[pts.length - 1][0], N = Math.ceil((x1 - x0) / 0.1) + 1;
    const tab = new Float32Array(N).fill(1e9);
    let k = 0;
    for (let i = 0; i < N; i++) {
      const x = x0 + i * 0.1;
      while (k < P.n - 2 && P.x[k + 1] < x) k++;
      const f = clamp((x - P.x[k]) / (P.x[k + 1] - P.x[k] || 1), 0, 1);
      tab[i] = P.y[k] + (P.y[k + 1] - P.y[k]) * f;
    }
    return (x) => {
      if (x < x0 || x > x1) return 1e9;
      const g = (x - x0) / 0.1, i = Math.floor(g), f = g - i;
      return i + 1 < N ? tab[i] + (tab[i + 1] - tab[i]) * f : tab[N - 1];
    };
  }
  const R1 = ridge([[236, 112], [243, 94], [253, 76], [267, 62], [285, 56], [304, 60], [321, 71], [338, 84], [352, 100]]); // 奥の丘(朝日)
  const R2 = ridge([[140, 168], [168, 158], [196, 153], [216, 146], [233, 133], [249, 119], [268, 109], [288, 101], [306, 92], [321, 79], [333, 67], [347, 58], [366, 52]]); // 手前の土坡(春)
  const R3 = ridge([[-8, 101], [22, 97], [50, 98], [78, 104], [104, 115], [127, 130], [148, 144], [172, 154]]); // 秋の土坡
  const R4 = ridge([[-8, 124], [12, 120], [30, 123], [46, 132], [59, 145], [69, 160], [73, 172]]); // 雪の土坡
  const wobble = (R, sd, amp) => (x) => R(x) + (fbm(x * 0.09, sd * 1.7, 3, sd) - 0.5) * amp + (vnoise(x * 1.3, 0.5, sd + 1) - 0.5) * 0.2;
  const R1d = wobble(R1, 301, 1.3), R2d = wobble(R2, 311, 1.3), R3d = wobble(R3, 321, 1.3), R4d = wobble(R4, 331, 1.6);
  const SUN = { x: 271, y: 47, r: 13.5 }, MOON = { x: 71, y: 79, r: 25.5 };
  const STREAM = path([[334, 72], [320, 82], [303, 89], [284, 95], [264, 102], [246, 113], [231, 127], [210, 138], [184, 141], [158, 149], [139, 168]], 0.4);
  const streamHW = (u) => 1.4 + 14.5 * Math.pow(u, 1.15) + 1.6 * Math.exp(-((u - 0.72) * (u - 0.72)) / 0.02);
  // 手前の岸は土坡が決める。水の面は岸の下へもぐるように手前側へ広げておく
  const STREAM_BODY = (() => {
    const xs = [], ys = [];
    for (let i = 0; i < STREAM.n; i++) {
      const k = Math.min(STREAM.n - 2, i), tx = STREAM.x[k + 1] - STREAM.x[k], ty = STREAM.y[k + 1] - STREAM.y[k], l = Math.hypot(tx, ty) || 1;
      xs.push(STREAM.x[i] + (ty / l) * 2.6); ys.push(STREAM.y[i] - (tx / l) * 2.6);
    }
    return pathXY(xs, ys);
  })();
  // 流れの座標(u: 道のり 0..1、eta: 幅方向 -1..1、+ が奥の岸)→ 画面
  function streamPt(u, eta) {
    const c = at(STREAM, u), hw = streamHW(u);
    return [c.x - c.ty * eta * hw, c.y + c.tx * eta * hw];
  }
  B.geo = { R1, R2, R3, R4, R1d, R2d, R3d, R4d, SUN, MOON, STREAM, streamHW, streamPt };

  B.paint = function (E, opt) {
    opt = opt || {};
    const log = opt.log || (() => {});
    const S = E.S, px = E.px;
    E.hooks.moon = MOON;
    E.hooks.leafKind = (X, Y) => {
      if ((X - MOON.x) * (X - MOON.x) + (Y - MOON.y) * (Y - MOON.y) < MOON.r * MOON.r) return 1;
      if ((X - SUN.x) * (X - SUN.x) + (Y - SUN.y) * (Y - SUN.y) < SUN.r * SUN.r && Y < R1d(X)) return 2;
      return 0;
    };
    E.hooks.relief = (X, Y) => {
      const d = Math.hypot(X - SUN.x, Y - SUN.y);
      if (d > SUN.r || Y > R1d(X) + 0.1) return 0;
      const q = d / SUN.r;
      return 0.14 * sstep(SUN.r, SUN.r - 0.5, d) + 0.85 * Math.sqrt(1 - q * q * 0.96) * sstep(1, 0.9, q);
    };
    // 空に霞のようにたなびく切箔・砂子
    E.hooks.sprinkle = (X, Y) => {
      if (Y > 62 || X < 88 || X > 304) return 0;
      const y1 = 21 + 5 * Math.sin(X / 47 + 0.6) + 3 * Math.sin(X / 19), y2 = 40 + 4 * Math.sin(X / 38 + 2.2);
      const e1 = Math.exp(-Math.pow((Y - y1) / 5.5, 2)) * sstep(92, 150, X) * (1 - sstep(236, 300, X));
      const e2 = Math.exp(-Math.pow((Y - y2) / 4, 2)) * sstep(128, 176, X) * (1 - sstep(214, 262, X)) * 0.8;
      if (e1 + e2 < 0.01) return 0;
      return clamp((e1 + e2) * (0.3 + 1.2 * fbm(X / 13, Y / 5, 3, 221)), 0, 1);
    };
    // 飾り金具:四隅と折れ目の上下
    {
      const { EXT, FUCHI, PANEL } = B.dim, L = 10.5;
      const plate = (s, q, len) => {
        // s:金具の付け根からの距離、q:椽の幅方向 0..1。先は剣先のように尖る
        const end = len - 1.9 * Math.pow(Math.abs(2 * q - 1), 1.5);
        if (s > end || s < 0) return 0;
        const eb = Math.min(q, 1 - q) * FUCHI, ee = end - s;
        const edge = Math.min(eb, ee * 0.8);
        if (edge > 0.2 && edge < 0.34) return 1.5;
        return 1;
      };
      const nail = (dx, dy) => (dx * dx + dy * dy < 0.3 * 0.3 ? 2.5 : 0);
      E.hooks.fitting = (X, Y, q) => {
        const top = Y < 0, bot = Y > PH, left = X < 0, right = X > PW;
        const horiz = Math.max(-Y, Y - PH) >= Math.max(-X, X - PW);
        const yc = top ? -(EXT - FUCHI / 2) : PH + EXT - FUCHI / 2, xc = left ? -(EXT - FUCHI / 2) : PW + EXT - FUCHI / 2;
        let f = 0;
        if (horiz) {
          const sL = X + EXT, sR = PW + EXT - X;
          f = Math.max(plate(sL, q, L), plate(sR, q, L));
          if (f > 0) f = Math.max(f, nail(sL - 3.2, Y - yc), nail(sL - 7, Y - yc), nail(sR - 3.2, Y - yc), nail(sR - 7, Y - yc));
          for (let k = 1; k <= 5; k++) {
            const d = Math.abs(X - k * PANEL);
            if (d < 5 && d > 0.06) { const g = plate(d, q, 4.4); if (g > 0) f = Math.max(f, g, nail(d - 1.6, Y - yc)); }
          }
        } else {
          const sT = Y + EXT, sB = PH + EXT - Y;
          f = Math.max(plate(sT, q, L), plate(sB, q, L));
          if (f > 0) f = Math.max(f, nail(X - xc, sT - 3.2), nail(X - xc, sT - 7), nail(X - xc, sB - 3.2), nail(X - xc, sB - 7));
        }
        return f;
      };
    }
    const stages = [];
    const stage = (name, fn) => stages.push([name, fn]);

    const grain = (X, Y) => vnoise(X * 13, Y * 13, 5) * 0.6 + vnoise(X * 31, Y * 31, 6) * 0.4;
    const C = (h) => hex(h);
    const set = (o, c, k) => { o.r = c[0] * k; o.g = c[1] * k; o.b = c[2] * k; };

    // ---------- 土坡(たらし込み) ----------
    // 岩絵具の面に、濡れているうちに落とした絵具のにじみ(輪の縁に絵具がたまる)を置く
    function mound(R, x0, x1, yTop, P) {
      const sd = P.seed, rnd = rng(sd * 7 + 1);
      const blobs = [];
      for (let i = 0; i < P.nBlob; i++) {
        const bx = rnd.range(x0 + 3, x1 - 3), rr = rnd.range(P.blobR[0], P.blobR[1]);
        const sl = Math.atan((R(bx + 2) - R(bx - 2)) / 4) * 0.8;
        const by = R(bx) + rr * 0.8 + Math.pow(rnd(), 1.3) * P.depth;
        blobs.push({ x: bx, y: by, r: rr, ax: rnd.range(1.3, 2.2), dark: rnd() < P.darkP, s: rnd.int(1, 9999), c: Math.cos(sl), sn: Math.sin(sl), k: rnd.range(0.6, 1) });
      }
      const clip = P.clip;
      E.region(x0, yTop, x1, PH, (o, X, Y) => {
        const d = Y - R(X);
        if (d < -px) return;
        let cov = clamp(d * S + 0.5, 0, 1);
        if (clip) cov *= clamp((clip(X) + 0.5 - Y) * S, 0, 1);
        if (cov < 0.003) return;
        const gr = grain(X, Y);
        // 面のゆるいむら(稜線に沿って流れる)
        const wx = fbm(X / 19, d / 13, 3, sd + 2) - 0.5, wy = fbm(X / 19 + 7.7, d / 13 + 3.1, 3, sd + 3) - 0.5;
        const n1 = fbm((X + wx * 20) / 46, (d + wy * 16) / 21, 3, sd + 4);
        const k1 = sstep(0.28, 0.72, n1);
        let r = mix(P.gA[0], P.gB[0], k1), g = mix(P.gA[1], P.gB[1], k1), b = mix(P.gA[2], P.gB[2], k1);
        // にじみ
        let light = 0, dark = 0, ring = 0;
        for (let q = 0; q < blobs.length; q++) {
          const bl = blobs[q], ex = X - bl.x, ey = Y - bl.y;
          const lx = (ex * bl.c + ey * bl.sn) / (bl.r * bl.ax), ly = (-ex * bl.sn + ey * bl.c) / bl.r;
          const q2 = lx * lx + ly * ly;
          if (q2 > 3.2) continue;
          const w = 0.66 + 0.68 * fbm(X / (bl.r * 0.62), Y / (bl.r * 0.62), 3, bl.s) + (vnoise(X * 1.9, Y * 1.9, bl.s + 3) - 0.5) * 0.07;
          const t = Math.sqrt(q2) / w;
          if (t > 1.5) continue;
          const inside = 1 - sstep(0.9, 1.0, t);
          const core = inside * (0.55 + 0.45 * sstep(0.2, 0.95, t)) * bl.k; // 中心ほど薄く、縁に寄る
          const rim = Math.exp(-Math.pow((t - 0.975) / 0.028, 2)) * bl.k;
          if (bl.dark) dark = Math.max(dark, core); else light = Math.max(light, core * (0.3 + 0.7 * fbm(X / 2.3, Y / 2.3, 3, bl.s + 5)));
          ring = Math.max(ring, rim);
          dark = Math.max(dark, (1 - inside) * sstep(1.5, 1.0, t) * 0.18);
        }
        r = mix(r, P.light[0], light * P.lightK); g = mix(g, P.light[1], light * P.lightK); b = mix(b, P.light[2], light * P.lightK);
        const rk = P.ringK == null ? 0.5 : P.ringK;
        r = mix(r, P.dark[0], dark * 0.55); g = mix(g, P.dark[1], dark * 0.55); b = mix(b, P.dark[2], dark * 0.55);
        r = mix(r, P.dark[0], ring * rk); g = mix(g, P.dark[1], ring * rk); b = mix(b, P.dark[2], ring * rk);
        // 下塗りののぞく所:稜線のきわと、ところどころの薄塗り
        const thinN = fbm((X - wy * 12) / 15, (d + wx * 10) / 8, 4, sd + 6) + (fbm(X / 2.2, Y / 2.2, 2, sd + 5) - 0.5) * 0.12;
        const top = Math.exp(-d / P.topBand) * (0.55 + 0.9 * vnoise(X * 0.12, 2.5, sd + 7));
        let thin = clamp(sstep(P.thin, P.thin + 0.1, thinN) * 0.85 + top, 0, 1) * (1 - light * 0.7);
        thin *= 0.8 + 0.4 * gr;
        const wn = fbm(X / 6, Y / 6, 3, sd + 8);
        const wk = sstep(0.3, 0.8, wn);
        const wr = mix(P.wash[0], P.dark[0], wk), wg = mix(P.wash[1], P.dark[1], wk), wb = mix(P.wash[2], P.dark[2], wk);
        r = mix(r, wr, thin); g = mix(g, wg, thin); b = mix(b, wb, thin);
        // 筆の走り
        const br = 0.94 + 0.12 * fbm(X / 34, d / 1.1, 2, sd + 12);
        const tone = (0.9 + 0.2 * gr) * br;
        o.r = r * tone; o.g = g * tone; o.b = b * tone;
        let a = mix(0.985, P.washA * (0.7 + 0.5 * wn), thin);
        // 稜線の墨のきわ
        const line = Math.exp(-d / 0.3) * sstep(0.2, 0.5, vnoise(X * 0.3, 1.5, sd + 9) + 0.2);
        o.r = mix(o.r, P.dark[0] * 0.7, line * 0.6); o.g = mix(o.g, P.dark[1] * 0.7, line * 0.6); o.b = mix(o.b, P.dark[2] * 0.7, line * 0.6);
        a = Math.max(a, line * 0.9);
        // 粒の粗い所と剥落
        if (gr > 0.84) a *= 1 - (gr - 0.84) * 1.3;
        const fl = vnoise(X * 4.1, Y * 4.1, sd + 11);
        if (fl > 0.94) a *= 1 - sstep(0.94, 0.975, fl) * 0.8;
        if (P.fade) a *= 1 - sstep(P.fade[0], P.fade[1], d + (fbm(X / 8, Y / 8, 3, sd + 13) - 0.5) * 9);
        o.a = cov * clamp(a, 0, 1);
        o.h = 0.006 + (1 - thin) * (0.026 + 0.02 * gr) + ring * 0.012 + light * 0.008;
      });
    }
    const M_FAR = { seed: 301, wash: C('#7a6a3e'), dark: C('#3d4a3a'), washA: 0.5, gA: C('#6ea88c'), gB: C('#559178'), light: C('#b4d4bd'), lightK: 0.3, thin: 0.7, topBand: 0.7, nBlob: 4, blobR: [3.5, 8], depth: 26, darkP: 0.35, clip: R2d };
    const M_SPRING = { seed: 311, wash: C('#5e4c2a'), dark: C('#1f3a30'), washA: 0.6, gA: C('#3f8f6a'), gB: C('#2d7359'), light: C('#9ccaa6'), lightK: 0.42, thin: 0.75, topBand: 0.9, nBlob: 18, blobR: [4, 11], depth: 60, darkP: 0.6 };
    const M_AUTUMN = { seed: 321, wash: C('#7d5526'), dark: C('#3c2a16'), washA: 0.62, gA: C('#b5913f'), gB: C('#8f8a40'), light: C('#d8b85c'), lightK: 0.6, thin: 0.63, topBand: 1.0, nBlob: 12, blobR: [4, 12], depth: 46, darkP: 0.5, ringK: 0.3 };

    stage('m1', () => mound(R1d, 230, 356, 48, M_FAR));
    stage('m3', () => mound(R3d, 0, 172, 88, M_AUTUMN));

    // ---------- 秋の土坡の左の肩に積もりはじめた雪 ----------
    stage('hadare', () => {
      const cW = C('#f6f3eb'), cSh = C('#c9d0d8');
      E.region(0, 92, 66, 126, (o, X, Y) => {
        const d = Y - R3d(X);
        if (d < -px) return;
        // 左ほど厚く、右へ行くと途切れて消える
        const n1 = fbm(X / 6.5, 1.3, 3, 341), n2 = fbm(X / 1.9, Y / 1.9, 2, 342);
        const band = (9.5 * (1 - sstep(4, 58, X)) + 1.2) * (0.25 + 1.3 * n1) - sstep(30, 60, X) * 2.6;
        const e = band - d + (n2 - 0.5) * 0.7;
        if (e < 0) return;
        const gr = grain(X, Y), body = sstep(0, 1.6, e), t = 0.95 + 0.08 * gr;
        const sh = 0.5 * (1 - body) + 0.12;
        o.r = mix(cW[0], cSh[0], sh) * t; o.g = mix(cW[1], cSh[1], sh) * t; o.b = mix(cW[2], cSh[2], sh) * t;
        o.a = clamp(d * S + 0.5, 0, 1) * sstep(0, 0.12, e) * (0.9 + 0.1 * body) * (gr > 0.92 && body < 0.5 ? 0.6 : 1);
        o.h = 0.02 + 0.07 * body;
      });
    });

    // ---------- 雪の土坡 ----------
    stage('m4', () => {
      const cW = C('#f7f4ec'), cSh = C('#bcc7d3');
      E.region(0, 108, 80, PH, (o, X, Y) => {
        const d = Y - R4d(X);
        if (d < -px) return;
        const cov = clamp(d * S + 0.5, 0, 1);
        const n1 = fbm(X / 24, Y / 17, 3, 332), n2 = fbm(X / 5, Y / 4, 3, 333), gr = grain(X, Y);
        // 光は左上から。丸みの右下へ回るほど淡い青の陰
        const side = sstep(22, 78, X + (Y - 122) * 0.5 + (n1 - 0.5) * 26);
        const hollow = sstep(0.5, 0.78, n1) * 0.22;
        const shd = clamp(side * 0.4 + hollow, 0, 0.62);
        const k = 0.95 + 0.08 * gr;
        o.r = mix(cW[0], cSh[0], shd) * k; o.g = mix(cW[1], cSh[1], shd) * k; o.b = mix(cW[2], cSh[2], shd) * k;
        const edge = sstep(0, 1.6, d);
        o.a = cov * (0.94 + 0.06 * edge) * (gr > 0.9 && d < 1.8 ? 0.6 : 1);
        o.h = 0.02 + 0.085 * edge * (0.85 + 0.3 * n2) + 0.05 * n1;
      });
    });

    // ---------- 流水 ----------
    const bankClip = (X, Y) => clamp((R2d(X) + 0.5 - Y) * S, 0, 1);
    stage('stream', () => {
      const cDeep = C('#17306f'), cMid = C('#2548a0'), cLight = C('#3f66b8'), cGreenish = C('#1f5a93');
      const Lc = STREAM.len;
      E.stroke(STREAM_BODY, (u) => streamHW(u) + 2.6, (o, u, v, X, Y) => {
        const hwb = streamHW(u) + 2.6, dFar = (1 - v) * hwb, a = u * Lc, bb = v * hwb;
        const n1 = fbm(a / 26 + bb / 60, bb / 4.2, 4, 201), n2 = fbm(a / 13, bb / 3.2, 3, 202), gr = grain(X, Y);
        const k1 = sstep(0.3, 0.72, n1);
        let r = mix(cDeep[0], cMid[0], k1), g = mix(cDeep[1], cMid[1], k1), b = mix(cDeep[2], cMid[2], k1);
        const k2 = sstep(0.56, 0.86, n2) * 0.4;
        r = mix(r, cLight[0], k2); g = mix(g, cLight[1], k2); b = mix(b, cLight[2], k2);
        const k3 = sstep(0.55, 0.8, fbm(a / 40, bb / 9, 3, 204)) * 0.35;
        r = mix(r, cGreenish[0], k3); g = mix(g, cGreenish[1], k3); b = mix(b, cGreenish[2], k3);
        // 岸のきわに絵具がたまる
        const en = (vnoise(a * 0.9, 3.1, 203) - 0.5) * 0.3 + (vnoise(a * 4, 1.7, 205) - 0.5) * 0.1;
        const pool = Math.exp(-Math.max(0, dFar + en) / 0.3);
        const t = (0.86 + 0.24 * gr) * (1 - pool * 0.3);
        o.r = r * t; o.g = g * t; o.b = b * t;
        let al = sstep(0, 0.14, dFar + en + 0.05);
        const fl = vnoise(X * 4.7, Y * 4.7, 206);
        if (fl > 0.94) al *= 1 - sstep(0.94, 0.975, fl) * 0.75;
        if (gr > 0.86) al *= 0.86;
        o.a = al * bankClip(X, Y);
        o.h = 0.03 + 0.012 * gr + pool * 0.012;
      });
    });
    stage('lines', () => {
      const rnd = rng(77), Lc = STREAM.len;
      const gold = C('#d2a850');
      const lanes = [[0, 1.2]];
      for (const e of [-0.5, 0.5]) lanes.push([e, 2.7]);
      for (const e of [-0.75, -0.25, 0.25, 0.75]) lanes.push([e, 5.4]);
      for (const e of [-0.875, -0.625, -0.375, -0.125, 0.125, 0.375, 0.625, 0.875]) lanes.push([e, 10]);
      const shade = (o, u, v, X, Y) => {
        const gr = grain(X, Y), k = 0.86 + 0.28 * gr;
        o.r = gold[0] * k; o.g = gold[1] * k; o.b = gold[2] * k;
        o.a = (0.95 - sstep(0.75, 1, gr) * 0.35) * bankClip(X, Y); o.m = 1; o.h = 0.012;
      };
      const wob = (s, e) => 0.05 * Math.sin(s / 7.3 + e * 2.3) + 0.028 * Math.sin(s / 3.1 + e * 4.6 + 1.3) + 0.02 * Math.sin(s / 15 + e * 1.1 + 4);
      const lanePt = (q, eta) => streamPt(q / Lc, (eta + wob(q, eta)) * 0.93);
      // 渦:流れてきた線が巻きこむ
      const eddies = [];
      for (const [u, eta, r, dir] of [[0.33, 0.3, 1.5, 1], [0.47, -0.2, 2.1, -1], [0.58, 0.45, 2.5, 1], [0.66, -0.38, 2.7, -1], [0.75, 0.12, 3.1, 1], [0.83, 0.55, 2.6, -1], [0.88, -0.3, 3.0, 1], [0.95, 0.2, 2.8, -1]]) {
        const c = streamPt(u, eta), f = at(STREAM, u);
        eddies.push({ u, eta, r, dir, x: c[0], y: c[1], fx: f.tx, fy: f.ty });
      }
      const inEddy = (x, y) => { for (const e of eddies) if ((x - e.x) * (x - e.x) + (y - e.y) * (y - e.y) < e.r * e.r * 1.75) return true; return false; };
      const drawLine = (xs, ys, w0) => {
        if (xs.length < 5) return;
        const ph = rnd.range(0, 9);
        E.stroke(pathXY(xs, ys), (t) => w0 * Math.pow(Math.sin(Math.PI * clamp(t, 0.004, 0.996)), 0.4) * (0.86 + 0.2 * Math.sin(t * 13 + ph)), shade);
      };
      for (const [eta, minHW] of lanes) {
        let u0 = 0;
        while (u0 < 1 && streamHW(u0) < minHW) u0 += 0.002;
        let s = u0 * Lc + rnd.range(0, 4);
        while (s < Lc - 2) {
          const len = rnd.range(16, 52), s1 = Math.min(Lc, s + len), w0 = rnd.range(0.1, 0.15);
          let xs = [], ys = [];
          for (let q = s; q <= s1; q += 0.35) {
            const p = lanePt(q, eta);
            if (inEddy(p[0], p[1])) { drawLine(xs, ys, w0); xs = []; ys = []; continue; }
            xs.push(p[0]); ys.push(p[1]);
          }
          drawLine(xs, ys, w0);
          s = s1 + rnd.range(1.6, 5.5);
        }
      }
      for (const e of eddies) {
        // 渦の入口へ、上流から流れに沿って入ってくる
        const hw = streamHW(e.u), side = -e.dir;
        const xs = [], ys = [];
        const lead = rnd.range(9, 20), sE = e.u * Lc;
        // 入口の点:中心から流れに直交して r だけ寄った所
        const ex = e.x + e.dir * e.fy * e.r, ey = e.y - e.dir * e.fx * e.r;
        const etaIn = e.eta + (side * e.r) / hw;
        for (let q = sE - lead; q < sE - 0.2; q += 0.35) {
          const k = sstep(sE - 4, sE, q);
          const p = streamPt(q / Lc, mix((etaIn + wob(q, etaIn)) * 0.93, etaIn, k));
          xs.push(mix(p[0], ex, k * k * (q > sE - 1 ? 1 : 0.0) ) ); ys.push(mix(p[1], ey, k * k * (q > sE - 1 ? 1 : 0.0)));
        }
        const th0 = Math.atan2(-e.dir * e.fx, e.dir * e.fy);
        const turns = rnd.range(1.25, 1.6);
        for (let k = 0; k <= 60; k++) {
          const t = k / 60, th = th0 + e.dir * t * turns * 2 * Math.PI, rad = e.r * (1 - 0.86 * Math.pow(t, 0.8));
          xs.push(e.x + Math.cos(th) * rad); ys.push(e.y + Math.sin(th) * rad);
        }
        const w0 = rnd.range(0.11, 0.15);
        E.stroke(pathXY(xs, ys), (t) => w0 * Math.pow(Math.sin(Math.PI * clamp(t * 0.93 + 0.004, 0.004, 0.996)), 0.4), shade);
        // 渦の外を回りこむ連れの線
        const xs2 = [], ys2 = [];
        for (let k = 0; k <= 40; k++) {
          const t = k / 40, th = th0 + e.dir * (-0.5 + t * 1.25) * Math.PI, rad = e.r * (1.5 + 0.9 * Math.pow(Math.abs(t - 0.4) / 0.6, 2));
          xs2.push(e.x + Math.cos(th) * rad * (1 + 0.0)); ys2.push(e.y + Math.sin(th) * rad);
        }
        E.stroke(pathXY(xs2, ys2), (t) => w0 * 0.9 * Math.pow(Math.sin(Math.PI * clamp(t, 0.004, 0.996)), 0.5), shade);
      }
    });
    stage('m2', () => mound(R2d, 136, 360, 44, M_SPRING));
    B.plants(E, stage, { grain, C });

    const only = opt.only ? opt.only.split(',') : null;
    let k = 0;
    for (const [name, fn] of stages) {
      if (only && !only.includes(name)) continue;
      fn();
      log(name);
      if (opt.onStage) opt.onStage(name, ++k, stages.length);
      if (opt.until === name) break;
    }
  };
});