/* OPHI-118 — animated CRT static.
 *
 * If <canvas id="static"> isn't on the page (e.g. compact widgets that
 * skip the noise overlay), this is a no-op.
 */
(function () {
  'use strict';
  document.addEventListener('DOMContentLoaded', () => {
    const cv = document.getElementById('static');
    if (!cv) return;
    const ctx = cv.getContext('2d');
    const W = 320, H = 180;
    cv.width = W; cv.height = H;
    const img = ctx.createImageData(W, H);
    const drawNoise = () => {
      const d = img.data;
      for (let i = 0; i < d.length; i += 4) {
        const v = (Math.random() * 255) | 0;
        d[i] = d[i+1] = d[i+2] = v;
        d[i+3] = 255;
      }
      ctx.putImageData(img, 0, 0);
    };
    drawNoise();
    // 8 fps — visually almost identical to 12 fps but ~33% less paint work.
    setInterval(drawNoise, 1000 / 8);
  });
})();
