{
  "$schema": "../../schema.json",
  "id": "cells",
  "type": "transition",
  "title": "Cells",
  "summary": "B appears through a grid of squares that grow in a diagonal wave.",
  "tags": [
    "transition",
    "graphic",
    "grid"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "cells",
  "signature": "cells(a, b, p, { cols, rows, origin, spread, curve })",
  "params": [
    {
      "name": "cols",
      "type": "number",
      "default": 16,
      "description": "grid columns",
      "min": 2,
      "max": 24,
      "step": 1,
      "group": "main"
    },
    {
      "name": "rows",
      "type": "number",
      "default": 9,
      "description": "grid rows",
      "min": 2,
      "max": 16,
      "step": 1,
      "group": "main"
    },
    {
      "name": "origin",
      "type": "array",
      "default": [
        0,
        0
      ],
      "description": "transform origin (CSS)",
      "group": "main"
    },
    {
      "name": "spread",
      "type": "number",
      "default": 0.6,
      "description": "how much the wave spreads (0–1)",
      "min": 0,
      "max": 1,
      "step": 0.01,
      "group": "main"
    },
    {
      "name": "curve",
      "type": "function",
      "default": "ease.outCubic",
      "description": "easing function (from `ease`)",
      "control": "ease",
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/cells.js",
      "content": "import { ease, clamp } from 'paper-motion';\nimport { rects, clipTo, size } from 'paper-motion/kit';\n\n/** B shows through a grid of squares that grow from their centres in a wave from `origin` (0..1, 0..1). */\nexport function cells(a, b, p, { cols = 16, rows = 9, origin = [0, 0], spread = 0.6, curve = ease.outCubic } = {}) {\n  if (p >= 1) { b.style.clipPath = 'none'; b.style.opacity = 1; return; }\n  const [w, h] = size(a, b), cw = w / cols, ch = h / rows, max = Math.hypot(Math.max(origin[0], 1 - origin[0]), Math.max(origin[1], 1 - origin[1]));\n  const list = [];\n  for (let j = 0; j < rows; j++) for (let i = 0; i < cols; i++) {\n    const d = (spread * Math.hypot((i + 0.5) / cols - origin[0], (j + 0.5) / rows - origin[1])) / max;\n    const q = curve(clamp((p - d) / (1 - spread)));\n    if (q <= 0) continue;\n    const k = Math.min(1, q * 1.08), sw = cw * k, sh = ch * k; // close the last hairline before the curve settles\n    list.push([i * cw + (cw - sw) / 2, j * ch + (ch - sh) / 2, sw, sh]);\n  }\n  clipTo(b, rects(list)); b.style.opacity = 1;\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { cells } from './moves/cells.js';\n\n// two stacked layers, B above A; in s.update(t), from 2.0 s to 2.6 s:\ncells(a, b, progress(t, 2.0, 2.6));",
  "notes": [
    "B shows through a grid of squares that grow from their centres in a wave from `origin` (0..1, 0..1).",
    "At p = 0 only A shows, at p = 1 only B; keep B above A (z-index)."
  ],
  "preview": {
    "video": "previews/cells.webm",
    "poster": "previews/cells.jpg"
  },
  "mood": [
    "technical",
    "playful",
    "bold"
  ],
  "energy": 4,
  "role": "swap",
  "when": [
    "a grid-minded, graphic brand",
    "a transition that reads as pixels or tiles"
  ]
}