{
  "$schema": "../../schema.json",
  "id": "glitch",
  "type": "transition",
  "title": "Glitch",
  "summary": "A few frames of torn bands and RGB split, then B.",
  "tags": [
    "transition",
    "digital",
    "raw",
    "energetic"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "glitch",
  "signature": "glitch(a, b, p, { seed, steps, rgb, shift })",
  "params": [
    {
      "name": "seed",
      "type": "number",
      "default": 1,
      "description": "random seed; change it for a different variation",
      "min": 1,
      "max": 999,
      "step": 1,
      "group": "advanced"
    },
    {
      "name": "steps",
      "type": "number",
      "default": 22,
      "description": "glitch changes per transition",
      "min": 4,
      "max": 60,
      "step": 1,
      "group": "main"
    },
    {
      "name": "rgb",
      "type": "number",
      "default": 16,
      "description": "RGB split in px",
      "min": 0,
      "max": 60,
      "step": 1,
      "group": "main"
    },
    {
      "name": "shift",
      "type": "number",
      "default": 140,
      "description": "band shift in px",
      "min": 0,
      "max": 400,
      "step": 5,
      "group": "main"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/glitch.js",
      "content": "import { clamp, rng } from 'paper-motion';\nimport { rects, clipTo, size } from 'paper-motion/kit';\n\n/** A few frames of torn bands, jitter and RGB split; the bands show more of B until B holds. */\nexport function glitch(a, b, p, { seed = 1, steps = 22, rgb = 16, shift = 140 } = {}) {\n  const fringe = (el, s) => { for (const c of el.children) c.style.filter = s > 0.3 ? `drop-shadow(${s}px 0 0 rgba(255,30,70,.9)) drop-shadow(${-s}px 0 0 rgba(0,220,255,.9))` : 'none'; };\n  if (p <= 0) { clipTo(b, ''); return; }\n  if (p >= 1) { b.style.clipPath = 'none'; b.style.opacity = 1; fringe(a, 0); fringe(b, 0); return; }\n  const r = rng(seed * 997 + Math.floor(p * steps)).next, amt = Math.sin(Math.PI * p), cover = clamp((p - 0.1) / 0.75);\n  const [w, h] = size(a, b), list = [];\n  for (let y = 0; y < h;) { const bh = h * (0.015 + 0.11 * r()); if (r() < cover) list.push([0, y, w, bh + 1]); y += bh; }\n  clipTo(b, rects(list)); b.style.opacity = 1;\n  b.style.transform = `translateX(${(r() - 0.5) * shift * amt}px)`;\n  a.style.transform = `translateX(${(r() - 0.5) * shift * 0.6 * amt}px)`;\n  fringe(a, rgb * amt * r()); fringe(b, rgb * amt);\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { glitch } from './moves/glitch.js';\n\n// two stacked layers, B above A; in s.update(t), from 2.0 s to 2.6 s:\nglitch(a, b, progress(t, 2.0, 2.6));",
  "notes": [
    "A few frames of torn bands, jitter and RGB split; the bands show more of B until B holds.",
    "At p = 0 only A shows, at p = 1 only B; keep B above A (z-index).",
    "Only for a digital or raw identity."
  ],
  "preview": {
    "video": "previews/glitch.webm",
    "poster": "previews/glitch.jpg"
  },
  "mood": [
    "raw",
    "technical",
    "bold"
  ],
  "energy": 5,
  "role": "swap",
  "when": [
    "the identity is digital, broken, underground",
    "a jolt on a drop"
  ]
}