Skip to content

Claude Code skill that makes launch videos, ads and music videos from one line: idea, script, visuals, voice, music, edit and review, then a review room where your notes make the next take

21.6 KB
Raw Blame
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>html,body{margin:0;padding:0;background:#ECE8DC}#c{display:block}</style>
</head>
<body>
<canvas id="c" width="1280" height="720"></canvas>
<script>
'use strict';
const W = 1280, H = 720;
const cv = document.getElementById('c');
const ctx = cv.getContext('2d');

// ---------- seeded RNG ----------
function mulberry32(seed) {
  let a = seed >>> 0;
  return function () {
    a |= 0; a = (a + 0x6D2B79F5) | 0;
    let t = Math.imul(a ^ (a >>> 15), 1 | a);
    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}
let R = mulberry32(1);
const rnd = (a = 1, b) => (b === undefined ? R() * a : a + R() * (b - a));
const pick = arr => arr[Math.floor(R() * arr.length)];

// ---------- crayon box ----------
const PAPER = '#EFEAD9';
const PEN = '#2B3A7E';       // blue ballpoint
const TEAL = '#2E7F72';      // teal green crayon
const TEAL_D = '#1F5F55';    // pressed harder
const ORANGE = '#E2762B';
const MARIGOLD = '#E8B23A';
const RED = '#C8452E';
const BROWN = '#7A5433';
const BLACK = '#26221F';

// ---------- grain tile (paper tooth, fixed seed => same wax texture every run) ----------
const grainTile = (() => {
  const g = mulberry32(7);
  const t = document.createElement('canvas');
  t.width = t.height = 256;
  const tc = t.getContext('2d');
  const img = tc.createImageData(256, 256);
  // blocky low-res layer for clumping
  const blocks = [];
  for (let i = 0; i < 64 * 64; i++) blocks.push(g());
  for (let y = 0; y < 256; y++) {
    for (let x = 0; x < 256; x++) {
      const i = (y * 256 + x) * 4;
      const fine = g();
      const block = blocks[(y >> 2) * 64 + (x >> 2)];
      let v = 0.45 + 0.55 * (fine * 0.55 + block * 0.45);
      if (g() < 0.10) v *= 0.30; // valleys where the wax skips
      img.data[i] = 0; img.data[i + 1] = 0; img.data[i + 2] = 0;
      img.data[i + 3] = Math.floor(255 * Math.min(1, v));
    }
  }
  tc.putImageData(img, 0, 0);
  return t;
})();

// ---------- crayon layer (draw strokes on scratch, keep only where grain has tooth) ----------
const S = document.createElement('canvas'); S.width = W; S.height = H;
const sc = S.getContext('2d');
const grainPat = sc.createPattern(grainTile, 'repeat');
let target = ctx;
function beginCrayon() { sc.clearRect(0, 0, W, H); target = sc; }
function endCrayon(alpha = 1) {
  sc.globalCompositeOperation = 'destination-in';
  sc.fillStyle = grainPat;
  sc.fillRect(0, 0, W, H);
  sc.globalCompositeOperation = 'source-over';
  ctx.globalAlpha = alpha;
  ctx.drawImage(S, 0, 0);
  ctx.globalAlpha = 1;
  target = ctx;
}

// ---------- polyline helpers ----------
function resample(pts, step) {
  const out = [pts[0]];
  let rest = 0;
  for (let i = 1; i < pts.length; i++) {
    let [x0, y0] = pts[i - 1], [x1, y1] = pts[i];
    const dx = x1 - x0, dy = y1 - y0;
    const len = Math.hypot(dx, dy);
    if (len < 1e-6) continue;
    let d = step - rest;
    while (d <= len) {
      out.push([x0 + dx * d / len, y0 + dy * d / len]);
      d += step;
    }
    rest = len - (d - step);
  }
  out.push(pts[pts.length - 1]);
  return out;
}

// ---------- crayon stroke: pressure varies along, ends fade like wax lifting ----------
function crayon(pts, w, color, opts = {}) {
  const c = target;
  const step = Math.max(2, w * 0.5);
  const rs = resample(pts, step);
  const n = rs.length;
  c.strokeStyle = color;
  c.lineCap = 'round';
  for (let i = 0; i < n - 1; i++) {
    const t = i / (n - 1);
    let press = Math.min(1, t / 0.12 + 0.15, (1 - t) / 0.12 + 0.15);
    if (opts.flat) press = 1;
    if (R() < (opts.skip || 0)) continue;   // unfilled patches
    const j = w * 0.14;
    const [x0, y0] = rs[i], [x1, y1] = rs[i + 1];
    c.globalAlpha = press * rnd(0.55, 0.95) * (opts.alpha || 1);
    c.lineWidth = w * rnd(0.7, 1.08);
    c.beginPath();
    c.moveTo(x0 + rnd(-j, j), y0 + rnd(-j, j));
    c.lineTo(x1 + rnd(-j, j), y1 + rnd(-j, j));
    c.stroke();
  }
  c.globalAlpha = 1;
}

// ---------- ballpoint: ONE thin wobbly blue contour, gaps, occasional double-stroke ----------
function pen(pts, opts = {}) {
  const c = target;
  const wob = opts.wobble ?? 2.2;
  const rs = resample(pts, 9);
  const jit = rs.map(([x, y]) => [x + rnd(-wob, wob), y + rnd(-wob, wob)]);
  const passes = (opts.dbl ?? (R() < 0.3)) ? 2 : 1;
  for (let p = 0; p < passes; p++) {
    c.strokeStyle = opts.color || PEN;
    c.lineWidth = opts.w || 2.1;
    c.lineJoin = 'round'; c.lineCap = 'round';
    c.globalAlpha = (p === 0 ? 0.92 : 0.45) * (opts.alpha || 1);
    const off = p === 0 ? 0 : rnd(1.5, 3);
    let drawing = false;
    c.beginPath();
    for (let i = 0; i < jit.length; i++) {
      if (R() < (opts.gap ?? 0.04) && i > 0 && i < jit.length - 1) { drawing = false; continue; } // hand lifted
      const [x, y] = jit[i];
      if (!drawing) { c.moveTo(x + off, y + off); drawing = true; }
      else c.lineTo(x + off, y + off);
    }
    c.stroke();
  }
  c.globalAlpha = 1;
}

// ---------- scribble fill: hatch runs that disobey the boundary ----------
function scribble(insideFn, bbox, angleDeg, spacing, w, color, opts = {}) {
  const a = angleDeg * Math.PI / 180;
  const dx = Math.cos(a), dy = Math.sin(a);
  const px = -dy, py = dx; // perpendicular
  const [x0, y0, x1, y1] = bbox;
  const cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;
  const diag = Math.hypot(x1 - x0, y1 - y0) / 2 + 40;
  for (let o = -diag; o <= diag; o += spacing * rnd(0.75, 1.25)) {
    if (R() < (opts.rowSkip || 0)) continue; // whole missing row = unfilled patch
    // sample along the hatch line, gather runs inside the blob
    const runs = [];
    let run = null;
    for (let s = -diag; s <= diag; s += 6) {
      const x = cx + px * o + dx * s, y = cy + py * o + dy * s;
      if (insideFn(x, y)) {
        if (!run) run = [];
        run.push([x, y]);
      } else if (run) { runs.push(run); run = null; }
    }
    if (run) runs.push(run);
    for (const r of runs) {
      if (r.length < 2) continue;
      // overshoot / undershoot: the crayon disobeys the line
      const ov1 = rnd(-w * 0.6, w * 1.3), ov2 = rnd(-w * 0.6, w * 1.3);
      const h = r.map(([x, y]) => [x + rnd(-2.5, 2.5), y + rnd(-2.5, 2.5)]);
      h[0] = [h[0][0] - dx * ov1, h[0][1] - dy * ov1];
      h[h.length - 1] = [h[h.length - 1][0] + dx * ov2, h[h.length - 1][1] + dy * ov2];
      crayon(h, w, color, { skip: opts.skip ?? 0.04, alpha: opts.alpha || 1 });
    }
  }
}

function inPoly(poly) {
  return (x, y) => {
    let inside = false;
    for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
      const [xi, yi] = poly[i], [xj, yj] = poly[j];
      if (((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi)) inside = !inside;
    }
    return inside;
  };
}

// ---------- sun: concentric orange scribble spiral ----------
function sunSpiral(cx, cy, rMax, turns, w, color) {
  const pts = [];
  const steps = 130;
  for (let i = 0; i <= steps; i++) {
    const t = i / steps;
    const th = t * turns * 2 * Math.PI + 0.6;
    const r = 4 + t * rMax;
    pts.push([cx + Math.cos(th) * r + rnd(-3, 3), cy + Math.sin(th) * r * 0.96 + rnd(-3, 3)]);
  }
  crayon(pts, w, color, { flat: true, alpha: 0.95 });
}

// ---------- hand-drawn caption font (polylines, baseline y=1) ----------
function circGlyph(cx, cy, r, gapAt = 0.9) {
  const pts = [];
  for (let i = 0; i <= 15; i++) {
    const th = gapAt + i / 15 * (2 * Math.PI - 0.35);
    pts.push([cx + Math.cos(th) * r, cy + Math.sin(th) * r]);
  }
  return pts;
}
const GLYPHS = {
  'a': { w: 0.62, s: [circGlyph(0.28, 0.68, 0.28), [[0.56, 0.42], [0.57, 0.8], [0.6, 1]]] },
  'd': { w: 0.62, s: [circGlyph(0.28, 0.7, 0.27), [[0.55, 0.02], [0.56, 0.6], [0.58, 1]]] },
  'y': { w: 0.58, s: [[[0.03, 0.38], [0.16, 0.7], [0.3, 1]], [[0.58, 0.38], [0.4, 0.85], [0.26, 1.22], [0.1, 1.42]]] },
  'o': { w: 0.6, s: [circGlyph(0.3, 0.68, 0.3)] },
  'n': { w: 0.6, s: [[[0.06, 0.38], [0.05, 0.7], [0.06, 1]], [[0.06, 0.64], [0.12, 0.44], [0.3, 0.36], [0.48, 0.44], [0.55, 0.64], [0.55, 1]]] },
  'e': { w: 0.58, s: [[[0.06, 0.66], [0.3, 0.64], [0.52, 0.62], [0.5, 0.45], [0.34, 0.36], [0.16, 0.42], [0.06, 0.62], [0.08, 0.82], [0.22, 0.98], [0.42, 1.0], [0.54, 0.92]]] },
  't': { w: 0.5, s: [[[0.24, 0.08], [0.24, 0.6], [0.26, 0.9], [0.34, 1.0], [0.47, 0.96]], [[0.02, 0.36], [0.25, 0.35], [0.5, 0.34]]] },
  'h': { w: 0.6, s: [[[0.06, 0.02], [0.06, 0.5], [0.06, 1]], [[0.06, 0.62], [0.15, 0.42], [0.32, 0.36], [0.48, 0.45], [0.54, 0.64], [0.54, 1]]] },
  's': { w: 0.5, s: [[[0.45, 0.42], [0.3, 0.35], [0.14, 0.4], [0.1, 0.52], [0.2, 0.62], [0.35, 0.68], [0.42, 0.78], [0.36, 0.92], [0.2, 0.98], [0.05, 0.92]]] },
  'k': { w: 0.56, s: [[[0.06, 0.02], [0.06, 0.5], [0.06, 1]], [[0.5, 0.38], [0.28, 0.55], [0.08, 0.68]], [[0.2, 0.6], [0.36, 0.8], [0.52, 1]]] },
  'g': { w: 0.62, s: [circGlyph(0.28, 0.66, 0.27), [[0.55, 0.42], [0.56, 0.85], [0.56, 1.15], [0.5, 1.38], [0.3, 1.45], [0.14, 1.34]]] },
  'r': { w: 0.46, s: [[[0.06, 0.38], [0.05, 0.7], [0.06, 1]], [[0.06, 0.6], [0.14, 0.43], [0.28, 0.36], [0.41, 0.41]]] },
  'w': { w: 0.78, s: [[[0.03, 0.38], [0.18, 1], [0.36, 0.55], [0.55, 1], [0.72, 0.38]]] },
  '.': { w: 0.28, s: [[[0.1, 0.93], [0.14, 0.97], [0.11, 1.0]]] },
  ' ': { w: 0.5, s: [] },
};
function caption(text, cx, baseY, size, color = BLACK, w = 4.6) {
  let total = 0;
  for (const ch of text) total += (GLYPHS[ch] ? GLYPHS[ch].w : 0.5) * size + size * 0.16;
  let x = cx - total / 2;
  for (const ch of text) {
    const g = GLYPHS[ch];
    if (g) {
      const rot = rnd(-0.045, 0.045);
      const jy = rnd(-2, 2);
      for (const stroke of g.s) {
        const pts = stroke.map(([gx, gy]) => {
          const lx = gx * size, ly = (gy - 1) * size;
          return [x + lx * Math.cos(rot) - ly * Math.sin(rot),
                  baseY + jy + lx * Math.sin(rot) + ly * Math.cos(rot)];
        });
        crayon(pts, w, color, { flat: false, alpha: 0.95 });
      }
      x += g.w * size + size * 0.16;
    } else x += 0.5 * size;
  }
}

// ---------- the paper boat: hull + triangular sail-peak, no face, no limbs ----------
function boat(cx, cy, s, tiltDeg, stormy) {
  const a = tiltDeg * Math.PI / 180;
  const T = ([x, y]) => [cx + (x * Math.cos(a) - y * Math.sin(a)) * s,
                         cy + (x * Math.sin(a) + y * Math.cos(a)) * s];
  // hull trapezoid, bow (right) slightly lifted so it points forward
  const hull = [[-1.02, 0.02], [1.06, -0.1], [0.62, 0.5], [-0.58, 0.5], [-1.02, 0.02]].map(T);
  const sail = [[-0.52, 0.02], [0.04, -1.05], [0.58, -0.04]].map(T);
  const fold = [[0.04, -1.05], [0.09, -0.5], [0.1, -0.02]].map(T);
  const gunwale = [[-1.02, 0.02], [0.0, -0.03], [1.06, -0.1]].map(T);

  // the boat is PAPER: knock the sea out behind hull + sail before drawing it
  ctx.fillStyle = PAPER;
  for (const shape of [hull, sail]) {
    ctx.beginPath();
    ctx.moveTo(shape[0][0], shape[0][1]);
    for (let i = 1; i < shape.length; i++)
      ctx.lineTo(shape[i][0] + rnd(-1.5, 1.5), shape[i][1] + rnd(-1.5, 1.5));
    ctx.closePath();
    ctx.fill();
  }

  // hull fill: warm red crayon, strokes overshooting the contour
  beginCrayon();
  const hin = inPoly(hull);
  scribble(hin, [cx - 1.2 * s, cy - 0.2 * s, cx + 1.2 * s, cy + 0.6 * s],
    tiltDeg + rnd(-4, 4), s * 0.16, s * 0.13, RED, { skip: 0.05, rowSkip: 0.08 });
  // a touch of sunlight (or storm-light) catching the sail's leading half
  const litSail = [sail[1], sail[2], T([0.12, -0.02])];
  scribble(inPoly(litSail), [cx - s, cy - 1.1 * s, cx + s, cy + 0.2 * s],
    tiltDeg - 62, s * 0.2, s * 0.1, MARIGOLD, { skip: 0.12, rowSkip: 0.22, alpha: stormy ? 0.85 : 0.55 });
  endCrayon(0.95);

  // blue ballpoint contour, loose
  pen(hull, { wobble: s * 0.03, w: 2.4, dbl: true });
  pen(sail.concat([sail[0]]), { wobble: s * 0.03, w: 2.4, dbl: true });
  pen(fold, { wobble: s * 0.025, w: 1.9, alpha: 0.8 });
  pen(gunwale, { wobble: s * 0.025, w: 1.9, alpha: 0.7 });
}

// ================================================================
// FRAME A — "day one."  calm morning, boat lower-left heading right
// ================================================================
function frameA() {
  R = mulberry32(101);
  ctx.fillStyle = PAPER;
  ctx.fillRect(0, 0, W, H);

  const HOR = 424;

  // morning light: loose side-of-crayon marigold strokes, denser near the sun and horizon
  beginCrayon();
  for (let i = 0; i < 15; i++) {
    const nearSun = R() < 0.55;
    const y = nearSun ? rnd(200, HOR - 15) : HOR - rnd(15, 90);
    const xm = nearSun ? rnd(620, 1230) : rnd(90, 1200);
    const len = rnd(70, 260);
    crayon([[xm - len / 2, y + rnd(-4, 4)], [xm, y + rnd(-6, 6)], [xm + len / 2, y + rnd(-4, 4)]],
      rnd(14, 22), MARIGOLD, { skip: 0.12, alpha: rnd(0.22, 0.4) });
  }
  sunSpiral(985, 268, 88, 3.1, 8, ORANGE);
  // few marigold flicks around the sun
  for (let i = 0; i < 8; i++) {
    const th = rnd(0, Math.PI * 2);
    const r0 = 104 + rnd(0, 12), r1 = r0 + rnd(22, 44);
    crayon([[985 + Math.cos(th) * r0, 268 + Math.sin(th) * r0],
            [985 + Math.cos(th) * r1, 268 + Math.sin(th) * r1]], 7, MARIGOLD, { alpha: 0.8 });
  }
  endCrayon(0.95);

  // the sea: teal broad strokes, ragged bottom edge, bare paper band below for the caption
  beginCrayon();
  const seaBottom = x => 596 + Math.sin(x * 0.013 + 2) * 14 + Math.sin(x * 0.037) * 8;
  const inSea = (x, y) => x > -20 && x < W + 20 && y > HOR + 2 + Math.sin(x * 0.02) * 3 && y < seaBottom(x);
  scribble(inSea, [-20, HOR, W + 20, 640], 0.5, 15, 18, TEAL, { skip: 0.05, rowSkip: 0.06 });
  // pressed-harder teal accents
  for (let i = 0; i < 9; i++) {
    const y = rnd(HOR + 20, 585);
    const x0 = rnd(0, 950);
    crayon([[x0, y], [x0 + rnd(90, 260), y + rnd(-4, 4)]], 9, TEAL_D, { alpha: 0.75 });
  }
  // sun's reflection: short orange flicks on the water under the sun
  for (let i = 0; i < 6; i++) {
    const y = HOR + 14 + i * rnd(12, 22);
    const xw = rnd(20, 60);
    crayon([[985 - xw + rnd(-14, 14), y], [985 + xw + rnd(-14, 14), y]], 8, ORANGE, { alpha: 0.7 });
  }
  endCrayon(0.92);

  // ballpoint: horizon + little wave squiggles + two birds
  pen([[55, HOR], [400, HOR + rnd(-3, 3)], [760, HOR + rnd(-3, 3)], [1230, HOR - 2]], { wobble: 2.5, gap: 0.07 });
  for (let i = 0; i < 10; i++) {
    const x = rnd(60, 1150), y = rnd(HOR + 25, 580);
    const wpts = [];
    for (let k = 0; k <= 6; k++) wpts.push([x + k * 11, y + (k % 2 ? -4 : 3)]);
    pen(wpts, { wobble: 1.4, w: 1.8, alpha: 0.6, gap: 0.02 });
  }
  for (const [bx, by] of [[700, 170], [780, 205]]) {
    pen([[bx - 22, by + 4], [bx - 10, by - 6], [bx, by + 2]], { wobble: 1.2, w: 2, alpha: 0.85 });
    pen([[bx, by + 2], [bx + 11, by - 7], [bx + 23, by + 3]], { wobble: 1.2, w: 2, alpha: 0.85 });
  }

  // the boat, lower-left third, heading right, bow a touch up
  boat(365, 505, 92, -4, false);

  // it sits IN the water: a few teal strokes back over the hull bottom + wake
  beginCrayon();
  crayon([[240, 548], [370, 552], [500, 547]], 14, TEAL, { alpha: 0.8 });
  crayon([[275, 560], [460, 562]], 11, TEAL, { alpha: 0.6 });
  endCrayon(0.9);
  pen([[262, 545], [215, 552], [172, 548]], { wobble: 2, w: 1.9, alpha: 0.7 }); // wake
  pen([[250, 558], [200, 566]], { wobble: 2, w: 1.8, alpha: 0.5 });

  // caption strip
  caption('day one.', W / 2, 672, 44);
}

// ================================================================
// FRAME B — "the sky got angry."  black-scrubbed sky, one diagonal wave
// ================================================================
function frameB() {
  R = mulberry32(202);
  ctx.fillStyle = PAPER;
  ctx.fillRect(0, 0, W, H);

  const sunC = [195, 148], sunHole = 86;
  const skyEdge = x => (x < 560 ? 300 + (x / 560) * 70 : 370) + Math.sin(x * 0.011 + 1) * 26 + Math.sin(x * 0.031 + 4) * 14;

  // crest of the wave, needed early so the sky stops at it
  const waveTop = [
    [1300, 158], [1150, 172], [1010, 205], [880, 252], [760, 306],
    [640, 362], [540, 408], [470, 436], [420, 452], [388, 474], [378, 500]
  ];
  const waveTopY = x => {
    if (x <= 378) return 1e9;
    for (let i = waveTop.length - 1; i > 0; i--) {
      const [x1, y1] = waveTop[i], [x0, y0] = waveTop[i - 1];
      if (x >= x1 && x <= x0) return y1 + (y0 - y1) * (x - x1) / (x0 - x1);
    }
    return waveTop[0][1];
  };
  const skyBot = x => Math.min(skyEdge(x), waveTopY(x) - 16);

  // catastrophe = black crayon scrubbed over the whole sky, ragged bottom edge,
  // with one hole left where the light fights through
  beginCrayon();
  for (let pass = 0; pass < 2; pass++) {
    for (let y = -8; y < 400; y += rnd(9, 14)) {
      const x0 = rnd(-30, 10), x1 = W + rnd(-10, 30);
      const seg = 60;
      let run = [];
      for (let x = x0; x <= x1; x += seg) {
        const yy = y + rnd(-4, 4);
        const nearEdge = yy > skyBot(x) - rnd(0, 34);
        const inHole = Math.hypot(x - sunC[0], yy - sunC[1]) < sunHole + rnd(-6, 10);
        if (yy > skyBot(x) || inHole || (nearEdge && R() < 0.5)) {
          if (run.length > 1) crayon(run, 21, BLACK, { skip: 0.06, alpha: 0.8, flat: true });
          run = [];
        } else run.push([x, yy]);
      }
      if (run.length > 1) crayon(run, 21, BLACK, { skip: 0.06, alpha: 0.8, flat: true });
    }
  }
  // some angry diagonal scrub on top
  for (let i = 0; i < 16; i++) {
    const x = rnd(-20, W), y = rnd(0, 290);
    if (Math.hypot(x - sunC[0], y - sunC[1]) < sunHole + 50) continue;
    const x2 = x + rnd(60, 170), y2 = y + rnd(18, 55);
    if (y > skyBot(x) - 20 || y2 > skyBot(x2) - 20) continue;
    crayon([[x, y], [x2, y2]], 17, BLACK, { alpha: 0.55 });
  }
  endCrayon(0.96);

  // the one light: small orange sun spiral in the hole + marigold shaft down to the boat
  beginCrayon();
  sunSpiral(sunC[0], sunC[1], 46, 2.6, 7, ORANGE);
  for (let i = 0; i < 6; i++) {
    const th = rnd(0, Math.PI * 2);
    crayon([[sunC[0] + Math.cos(th) * 58, sunC[1] + Math.sin(th) * 58],
            [sunC[0] + Math.cos(th) * (58 + rnd(14, 26)), sunC[1] + Math.sin(th) * (58 + rnd(14, 26))]],
      6, MARIGOLD, { alpha: 0.85 });
  }
  for (let i = 0; i < 5; i++) {
    const o = (i - 2) * 16;
    crayon([[sunC[0] + 30 + o, sunC[1] + 60], [255 + o + rnd(-8, 8), 330], [305 + o * 0.6 + rnd(-8, 8), 452]],
      15, MARIGOLD, { alpha: 0.28, skip: 0.1 });
  }
  // the lit patch of water around the boat
  for (let i = 0; i < 5; i++) {
    const y = 496 + i * rnd(8, 14);
    const xm = 315 + rnd(-15, 15), len = rnd(60, 130);
    crayon([[xm - len / 2, y], [xm + len / 2, y + rnd(-4, 4)]], 11, MARIGOLD, { alpha: 0.4 });
  }
  endCrayon(0.95);

  // THE WAVE: one big diagonal mass from upper right, breaking toward the boat
  // the lip: a small open hook, not a tangle
  const curl = [[378, 500], [386, 516], [402, 522], [414, 512]];
  const seaBottom = x => 606 + Math.sin(x * 0.017 + 1) * 12 + Math.sin(x * 0.041) * 7;
  // fill polygon offset DOWN from the crest so a bare-paper foam band survives
  const waveInner = waveTop.map(([x, y]) => [x - 6 + rnd(-4, 4), y + 26 + rnd(-6, 6)]);
  const wavePoly = waveInner.concat([[392, 552], [200, 564], [-20, 558], [-20, 640], [1300, 640]]);
  const inWave = (x, y) => y < seaBottom(x) && inPoly(wavePoly)(x, y);
  const inWaveFull = (x, y) => y < seaBottom(x) && inPoly(waveTop.concat([[392, 540], [-20, 556], [-20, 640], [1300, 640]]))(x, y);

  beginCrayon();
  // body: strokes climb the face, steeper than the crest line
  scribble(inWave, [-20, 140, W + 20, 650], -34, 15, 18, TEAL, { skip: 0.05, rowSkip: 0.05 });
  // pressed-harder streaks low on the face (danger), following the same diagonal
  for (let i = 0; i < 9; i++) {
    const idx = 2 + Math.floor(rnd(0, waveTop.length - 3));
    const [x, y] = waveTop[idx];
    const sx = x + rnd(30, 120), sy = y + rnd(90, 170);
    const ex = sx - rnd(70, 130), ey = sy + rnd(50, 90);
    if (ey > 570 || sy > 570) continue;
    crayon([[sx, sy], [ex, ey]], 11, TEAL_D, { alpha: 0.6 });
  }
  // foam tumble right at the lip: paper-white wax over the teal
  for (let i = 0; i < 5; i++) {
    const x = 398 + rnd(-12, 26), y = 508 + rnd(-6, 22);
    crayon([[x, y], [x + rnd(-22, -8), y + rnd(4, 14)]], 11, '#F6F2E4', { alpha: 0.9 });
  }
  // flat sea left of the wave
  const inFlat = (x, y) => x < 400 && y > 520 + Math.sin(x * 0.03) * 5 && y < seaBottom(x);
  scribble(inFlat, [-20, 500, 420, 640], 2, 14, 16, TEAL, { skip: 0.06, rowSkip: 0.08 });
  endCrayon(0.94);

  // crest contour + curl + foam scallops in ballpoint; foam band = bare paper
  pen(waveTop, { wobble: 3.2, w: 2.4, gap: 0.05, dbl: true });
  pen(curl, { wobble: 2.2, w: 2.4, gap: 0.02, dbl: true });
  for (let i = 1; i < waveTop.length - 3; i++) {
    const [x, y] = waveTop[i];
    pen([[x + 6, y + 8], [x - 4, y + 18], [x - 20, y + 16], [x - 26, y + 26]],
      { wobble: 1.8, w: 2, alpha: 0.8 });
  }
  // spray flicks off the upper crest only (keep the boat's corner clean)
  for (let i = 0; i < 9; i++) {
    const src = waveTop[1 + Math.floor(rnd(0, 6))];
    pen([[src[0] + rnd(-8, 8), src[1] - rnd(4, 10)], [src[0] + rnd(-34, -8), src[1] - rnd(16, 44)]],
      { wobble: 1.3, w: 1.8, alpha: 0.7, gap: 0 });
  }

  // rain: ballpoint diagonal dashes
  for (let i = 0; i < 85; i++) {
    const x = rnd(0, W), y = rnd(30, 470);
    if (Math.hypot(x - sunC[0], y - sunC[1]) < sunHole) continue;
    if (inWaveFull(x, y)) continue;
    pen([[x, y], [x - rnd(8, 15), y + rnd(18, 30)]], { wobble: 0.8, w: 1.7, alpha: 0.55, gap: 0 });
  }

  // the boat: small, in the lit patch, climbing the wave, still pointing forward
  boat(316, 474, 55, -16, true);

  // water over its hull bottom + a hard pitching wake
  beginCrayon();
  crayon([[248, 505], [318, 499], [386, 488]], 12, TEAL, { alpha: 0.85 });
  crayon([[262, 516], [356, 505]], 10, TEAL_D, { alpha: 0.7 });
  endCrayon(0.9);
  pen([[254, 508], [226, 518], [204, 515]], { wobble: 2, w: 1.8, alpha: 0.7 });

  // caption strip
  caption('the sky got angry.', W / 2, 672, 44);
}

window.drawFrame = function (which) {
  if (which === 'a') frameA(); else frameB();
  window.DONE = true;
};
window.READY = true;
</script>
</body>
</html>