{
  "$schema": "../../schema.json",
  "id": "scramble",
  "type": "text",
  "title": "Scramble",
  "summary": "Letters cycle through random glyphs and lock into place, left to right.",
  "tags": [
    "text",
    "tech",
    "digital"
  ],
  "version": "1.0.0",
  "license": "MIT",
  "export": "scramble",
  "signature": "scramble(el, t, { start, duration, fps, rate, seed, glyphs })",
  "params": [
    {
      "name": "start",
      "type": "number",
      "default": 0,
      "description": "start time in seconds",
      "hidden": true
    },
    {
      "name": "duration",
      "type": "number",
      "default": 1.4,
      "description": "length of the transition in seconds; springs use it to keep their feel",
      "min": 0.2,
      "max": 3,
      "step": 0.05,
      "group": "main"
    },
    {
      "name": "fps",
      "type": "number",
      "default": 30,
      "description": "scene fps",
      "hidden": true
    },
    {
      "name": "rate",
      "type": "number",
      "default": 2,
      "description": "frames per glyph change",
      "min": 1,
      "max": 6,
      "step": 1,
      "group": "main"
    },
    {
      "name": "seed",
      "type": "number",
      "default": 1,
      "description": "random seed; change it for a different variation",
      "min": 1,
      "max": 999,
      "step": 1,
      "group": "advanced"
    },
    {
      "name": "glyphs",
      "type": "string",
      "default": "ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&*+=/<>",
      "description": "glyphs used while scrambling",
      "group": "advanced"
    }
  ],
  "install": {
    "kind": "code"
  },
  "files": [
    {
      "path": "moves/scramble.js",
      "content": "import { rng } from 'paper-motion';\nimport { chars, hash } from 'paper-motion/kit';\n\n/** Letters show random glyphs, then lock into the real text from left to right. Widths stay fixed. */\nexport function scramble(el, t, { start = 0, duration = 1.4, fps = 30, rate = 2, seed = 1, glyphs = 'ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&*+=/<>' } = {}) {\n  const cs = chars(el);\n  if (!el._labText) {\n    el._labText = cs.map((c) => c.textContent);\n    // layout width, not the on-screen rect: inside a 3D world the rect is scaled by perspective\n    cs.forEach((c) => { c.style.width = `${c.offsetWidth}px`; c.style.textAlign = 'center'; });\n    const r = rng(seed); el._labJit = cs.map(() => r.next());\n  }\n  const n = cs.length, tick = Math.floor((t * fps) / rate);\n  cs.forEach((c, i) => {\n    const appear = start + (i / n) * duration * 0.35;\n    const settle = start + duration * (0.3 + 0.7 * (i / n)) + el._labJit[i] * 0.1;\n    if (t < appear) { c.style.opacity = 0; return; }\n    if (t >= settle) { c.textContent = el._labText[i]; c.style.opacity = 1; return; }\n    c.textContent = glyphs[Math.floor(hash(tick + seed, i) * glyphs.length)];\n    c.style.opacity = 0.5;\n  });\n}\n"
    }
  ],
  "requires": {
    "engine": ">=0.2.0"
  },
  "usage": "import { scramble } from './moves/scramble.js';\n\ns.update((t) => scramble(el, t, { start: 0.5 }));",
  "notes": [
    "Letters show random glyphs, then lock into the real text from left to right. Widths stay fixed."
  ],
  "preview": {
    "video": "previews/scramble.webm",
    "poster": "previews/scramble.jpg"
  },
  "mood": [
    "technical",
    "raw",
    "playful"
  ],
  "energy": 3,
  "role": "text",
  "when": [
    "hacker, data, cipher moods",
    "numbers or codes resolving"
  ]
}