<?xml version="1.0" encoding="UTF-8"?>

<MNPreset formatVersion="1">
  <metadata name="Cinemnode" author="Darc Sector" category="Visual" type="Effect" purpose="effect" description="Cinemnode: a cinemagraph tool by Darc Sector. Effects to lay over a picture of your own (a Widget Image under the see-through Scene, 1920 x 1080). Signs with a shader that you drag into shape over the picture (perspective, corner by corner), lit windows, neon, and lights that blink, twinkle or flicker. Edit mode for placing, and a clean picture for full screen in Perform." bundle="" tags="scene,visual,shader,photo" createdAt="1792881004037" modifiedAt="1792881004037" pluginVersion="1.1.7" isFavorite="0" preferredOpenMode="perform"/>
  <state>
    <marionietoworld.MNodes_State pv="1.1.7" gridActive="1" gridSize="60" viewOffsetX="0" viewOffsetY="0" zoom="0.4" didInitView="1" toolbarX="-1" toolbarY="-1" toolbarExpanded="1" transportBpm="120.0" transportSync="1" transportTimeSigNum="4" transportTimeSigDen="4">
      <nodes nextId="5">
        <node id="1" type="visual.gpucanvas" title="Cinemnode" expanded="0" x="0.0" y="0.0" w="1920.0" h="1080.0">
          <state pcount="27" speed="1.0" code="// Made by the Cinemnode Script: change the Script, not this.&#10;// Cinemnode (was Scene Kit): shared helpers and effects. The Script adds mainImage with every element.&#10;float h11(float n) { return fract(sin(n * 12.9898) * 43758.5453); }&#10;float h21(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }&#10;float vnoise(vec2 p)&#10;{&#10;    vec2 i = floor(p), f = fract(p);&#10;    f = f * f * (3.0 - 2.0 * f);&#10;    return mix(mix(h21(i), h21(i + vec2(1.0, 0.0)), f.x), mix(h21(i + vec2(0.0, 1.0)), h21(i + vec2(1.0, 1.0)), f.x), f.y);&#10;}&#10;float vnoise1(float x)&#10;{&#10;    float i = floor(x), f = fract(x);&#10;    f = f * f * (3.0 - 2.0 * f);&#10;    return mix(h11(i), h11(i + 1.0), f);&#10;}&#10;&#10;// Where p lies in the quad a (top left), b (top right), c (bottom right), d (bottom left): 0..1 each way, v down.&#10;// A perspective (projective) map, so a flat sign photographed at an angle is filled the way it really is.&#10;vec2 quadUV(vec2 p, vec2 a, vec2 b, vec2 c, vec2 d)&#10;{&#10;    float sx = a.x - b.x + c.x - d.x, sy = a.y - b.y + c.y - d.y;&#10;    float dx1 = b.x - c.x, dx2 = d.x - c.x, dy1 = b.y - c.y, dy2 = d.y - c.y;&#10;    float den = dx1 * dy2 - dx2 * dy1;&#10;    if (abs(den) &lt; 1e-9) return vec2(-10.0);&#10;    float g = (sx * dy2 - dx2 * sy) / den;&#10;    float h = (dx1 * sy - sx * dy1) / den;&#10;    float A = b.x - a.x + g * b.x, B = d.x - a.x + h * d.x, C = a.x;&#10;    float D = b.y - a.y + g * b.y, E = d.y - a.y + h * d.y, F = a.y;&#10;    // the inverse, by the adjugate (the determinant cancels in the division)&#10;    float i00 = E - F * h, i01 = C * h - B, i02 = B * F - C * E;&#10;    float i10 = F * g - D, i11 = A - C * g, i12 = C * D - A * F;&#10;    float i20 = D * h - E * g, i21 = B * g - A * h, i22 = A * E - B * D;&#10;    vec3 r = vec3(i00 * p.x + i01 * p.y + i02, i10 * p.x + i11 * p.y + i12, i20 * p.x + i21 * p.y + i22);&#10;    vec2 m = (a + b + c + d) * 0.25;&#10;    float wm = i20 * m.x + i21 * m.y + i22;&#10;    if (r.z * wm &lt;= 0.0) return vec2(-10.0);   // beyond the vanishing line&#10;    return r.xy / r.z;&#10;}&#10;&#10;// ---------- effects for a sign: each gives a colour and how much of it covers ----------&#10;vec4 fxPlasma(vec2 uv, float t, vec3 tint)&#10;{&#10;    vec2 p = uv * 6.0;&#10;    float v = sin(p.x + t) + sin(p.y * 1.3 - t * 1.1) + sin((p.x + p.y) * 0.7 + t * 0.8) + sin(length(p - 3.0) * 1.5 - t * 1.6);&#10;    vec3 c = 0.5 + 0.5 * cos(6.2832 * (v * 0.15 + vec3(0.0, 0.33, 0.67)) + t * 0.3);&#10;    return vec4(mix(c, c * tint, 0.35), 1.0);&#10;}&#10;&#10;vec4 fxText(vec2 uv, float t, vec3 tint, float cov)&#10;{&#10;    vec3 bg = vec3(0.015, 0.015, 0.03) + tint * 0.05 * (0.5 + 0.5 * sin(uv.y * 300.0));&#10;    vec3 c = mix(bg, tint * 1.5 + 0.15, cov);&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxGlitch(vec2 uv, float t, vec3 tint)&#10;{&#10;    float band = floor(uv.y * 24.0);&#10;    float g = step(0.82, h21(vec2(band, floor(t * 8.0))));&#10;    vec2 u = uv;&#10;    u.x += g * (h21(vec2(band, floor(t * 16.0))) - 0.5) * 0.3;&#10;    vec3 c = vec3(h21(floor(u * vec2(160.0, 90.0)) + floor(t * 24.0))) * 0.3;&#10;    vec2 cell = floor(u * vec2(8.0, 4.0) + vec2(t * 0.5, 0.0));&#10;    c += tint * step(0.6, h21(cell + floor(t * 2.0))) * 0.75;&#10;    c.r += 0.35 * g;&#10;    c.b += 0.3 * step(0.9, h21(vec2(band * 3.1, floor(t * 12.0))));&#10;    c *= 0.8 + 0.2 * sin(uv.y * 420.0);&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxBars(vec2 uv, float t, vec3 tint)&#10;{&#10;    float x = fract(uv.x + t * 0.04);&#10;    float i = floor(x * 7.0);&#10;    vec3 c = vec3((i &lt; 1.5 || (i &gt; 3.5 &amp;&amp; i &lt; 5.5)) ? 1.0 : 0.0, i &lt; 3.5 ? 1.0 : 0.0, mod(i, 2.0) &lt; 0.5 ? 1.0 : 0.0) * 0.8;&#10;    if (uv.y &gt; 0.78) c = vec3(fract(uv.x * 4.0 - t * 0.2)) * 0.9;&#10;    float roll = fract(uv.y - t * 0.15);&#10;    c *= 1.0 - 0.35 * smoothstep(0.9, 1.0, roll);&#10;    c += (h21(floor(uv * vec2(200.0, 120.0)) + floor(t * 30.0)) - 0.5) * 0.08;&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxRetro(vec2 uv, float t, vec3 tint)&#10;{&#10;    vec2 p = vec2(uv.x - 0.5, 1.0 - uv.y);&#10;    float hz = 0.42;&#10;    vec3 c;&#10;    if (p.y &gt; hz) {&#10;        c = mix(vec3(0.35, 0.05, 0.4), vec3(0.03, 0.0, 0.12), (p.y - hz) / (1.0 - hz));&#10;        vec2 s = vec2(p.x * 1.6, p.y - 0.62);&#10;        float r = length(s);&#10;        float gaps = step(0.5, fract((p.y - hz) * 22.0 + t * 0.6)) + step(0.7, p.y);&#10;        c = mix(c, mix(vec3(1.0, 0.25, 0.5), vec3(1.0, 0.85, 0.2), (p.y - 0.42) / 0.38), (1.0 - smoothstep(0.24, 0.25, r)) * min(gaps, 1.0));&#10;    } else {&#10;        float z = 0.08 / max(hz - p.y, 0.001);&#10;        vec2 g = vec2(p.x * z * 6.0, z + t);&#10;        vec2 f = abs(fract(g) - 0.5);&#10;        float w = 0.04 * z;&#10;        float line = max(1.0 - smoothstep(0.0, w + 0.02, 0.5 - f.x), 1.0 - smoothstep(0.0, w + 0.02, 0.5 - f.y));&#10;        c = mix(vec3(0.03, 0.0, 0.08), tint * 0.6 + vec3(0.6, 0.1, 0.8) * 0.6, line * exp(-z * 0.05));&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;&#10;vec4 fxWindow(vec2 uv, float t, vec3 tint)   // added to the photo: a lit window&#10;{&#10;    float e = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));&#10;    float f = 0.85 + 0.15 * vnoise1(t * 5.0);&#10;    float lit = (0.6 + 0.4 * smoothstep(0.0, 0.12, e)) * (1.0 - 0.3 * uv.y);   // lighter towards the ceiling lamp&#10;    return vec4(tint * f * lit * 0.8, 1.0);&#10;}&#10;&#10;vec4 fxNeon(vec2 uv, float t, vec3 tint)     // added to the photo: a neon tube along the edge&#10;{&#10;    float e = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));&#10;    float tube = 1.0 - smoothstep(0.006, 0.016, abs(e - 0.035));&#10;    float glow = exp(-abs(e - 0.035) * 30.0) * 0.5;&#10;    float on = 0.85 + 0.15 * sin(t * 40.0) * step(0.93, h11(floor(t * 3.0)));&#10;    return vec4(tint * (tube * 1.6 + glow) * on, 1.0);&#10;}&#10;&#10;// ---------- lights ----------&#10;// mode: 0 on, 1 slow blink, 2 twinkle, 3 broken tube, 4 pulse, 5 strobe, 6 candle&#10;float lampAmp(int mode, float t, float seed)&#10;{&#10;    if (mode == 1) { float s = fract(t * 0.5 + seed); return smoothstep(0.0, 0.08, s) * (1.0 - smoothstep(0.5, 0.58, s)); }&#10;    if (mode == 2) { float n = vnoise1(t * 4.0 + seed * 37.0); return 0.12 + 1.2 * n * n * n; }&#10;    if (mode == 3) {&#10;        float bad = h11(floor(t * 0.7) + seed * 91.0);&#10;        float fast = step(0.4, h11(floor(t * 17.0) + seed * 13.0));&#10;        return bad &gt; 0.55 ? fast * 0.95 : 0.9 + 0.1 * vnoise1(t * 30.0);&#10;    }&#10;    if (mode == 4) return 0.55 + 0.45 * sin(6.2832 * (t * 0.5 + seed));&#10;    if (mode == 5) { float s = fract(t * 2.0 + seed); return 1.0 - smoothstep(0.0, 0.07, s); }&#10;    if (mode == 6) return 0.7 + 0.3 * vnoise1(t * 7.0 + seed * 20.0) * (0.6 + 0.4 * vnoise1(t * 2.3 + seed * 5.0));&#10;    return 1.0;&#10;}&#10;&#10;vec3 lamp(vec2 fc, vec2 pos, float r, float amp, vec3 lc, float rays)&#10;{&#10;    vec2 d = fc - pos;&#10;    float l = length(d) / r;&#10;    float g = exp(-l * l * 18.0) * 1.6 + 0.5 / (1.0 + l * l * 10.0) * (1.0 - smoothstep(0.4, 1.4, l));&#10;    vec2 a = abs(d) / r;&#10;    g += rays * (exp(-a.x * 40.0 - a.y * 2.2) + exp(-a.y * 40.0 - a.x * 2.2)) * 0.8;&#10;    return lc * amp * g;&#10;}&#10;&#10;// light added to what is drawn so far: C is the colour times its cover, A the cover&#10;void glowAdd(inout vec3 C, inout float A, vec3 add)&#10;{&#10;    C += add;&#10;    A = max(A, clamp(max(add.r, max(add.g, add.b)), 0.0, 1.0));&#10;}&#10;&#10;// rain: thin streaks falling a little slanted, in three layers (far ones smaller, slower and fainter).&#10;// p is the place on the screen in screen heights (y up), so the drops keep their size on any sign&#10;vec4 fxRain(vec2 p, float t, vec3 tint)&#10;{&#10;    float a = 0.0;&#10;    for (int i = 0; i &lt; 3; i++) {&#10;        float fi = float(i);&#10;        float sc = 1.0 + fi * 0.8;                    // far layers: more, smaller drops&#10;        float cols = 70.0 * sc;&#10;        float x = (p.x + p.y * 0.12) * cols;          // slanted by the wind&#10;        float cx = floor(x);&#10;        float r1 = h21(vec2(cx, fi * 17.0)), r2 = h21(vec2(cx, fi * 31.0 + 5.0));&#10;        float len = 0.10 / sc;                         // a drop's streak, in screen heights&#10;        float y = p.y * (1.0 / len) * 0.25 + t * (9.0 - fi * 2.0) * (0.8 + 0.4 * r1) + r2 * 10.0;&#10;        float drop = fract(y);&#10;        float streak = smoothstep(0.0, 0.05, drop) * (1.0 - smoothstep(0.08, 0.25, drop));&#10;        float thin = 1.0 - smoothstep(0.06, 0.16, abs(fract(x) - 0.5));&#10;        float here = step(0.55, h21(vec2(cx, floor(y) + fi * 7.0)));   // not every column has a drop each time&#10;        a += streak * thin * here * (0.6 - fi * 0.17);&#10;    }&#10;    return vec4(tint, clamp(a, 0.0, 1.0));   // only the streaks cover: the picture shows between them&#10;}&#10;&#10;// ripples in water: rings that start in the middle of the sign and spread out, three at a time, fading as they go.&#10;// The crests are drawn light (tint), the troughs dark, each only as much as strength says; between the rings it is clear.&#10;// size: how far a ring gets (0.5 = to the edge of the sign)&#10;float rippleV(vec2 uv, float t, float size)   // the water's height: + crests, - troughs&#10;{&#10;    float r = length(uv - 0.5) * 2.0;             // 0 in the middle, 1 at the sides&#10;    float rmax = 0.15 + 1.25 * size;&#10;    float v = 0.0;&#10;    for (int k = 0; k &lt; 3; k++) {&#10;        float age = fract(t * 0.25 + float(k) / 3.0);&#10;        float d = r - age * rmax;                  // how far behind the front of this ring&#10;        float w = 0.05 + 0.08 * age;               // the rings widen as they spread&#10;        v += sin(d / w * 3.1416 * 1.5) * exp(-d * d / (w * w * 2.0)) * (1.0 - age) * (1.0 - age);&#10;    }&#10;    return v * (1.0 - smoothstep(0.85, 1.0, r));  // dies out before the edge of the sign&#10;}&#10;&#10;vec4 fxRipple(vec2 uv, float t, vec3 tint, float size, float strength)&#10;{&#10;    float v = rippleV(uv, t, size);&#10;    float a = clamp(abs(v) * strength * 1.6, 0.0, 1.0);&#10;    return vec4(v &gt; 0.0 ? tint : vec3(0.0), a);&#10;}&#10;&#10;// ---------- edit aids (only with a background in Image 1) ----------&#10;float lumaAt(vec2 uv) { return dot(texture(iImage0, uv).rgb, vec3(0.299, 0.587, 0.114)); }&#10;&#10;// how much of an edge the picture has here (Sobel), so windows, signs and lamps stand out to place things on&#10;float edgeAt(vec2 uv)&#10;{&#10;    vec2 e = 1.5 / iResolution.xy;&#10;    float tl = lumaAt(uv + vec2(-e.x, e.y)), t = lumaAt(uv + vec2(0.0, e.y)), tr = lumaAt(uv + e);&#10;    float l = lumaAt(uv - vec2(e.x, 0.0)), r = lumaAt(uv + vec2(e.x, 0.0));&#10;    float bl = lumaAt(uv - e), b = lumaAt(uv - vec2(0.0, e.y)), br = lumaAt(uv + vec2(e.x, -e.y));&#10;    float gx = tr + 2.0 * r + br - tl - 2.0 * l - bl;&#10;    float gy = tl + 2.0 * t + tr - bl - 2.0 * b - br;&#10;    return smoothstep(0.08, 0.3, length(vec2(gx, gy)));&#10;}&#10;&#10;// a round magnifier beside the point p (pixels): the background 4 times bigger, with a cross on p&#10;void magnifier(inout vec3 C, vec2 fc, vec2 p)&#10;{&#10;    vec2 R = iResolution.xy;&#10;    float S = R.y / 1080.0, rad = 110.0 * S;&#10;    vec2 off = vec2(p.x &gt; R.x - 300.0 * S ? -150.0 : 150.0, p.y &gt; R.y - 300.0 * S ? -150.0 : 150.0) * S;&#10;    vec2 m = p + off;&#10;    float d = length(fc - m);&#10;    if (d &gt; rad + 3.0 * S) return;&#10;    vec2 src = p + (fc - m) / 4.0;&#10;    vec3 col = texture(iImage0, src / R).rgb;&#10;    vec2 a = abs(fc - m);&#10;    float cross = (1.0 - smoothstep(0.5, 1.5, min(a.x, a.y) / S)) * step(max(a.x, a.y), 18.0 * S);&#10;    col = mix(col, vec3(0.54, 0.25, 1.0), cross);&#10;    C = mix(col, vec3(0.54, 0.25, 1.0), smoothstep(rad - 1.0, rad, d));&#10;}&#10;&#10;// ---------- v1.6 ----------&#10;float lum(vec3 c) { return dot(c, vec3(0.299, 0.587, 0.114)); }&#10;float fbm(vec2 p)&#10;{&#10;    float v = 0.0, a = 0.5;&#10;    for (int i = 0; i &lt; 5; i++) { v += a * vnoise(p); p = p * 2.03 + vec2(1.7, 9.2); a *= 0.5; }&#10;    return v;&#10;}&#10;&#10;// how an effect follows the picture under it: 1 its light and shade show through, 2 only on bright parts, 3 only on dark parts&#10;void picReact(inout vec4 s, int mode, vec3 pic)&#10;{&#10;    float l = lum(pic);&#10;    if (mode == 1) s.rgb *= 0.25 + 1.5 * l;&#10;    if (mode == 2) s.a *= smoothstep(0.3, 0.6, l);&#10;    if (mode == 3) s.a *= 1.0 - smoothstep(0.3, 0.6, l);&#10;}&#10;&#10;// clouds drifting across the board, see-through between them, fading at its edges&#10;vec4 fxClouds(vec2 uv, float t, vec3 tint)&#10;{&#10;    vec2 p = uv * vec2(3.0, 2.0) + vec2(t * 0.15, 0.0);&#10;    float n = fbm(p + 0.5 * fbm(p * 0.7 - vec2(t * 0.05, 0.0)));&#10;    float a = smoothstep(0.42, 0.75, n);&#10;    vec3 col = mix(tint * 0.55, tint, smoothstep(0.45, 0.9, n));   // lit tops, darker bellies&#10;    float e = smoothstep(0.0, 0.15, uv.x) * smoothstep(0.0, 0.15, 1.0 - uv.x) * smoothstep(0.0, 0.15, uv.y) * smoothstep(0.0, 0.15, 1.0 - uv.y);&#10;    return vec4(col, a * e);&#10;}&#10;&#10;// smoke rising from the middle of the board's bottom edge, swaying and widening as it goes up, gone at the top&#10;vec4 fxSmoke(vec2 uv, float t, vec3 tint)&#10;{&#10;    float h = 1.0 - uv.y;                          // 0 at the bottom, 1 at the top&#10;    float x = uv.x - 0.5;&#10;    float sway = (fbm(vec2(h * 1.5 - t * 0.25, 3.0)) - 0.5) * 0.5 * h;&#10;    float wdt = 0.05 + 0.32 * h;&#10;    float plume = exp(-pow((x - sway) / wdt, 2.0));&#10;    float n = fbm(vec2(x * 4.0 / (0.3 + h), h * 3.0 - t * 0.8));&#10;    float a = plume * (0.35 + 0.65 * smoothstep(0.2, 0.65, n)) * (1.0 - smoothstep(0.5, 1.0, h)) * smoothstep(0.0, 0.06, h);&#10;    return vec4(tint * (0.6 + 0.4 * n), clamp(a * 0.9, 0.0, 1.0));&#10;}&#10;&#10;// a lit rectangle (cov: how much of the pixel is inside) with a glow round it, glow 0..1 its reach&#10;vec4 fxLightBox(vec2 uv, float cov, float amp, vec3 tint, float glow)&#10;{&#10;    vec2 d = max(abs(uv - 0.5) - 0.5, 0.0);&#10;    float g = exp(-length(d) * (3.0 + 30.0 * (1.0 - glow)));&#10;    return vec4(tint * amp * (cov * 0.95 + (1.0 - cov) * g * 0.7), 1.0);&#10;}&#10;&#10;// the picture's colour round a spot (5 samples, so one odd pixel does not decide it)&#10;vec3 keyColour(vec2 k)&#10;{&#10;    vec2 e = 2.0 / iResolution.xy;&#10;    return (texture(iImage0, k).rgb + texture(iImage0, k + vec2(e.x, 0.0)).rgb + texture(iImage0, k - vec2(e.x, 0.0)).rgb +&#10;            texture(iImage0, k + vec2(0.0, e.y)).rgb + texture(iImage0, k - vec2(0.0, e.y)).rgb) / 5.0;&#10;}&#10;&#10;// light added where the picture has (nearly) the key colour: tol how near, soft how gently it fades&#10;vec4 fxKeyGlow(vec3 pic, vec3 key, float tol, float soft, float amp, vec3 tint)&#10;{&#10;    float t0 = 0.02 + 0.45 * tol;&#10;    float mk = 1.0 - smoothstep(t0, t0 + 0.02 + 0.3 * soft, length(pic - key));&#10;    return vec4(tint * mk * amp * (0.6 + 0.8 * lum(pic)), 1.0);&#10;}&#10;&#10;// ---------- v1.7: edges that tell straight from round ----------&#10;// the picture's brightness gradient (Sobel), measured e pixels apart&#10;vec2 gradAt(vec2 uv, vec2 e)&#10;{&#10;    float tl = lumaAt(uv + vec2(-e.x, e.y)), t = lumaAt(uv + vec2(0.0, e.y)), tr = lumaAt(uv + e);&#10;    float l = lumaAt(uv - vec2(e.x, 0.0)), r = lumaAt(uv + vec2(e.x, 0.0));&#10;    float bl = lumaAt(uv - e), b = lumaAt(uv - vec2(0.0, e.y)), br = lumaAt(uv + vec2(e.x, -e.y));&#10;    return vec2(tr + 2.0 * r + br - tl - 2.0 * l - bl, tl + 2.0 * t + tr - bl - 2.0 * b - br);&#10;}&#10;&#10;// Edges with a filter: 0 all (green straight, pink round, white the rest), 1 straight only, 2 round only.&#10;// An edge is straight when it runs the same way a little further along it on both sides, round when it turns&#10;// gently (a corner turns sharply and counts as neither). sens 0..1 finds fainter edges, width 0..1 draws them wider.&#10;void edgeView(inout vec3 C, vec2 uv, int filt, float sens, float width)&#10;{&#10;    vec2 px = 1.0 / iResolution.xy;&#10;    vec2 e = px * (1.0 + 3.0 * width);&#10;    vec2 g = gradAt(uv, e);&#10;    float mag = length(g);&#10;    float thr = 0.8 * pow(0.04, sens);            // sens 0: only hard edges, 1: faint ones too&#10;    float on = smoothstep(thr * 0.7, thr * 1.3, mag);&#10;    if (on &lt;= 0.0) return;&#10;    vec2 n = g / max(mag, 1e-5);&#10;    // look about 24 pixels along the edge each way; a curve has bent away from the straight line by then,&#10;    // so search a little across it for where the edge is strongest&#10;    vec2 e2 = px * 2.5 * (1.0 + width);&#10;    vec2 n0 = gradAt(uv, e2);&#10;    n0 /= max(length(n0), 1e-5);&#10;    vec2 tg = vec2(-n0.y, n0.x) * 24.0 * px * (1.0 + width);&#10;    vec2 ga = vec2(0.0), gb = vec2(0.0);&#10;    for (int k = -3; k &lt;= 3; k++) {&#10;        vec2 o = n0 * float(k) * 3.0 * px;&#10;        vec2 a = gradAt(uv + tg + o, e2), b = gradAt(uv - tg + o, e2);&#10;        if (length(a) &gt; length(ga)) ga = a;&#10;        if (length(b) &gt; length(gb)) gb = b;&#10;    }&#10;    float ma = length(ga), mb = length(gb);&#10;    // how far the edge turns on each side, in radians; a side with no edge counts as a sharp turn&#10;    float ta = ma &gt; thr * 0.5 ? acos(clamp(abs(dot(n0, ga / ma)), 0.0, 1.0)) : 2.0;&#10;    float tb = mb &gt; thr * 0.5 ? acos(clamp(abs(dot(n0, gb / mb)), 0.0, 1.0)) : 2.0;&#10;    float turn = max(ta, tb);&#10;    float straight = 1.0 - smoothstep(0.05, 0.09, turn);&#10;    // round: both sides turn, gently (a corner turns about 1.57 and is neither)&#10;    float round_ = smoothstep(0.08, 0.14, min(ta, tb)) * (1.0 - smoothstep(0.7, 1.0, turn));&#10;    vec3 green = vec3(0.25, 1.0, 0.45), pink = vec3(1.0, 0.35, 0.85);&#10;    if (filt == 1) { C = mix(C, green, on * straight * 0.9); return; }&#10;    if (filt == 2) { C = mix(C, pink, on * round_ * 0.9); return; }&#10;    vec3 col = straight &gt; 0.5 ? green : round_ &gt; 0.5 ? pink : vec3(0.85);&#10;    C = mix(C, col, on * (straight &gt; 0.5 || round_ &gt; 0.5 ? 0.9 : 0.45));&#10;}&#10;&#10;// ---------- v1.8: how much of this pixel the quad covers, measured on screen ----------&#10;// The smallest distance in pixels to the four sides (plus half a pixel), so the edge is smooth however steep the&#10;// perspective. Measuring on the board's own 0..1 (as before) broke down near its vanishing line: thin stray lines.&#10;float sideDist(vec2 p, vec2 u, vec2 v, float s)&#10;{&#10;    vec2 t = v - u;&#10;    return s * (t.x * (p.y - u.y) - t.y * (p.x - u.x)) / max(length(t), 1e-4);&#10;}&#10;float quadCov(vec2 q, vec2 a, vec2 b, vec2 c, vec2 d, vec2 R)&#10;{&#10;    vec2 p = q * R; a *= R; b *= R; c *= R; d *= R;&#10;    float area = (a.x * b.y - b.x * a.y) + (b.x * c.y - c.x * b.y) + (c.x * d.y - d.x * c.y) + (d.x * a.y - a.x * d.y);&#10;    float s = area &lt; 0.0 ? -1.0 : 1.0;&#10;    float e = min(min(sideDist(p, a, b, s), sideDist(p, b, c, s)), min(sideDist(p, c, d, s), sideDist(p, d, a, s)));&#10;    return clamp(e + 0.5, 0.0, 1.0);&#10;}&#10;&#10;// ---------- v1.9: Edge glow, the picture's own edges light up ----------&#10;// uv: where on the picture (as texture() counts), amp: the light mode, sens 0..1: fainter edges too,&#10;// width 0..1: a wider glow round them, style 0 glow, 1 a wave running over them, 2 sparkles along them.&#10;vec4 fxEdgeGlow(vec2 uv, float t, float amp, vec3 tint, float sens, float width, int style)&#10;{&#10;    vec2 px = 1.0 / iResolution.xy;&#10;    vec2 e = px * 1.5;&#10;    float thr = 0.8 * pow(0.04, sens);&#10;    float core = smoothstep(thr * 0.7, thr * 1.3, length(gradAt(uv, e)));&#10;    float halo = 0.0;   // edges a little way off, for the glow round them&#10;    float r = 3.0 + 18.0 * width;&#10;    for (int j = 0; j &lt; 12; j++) {   // at three distances, turned a little each time, so the glow has no rings in it&#10;        float a = float(j) * 2.3998;&#10;        float d = r * (0.3 + 0.35 * float(j % 3));&#10;        halo += smoothstep(thr * 0.5, thr * 1.3, length(gradAt(uv + vec2(cos(a), sin(a)) * d * px, e))) * (1.15 - 0.3 * float(j % 3));&#10;    }&#10;    halo /= 12.0;&#10;    float k = 1.0;&#10;    vec2 fc = uv * iResolution.xy;&#10;    if (style == 1)&#10;        k = 0.15 + 1.6 * pow(0.5 + 0.5 * sin((fc.x * 0.8 + fc.y) * 0.012 - t * 3.0), 6.0);&#10;    else if (style == 2)&#10;        k = 0.1 + 2.0 * step(0.86, h21(floor(fc / 5.0) + floor(t * 6.0))) * core;&#10;    return vec4(tint * (core * 1.5 + halo * (0.3 + 0.9 * width)) * amp * k, 1.0);&#10;}&#10;&#10;// ---------- Cinemnode v1.1: the picture itself moves (m: where in the board, 0..1 from its top left) ----------&#10;float edgeFade(vec2 m, float w) { return smoothstep(0.0, w, min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y))); }&#10;vec3 picAt(vec2 uv) { return texture(iImage0, uv).rgb; }&#10;&#10;vec4 fxFlow(vec2 uv, vec2 m, float t, float dir, float len)   // water runs one way: two phases, faded into each other&#10;{&#10;    float a = dir * 6.2831853;&#10;    vec2 d = vec2(sin(a), -cos(a));   // 0: down, 90: right, 180: up, 270: left&#10;    float L = (0.008 + 0.07 * len) * edgeFade(m, 0.1);&#10;    float ph = vnoise(uv * 9.0) * 0.6;&#10;    float p1 = fract(t * 0.3 + ph), p2 = fract(t * 0.3 + ph + 0.5);&#10;    float w = 1.0 - abs(2.0 * p1 - 1.0);&#10;    return vec4(mix(picAt(uv - d * L * p2), picAt(uv - d * L * p1), w), 1.0);&#10;}&#10;&#10;vec4 fxSway(vec2 uv, vec2 m, float t, float wind, float size, int style)   // 0 grass (fixed at the bottom), 1 leaves, 2 flag (fixed on the left)&#10;{&#10;    float k = 2.0 + 10.0 * (1.0 - size);&#10;    float gust = 0.65 + 0.35 * sin(t * 0.37) * sin(t * 0.23 + 1.0);&#10;    float fade = edgeFade(m, 0.15);&#10;    vec2 off;&#10;    float shade = 1.0;&#10;    if (style == 2) {&#10;        float w = sin(m.x * k - t * 4.0 + vnoise(m * 3.0 + t * 0.3) * 2.0);&#10;        off = vec2(0.15 * w, w) * m.x;&#10;        shade = 1.0 + 0.18 * wind * cos(m.x * k - t * 4.0) * m.x;&#10;    } else {&#10;        float w = style == 0 ? 1.0 - m.y : 0.55 + 0.45 * vnoise(m * k + 4.0);&#10;        off = vec2(sin(t * 2.0 + m.x * k * 0.7 + vnoise(m * k) * 3.0) + 0.5 * sin(t * 3.3 + m.y * k), 0.0) * w;&#10;    }&#10;    off *= wind * 0.018 * gust * (style == 2 ? 1.0 : fade);&#10;    return vec4(picAt(uv + vec2(off.x, -off.y)) * shade, 1.0);&#10;}&#10;&#10;vec4 fxHaze(vec2 uv, vec2 m, float t, float amt, float size)   // air that trembles, rising, strongest low down&#10;{&#10;    vec2 p = m * (6.0 + 30.0 * (1.0 - size)) + vec2(0.0, t * 1.5);&#10;    vec2 d = vec2(vnoise(p) - 0.5, vnoise(p + 17.3) - 0.5);&#10;    d *= amt * 0.014 * edgeFade(m, 0.12) * (0.4 + 0.6 * m.y);&#10;    return vec4(picAt(uv + vec2(d.x, -d.y)), 1.0);&#10;}&#10;&#10;vec4 fxReflect(vec2 q, vec2 m, float t, vec2 a, vec2 b, float wave, float clear, vec3 tint)   // the picture above the board's top edge, mirrored and rippling&#10;{&#10;    float top = mix(a.y, b.y, clamp(m.x, 0.0, 1.0));&#10;    float dy = max(q.y - top, 0.0);&#10;    float rx = (sin(dy * 260.0 / (1.0 + dy * 12.0) - t * 3.0) + 0.6 * (vnoise(vec2(q.x * 40.0, dy * 90.0 - t * 1.5)) - 0.5)) * wave * 0.008 * (0.3 + dy * 10.0);&#10;    vec2 r = vec2(q.x + rx, top - dy - 0.002);&#10;    vec3 col = picAt(vec2(r.x, 1.0 - r.y)) * mix(vec3(1.0), tint, 0.35) * 0.8;&#10;    return vec4(col, clear * smoothstep(0.0, 0.01, dy + 0.004));&#10;}&#10;&#10;vec4 fxBreathe(vec2 uv, vec2 m, float t, vec2 ctr, float amt, float soft)   // a very slow zoom and drift&#10;{&#10;    vec2 c = vec2(ctr.x, 1.0 - ctr.y);&#10;    float z = 1.0 - amt * 0.05 * (0.5 + 0.5 * sin(t * 0.5));&#10;    vec2 drift = amt * 0.004 * vec2(sin(t * 0.31), cos(t * 0.23));&#10;    vec3 moved = picAt(c + (uv - c) * z + drift);&#10;    return vec4(mix(picAt(uv), moved, soft &gt; 0.5 ? edgeFade(m, 0.15) : 1.0), 1.0);&#10;}&#10;&#10;// ---------- Cinemnode v1.1: laid over the picture ----------&#10;vec4 fxParticles(vec2 p, float t, vec3 tint, float amount, float size, int style)   // 0 snow, 1 dust, 2 fireflies (p: fc / R.y)&#10;{&#10;    vec3 c = vec3(0.0);&#10;    float a = 0.0;&#10;    for (int L = 0; L &lt; 3; L++) {&#10;        float fl = float(L);&#10;        float sc = 5.0 + fl * 5.0;&#10;        vec2 off = style == 0 ? vec2(sin(t * 0.4 + fl) * 0.6, t * (1.2 + 0.5 * fl)) :&#10;                   style == 1 ? vec2(t * 0.12, sin(t * 0.2 + fl) * 0.3) : vec2(sin(t * 0.1 + fl) * 0.3, -t * 0.08);&#10;        vec2 g = p * sc + off;&#10;        vec2 id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + fl * 31.7);&#10;        if (h &gt; 0.15 + 0.85 * amount) continue;&#10;        vec2 o = (vec2(h21(id + 3.1), h21(id + 7.7)) - 0.5) * 0.5;&#10;        if (style == 0) o.x += 0.15 * sin(t * (1.0 + h) + h * 20.0);&#10;        if (style == 2) o += 0.2 * vec2(sin(t * (0.7 + h) + h * 20.0), cos(t * (0.9 + h) + h * 13.0));&#10;        float r = (0.04 + 0.1 * size) * (0.6 + 0.4 * h) * (1.0 - fl * 0.2);&#10;        float d = length(f - o);&#10;        float core = smoothstep(r, r * 0.3, d);&#10;        float halo = style == 2 ? 0.06 * r / (d * d + 0.004) * 0.02 : 0.0;&#10;        float tw = style == 2 ? 0.5 + 0.5 * sin(t * 3.0 * (0.5 + h) + h * 40.0) : style == 1 ? 0.55 + 0.45 * sin(t * 2.0 + h * 30.0) : 1.0;&#10;        c += tint * (core + halo) * tw * (style == 1 ? 0.6 : 1.0);&#10;        a = max(a, core * tw);&#10;    }&#10;    return style == 0 ? vec4(tint, clamp(a, 0.0, 1.0)) : vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxRays(vec2 m, float t, vec3 tint, float from, float many)   // sunbeams fanning down from above the board&#10;{&#10;    vec2 d = m - vec2(0.1 + 0.8 * from, -0.4);&#10;    float a = atan(d.x, d.y);&#10;    float r = vnoise(vec2(a * (8.0 + 24.0 * many), t * 0.15)) * vnoise(vec2(a * 23.0 + 5.0, t * 0.27 + 3.0));&#10;    r = smoothstep(0.08, 0.6, r);&#10;    float fall = smoothstep(1.6, 0.3, length(d));&#10;    float side = smoothstep(0.0, 0.12, m.x) * smoothstep(1.0, 0.88, m.x) * smoothstep(0.0, 0.08, m.y) * smoothstep(1.0, 0.8, m.y);&#10;    return vec4(tint * r * fall * side * 0.8, 1.0);&#10;}&#10;&#10;vec4 fxFire(vec2 m, float t, vec3 tint, float height, float detail)   // flames rising from the bottom of the board&#10;{&#10;    float up = 1.0 - m.y;&#10;    vec2 p = vec2(m.x * (3.0 + 4.0 * detail), up * (2.0 + 3.0 * detail));&#10;    float n = fbm(p * 1.5 - vec2(0.0, t * 2.2)) * 0.8 + fbm(p * 3.0 - vec2(t * 0.3, t * 3.5)) * 0.4;&#10;    float shape = 1.0 - up / (0.25 + 0.75 * height);&#10;    float side = 1.0 - pow(abs(m.x * 2.0 - 1.0), 2.0);&#10;    float f = clamp(shape * side * 1.6 + n - 0.9, 0.0, 1.0);&#10;    f *= smoothstep(0.0, 0.15, m.x) * smoothstep(1.0, 0.85, m.x) * smoothstep(0.0, 0.2, m.y);&#10;    vec3 col = vec3(1.5, 0.42, 0.08) * f + vec3(1.0, 0.85, 0.45) * pow(f, 3.0) * 1.5;&#10;    return vec4(col * mix(vec3(1.0), tint, 0.5) * 1.3, 1.0);&#10;}&#10;&#10;vec4 fxSteam(vec2 m, float t, vec3 tint, float amount, float width)   // soft wisps going up and fading&#10;{&#10;    vec2 p = vec2((m.x - 0.5) * (2.0 + 3.0 * (1.0 - width)), 1.0 - m.y);&#10;    p.x += 0.3 * sin(p.y * 3.0 - t * 1.3) * p.y;&#10;    float n = fbm(vec2(p.x * 2.5, p.y * 2.0 - t * 0.8));&#10;    float col = smoothstep(0.8, 0.0, abs(p.x) / (0.35 + p.y * 0.8));&#10;    float a = col * smoothstep(0.35, 0.75, n) * smoothstep(1.0, 0.4, p.y) * smoothstep(0.0, 0.1, p.y) * (0.6 + 1.2 * amount);&#10;    return vec4(tint, clamp(a, 0.0, 1.0));&#10;}&#10;&#10;vec4 fxLightning(vec2 m, float t, vec3 tint, float flash, float bolt, vec3 pic)   // now and then a strike: the picture lights up, with a bolt if you like&#10;{&#10;    float k = floor(t * 0.5), f = fract(t * 0.5);&#10;    float h = h11(k * 1.7 + 0.3);&#10;    if (h &lt; 0.4) return vec4(0.0);&#10;    float amp = exp(-f * 45.0) + 0.7 * exp(-max(f - 0.06, 0.0) * 35.0) * step(0.06, f);&#10;    vec3 c = (pic * 1.8 * flash + tint * 0.35 * flash) * amp;&#10;    if (bolt &gt; 0.01) {&#10;        float x = 0.2 + 0.6 * h11(k + 9.1);&#10;        x += (vnoise1(m.y * 6.0 + k * 13.0) - 0.5) * 0.25 + (vnoise1(m.y * 25.0 + k * 7.0) - 0.5) * 0.06;&#10;        float d = abs(m.x - x);&#10;        float b = (0.0015 / (d + 0.0015) + 0.25 * exp(-d * 30.0)) * smoothstep(1.0, 0.6, m.y / (0.5 + 0.5 * h11(k + 2.2)));&#10;        c += mix(vec3(1.0), tint, 0.4) * b * bolt * amp * 1.5;&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxGlass(vec2 p, vec2 uv, float t, vec3 tint, float drops, float mist)   // drops on a window, running down, the picture bent in them (p: fc / R.y)&#10;{&#10;    vec2 n = vec2(0.0);&#10;    float mask = 0.0;&#10;    for (int L = 0; L &lt; 2; L++) {   // drops that sit, grow and go&#10;        float sc = 16.0 + 12.0 * float(L);&#10;        vec2 g = p * sc, id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + float(L) * 7.0);&#10;        if (h &lt; 0.15 + 0.7 * drops) {&#10;            vec2 o = (vec2(h21(id + 1.3), h21(id + 2.7)) - 0.5) * 0.6;&#10;            float life = fract(t * 0.05 + h * 7.0);&#10;            float r = (0.12 + 0.2 * h21(id + 4.1)) * smoothstep(1.0, 0.8, life) * smoothstep(0.0, 0.05, life);&#10;            vec2 d = (f - o) / max(r, 0.001);&#10;            float k = smoothstep(1.0, 0.8, length(d));&#10;            mask = max(mask, k);&#10;            n += d * k;&#10;        }&#10;    }&#10;    {   // drops that run down, leaving a trail&#10;        float sc = 7.0;&#10;        float cx = floor(p.x * sc), fx = fract(p.x * sc) - 0.5;&#10;        float h = h11(cx * 3.7);&#10;        if (h &lt; 0.2 + 0.6 * drops) {&#10;            float wob = 0.15 * sin(p.y * 9.0 + h * 20.0);&#10;            float yy = fract(p.y * 0.5 + t * (0.05 + 0.08 * h) + h);&#10;            vec2 d = vec2((fx - wob) / 0.16, (yy - 0.5) * 9.0);&#10;            float k = smoothstep(1.0, 0.8, length(d));&#10;            float trail = smoothstep(0.06, 0.0, abs(fx - wob)) * step(0.5, yy) * smoothstep(1.0, 0.5, yy) * 0.6;&#10;            mask = max(mask, max(k, trail));&#10;            n += d * k + vec2((fx - wob) * 4.0, 0.0) * trail;&#10;        }&#10;    }&#10;    vec3 blur = vec3(0.0);&#10;    for (int i = 0; i &lt; 8; i++) {&#10;        float a = float(i) * 0.785398;&#10;        blur += picAt(uv + vec2(cos(a), sin(a)) * 0.006 * mist);&#10;    }&#10;    blur /= 8.0;&#10;    vec3 drop = picAt(uv - n * 0.035) * 1.1 + tint * pow(max(0.0, dot(normalize(n + 1e-4), vec2(-0.6, 0.8))), 4.0) * 0.35 * mask;&#10;    vec3 col = mix(blur * (1.0 + 0.15 * mist), drop, mask);&#10;    return vec4(col, max(mask, clamp(mist * 1.2, 0.0, 1.0)));&#10;}&#10;&#10;vec4 fxSparkle(vec2 fc, float t, vec3 tint, float amount, float size, float S, float bright)   // glints that come and go where the water is bright&#10;{&#10;    vec2 g = fc / (S * (8.0 + 14.0 * size));&#10;    vec2 id = floor(g), f = fract(g) - 0.5;&#10;    float h = h21(id);&#10;    if (h &gt; 0.1 + 0.6 * amount) return vec4(0.0);&#10;    vec2 d = f - (vec2(h21(id + 1.7), h21(id + 4.3)) - 0.5) * 0.6;&#10;    float tw = pow(max(0.0, sin(t * 3.0 * (0.6 + h) + h * 60.0)), 24.0);&#10;    float star = pow(max(0.0, 1.0 - length(d) * 5.0), 3.0) + 0.004 / (abs(d.x) + 0.01) * smoothstep(0.3, 0.0, abs(d.y)) + 0.004 / (abs(d.y) + 0.01) * smoothstep(0.3, 0.0, abs(d.x));&#10;    return vec4(tint * min(star, 3.0) * tw * smoothstep(0.12, 0.7, bright) * 1.5, 1.0);&#10;}&#10;&#10;&#10;vec4 fxCustom(vec2 uv, float t, vec3 tint)&#10;{&#10;    float r = length(uv - 0.5);&#10;    float w = 0.5 + 0.5 * sin(r * 40.0 - t * 4.0);&#10;    return vec4(tint * w, 1.0);&#10;}&#10;&#10;void sceneImage(out vec4 o, in vec2 fc)&#10;{&#10;    vec2 R = iResolution.xy;&#10;    vec2 uv = fc / R;&#10;    vec3 C = vec3(0.0);   // the colour, times how much covers&#10;    float A = 0.0;        // how much covers: where it is 0 the picture under the Scene shows&#10;    vec2 q = vec2(uv.x, 1.0 - uv.y);   // as the editor counts: from the top left&#10;    float S = R.y / 1080.0, T = iTime;&#10;    o = A &gt; 0.0001 ? vec4(min(C / A, vec3(1.0)), A) : vec4(0.0);&#10;}&#10;&#10;void mainImage(out vec4 o, in vec2 fc)&#10;{&#10;    if (P27 &lt; 0.0001) { sceneImage(o, fc); return; }&#10;    vec2 R = iResolution.xy;&#10;    vec2 p = (vec2(fc.x / R.x, 1.0 - fc.y / R.y) - (vec2(P25, P26) - 0.5) * 20.0) / (P27 * 10.0);   // where in the picture, from its top left&#10;    if (p.x &lt; 0.0 || p.y &lt; 0.0 || p.x &gt; 1.0 || p.y &gt; 1.0) {&#10;        vec2 k = floor(fc / (12.0 * R.y / 1080.0));&#10;        o = vec4(vec3(0.05, 0.045, 0.075) + 0.012 * mod(k.x + k.y, 2.0), 1.0);   // the ground round it&#10;        return;&#10;    }&#10;    sceneImage(o, vec2(p.x, 1.0 - p.y) * R);&#10;    if (o.a &lt; 1.0) {   // see-through parts show a chequer, as in Photoshop&#10;        vec2 k = floor(p * vec2(1920.0, 1080.0) / 16.0);&#10;        vec3 g = vec3(0.15, 0.14, 0.19) + 0.05 * mod(k.x + k.y, 2.0);&#10;        o = vec4(mix(g, o.rgb, o.a), 1.0);&#10;    }&#10;}&#10;" zones="" zonevalues="" labels="DARC SECTOR&#10;OPEN 24/7&#10;HOTEL&#10;BAR&#10;TECHNO TONIGHT&#10;NO PARKING" image1="" image2="" fontFile="" preserveBuffers="0" resolution="0" framerate="0" transparent="1" background="00000000" keyboard="0" zoneinputs="0" showOrientation="0" showObjectAxes="0" visible="1" ignoreClicks="0" panelX="0.0" panelY="0.0" panelW="1920.0" panelH="1080.0" tooltipStyle="" exposeToDAW="0" panel_visible="1"/>
        </node>
        <node id="2" type="flow.script" title="Cinemnode Editor" expanded="0" x="-1100.0" y="0.0" w="900.0" h="1000.0">
          <state code="// Cinemnode v1.4 (was Scene Kit), in Darc Sector colours: signs, screens and lights to lay over a picture of your own. The Scene has no picture and is&#10;// see-through (Transparent on) where nothing is: put a Widget Image under it on the front panel, both 1920 x 1080.&#10;// Edit mode: drag a sign's corners to fit it into the picture, drag it to move, mouse wheel to make it&#10;// bigger or smaller (Shift + wheel turns it); double-click an empty spot for a new light; right-click deletes.&#10;// Out of Edit mode only the effects are left. Back to Edit mode: double-click anywhere on the Scene, or a&#10;// message on In 1 (a Widget Toggle, for instance).&#10;// Laid out as in Photoshop: the tools down the left (add a board or a light, copy, delete, picture, edges, snap,&#10;// clear, panels, done), and a dock on the right with Properties and Layers, each folding in by its header; the tab&#10;// on the dock's edge (or Panels) folds the whole dock away. The wheel scrolls the dock when it is too long.&#10;// Layers lists every element: click a name to select it, the eye hides it, the lock keeps it in place&#10;// (no handles, no Delete), the arrows move it to the front or the back.&#10;// Edge glow (with a background): the picture's own edges inside the board light up: Glow, Running or Sparkle.&#10;// In Edit mode the picture fits between the toolbar and the dock, so nothing hides under them: the wheel on an&#10;// empty spot zooms in where the mouse is, dragging an empty spot moves the picture, Fit puts it back.&#10;// Picture (or Choose... in Properties with nothing selected): Out 2 opens the File node's dialog, the path comes back on In 2 and becomes the Scene's Image 1,&#10;// drawn under everything (stretched to 1920 x 1080). With a background, Edges outlines what is in the picture and&#10;// a magnifier shows the picture under a corner or a light while you drag it, and a Ripple bends the picture.&#10;// Picture (with a background): an effect can follow the picture under it: Surface (the picture's light and shade&#10;// show through it), Bright parts or Dark parts only; a Ripple goes On top or In the picture (bends it).&#10;// Colours: the swatches, your own palette (+ keeps the current colour, right-click forgets one), Red/Green/Blue (0-255)&#10;// or Hue/Saturation/Value, and the colour as a code: click it to type #RGB, #RGBA, #RRGGBB or #RRGGBBAA on the keys&#10;// that open under it (the last two digits, alpha, set its Transparency). A Text Input on In 3 takes a code too, or 255, 128, 0.&#10;// Edges can show only Straight (rectangles) or Round (circles) edges. Snap pulls what you drag onto the corners of&#10;// the other boards, the lights and the sides of the Scene (Alt while dragging: no snap). A board's corners either&#10;// shape it, or with Corners: Scale (or Ctrl while dragging) scale the whole board from the opposite corner.&#10;// Everything is kept with the project.&#10;// Out 1 -&gt; Scene Objects. The effects are GLSL, made here and sent to the Scene as its code.&#10;&#10;// The lines for the Text effect (at most 16). Change them here.&#10;const TEXTS = ['DARC SECTOR', 'OPEN 24/7', 'HOTEL', 'BAR', 'TECHNO TONIGHT', 'NO PARKING'];&#10;&#10;// Your own effect, for the effect &quot;Custom&quot;: uv goes 0..1 across and down the sign, t is the time&#10;// (times its Speed), tint its Colour. Return the colour and its cover (1 = solid).&#10;const CUSTOM = `&#10;vec4 fxCustom(vec2 uv, float t, vec3 tint)&#10;{&#10;    float r = length(uv - 0.5);&#10;    float w = 0.5 + 0.5 * sin(r * 40.0 - t * 4.0);&#10;    return vec4(tint * w, 1.0);&#10;}&#10;`;&#10;&#10;const SHARED = `// Cinemnode (was Scene Kit): shared helpers and effects. The Script adds mainImage with every element.&#10;float h11(float n) { return fract(sin(n * 12.9898) * 43758.5453); }&#10;float h21(vec2 p) { return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }&#10;float vnoise(vec2 p)&#10;{&#10;    vec2 i = floor(p), f = fract(p);&#10;    f = f * f * (3.0 - 2.0 * f);&#10;    return mix(mix(h21(i), h21(i + vec2(1.0, 0.0)), f.x), mix(h21(i + vec2(0.0, 1.0)), h21(i + vec2(1.0, 1.0)), f.x), f.y);&#10;}&#10;float vnoise1(float x)&#10;{&#10;    float i = floor(x), f = fract(x);&#10;    f = f * f * (3.0 - 2.0 * f);&#10;    return mix(h11(i), h11(i + 1.0), f);&#10;}&#10;&#10;// Where p lies in the quad a (top left), b (top right), c (bottom right), d (bottom left): 0..1 each way, v down.&#10;// A perspective (projective) map, so a flat sign photographed at an angle is filled the way it really is.&#10;vec2 quadUV(vec2 p, vec2 a, vec2 b, vec2 c, vec2 d)&#10;{&#10;    float sx = a.x - b.x + c.x - d.x, sy = a.y - b.y + c.y - d.y;&#10;    float dx1 = b.x - c.x, dx2 = d.x - c.x, dy1 = b.y - c.y, dy2 = d.y - c.y;&#10;    float den = dx1 * dy2 - dx2 * dy1;&#10;    if (abs(den) &lt; 1e-9) return vec2(-10.0);&#10;    float g = (sx * dy2 - dx2 * sy) / den;&#10;    float h = (dx1 * sy - sx * dy1) / den;&#10;    float A = b.x - a.x + g * b.x, B = d.x - a.x + h * d.x, C = a.x;&#10;    float D = b.y - a.y + g * b.y, E = d.y - a.y + h * d.y, F = a.y;&#10;    // the inverse, by the adjugate (the determinant cancels in the division)&#10;    float i00 = E - F * h, i01 = C * h - B, i02 = B * F - C * E;&#10;    float i10 = F * g - D, i11 = A - C * g, i12 = C * D - A * F;&#10;    float i20 = D * h - E * g, i21 = B * g - A * h, i22 = A * E - B * D;&#10;    vec3 r = vec3(i00 * p.x + i01 * p.y + i02, i10 * p.x + i11 * p.y + i12, i20 * p.x + i21 * p.y + i22);&#10;    vec2 m = (a + b + c + d) * 0.25;&#10;    float wm = i20 * m.x + i21 * m.y + i22;&#10;    if (r.z * wm &lt;= 0.0) return vec2(-10.0);   // beyond the vanishing line&#10;    return r.xy / r.z;&#10;}&#10;&#10;// ---------- effects for a sign: each gives a colour and how much of it covers ----------&#10;vec4 fxPlasma(vec2 uv, float t, vec3 tint)&#10;{&#10;    vec2 p = uv * 6.0;&#10;    float v = sin(p.x + t) + sin(p.y * 1.3 - t * 1.1) + sin((p.x + p.y) * 0.7 + t * 0.8) + sin(length(p - 3.0) * 1.5 - t * 1.6);&#10;    vec3 c = 0.5 + 0.5 * cos(6.2832 * (v * 0.15 + vec3(0.0, 0.33, 0.67)) + t * 0.3);&#10;    return vec4(mix(c, c * tint, 0.35), 1.0);&#10;}&#10;&#10;vec4 fxText(vec2 uv, float t, vec3 tint, float cov)&#10;{&#10;    vec3 bg = vec3(0.015, 0.015, 0.03) + tint * 0.05 * (0.5 + 0.5 * sin(uv.y * 300.0));&#10;    vec3 c = mix(bg, tint * 1.5 + 0.15, cov);&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxGlitch(vec2 uv, float t, vec3 tint)&#10;{&#10;    float band = floor(uv.y * 24.0);&#10;    float g = step(0.82, h21(vec2(band, floor(t * 8.0))));&#10;    vec2 u = uv;&#10;    u.x += g * (h21(vec2(band, floor(t * 16.0))) - 0.5) * 0.3;&#10;    vec3 c = vec3(h21(floor(u * vec2(160.0, 90.0)) + floor(t * 24.0))) * 0.3;&#10;    vec2 cell = floor(u * vec2(8.0, 4.0) + vec2(t * 0.5, 0.0));&#10;    c += tint * step(0.6, h21(cell + floor(t * 2.0))) * 0.75;&#10;    c.r += 0.35 * g;&#10;    c.b += 0.3 * step(0.9, h21(vec2(band * 3.1, floor(t * 12.0))));&#10;    c *= 0.8 + 0.2 * sin(uv.y * 420.0);&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxBars(vec2 uv, float t, vec3 tint)&#10;{&#10;    float x = fract(uv.x + t * 0.04);&#10;    float i = floor(x * 7.0);&#10;    vec3 c = vec3((i &lt; 1.5 || (i &gt; 3.5 &amp;&amp; i &lt; 5.5)) ? 1.0 : 0.0, i &lt; 3.5 ? 1.0 : 0.0, mod(i, 2.0) &lt; 0.5 ? 1.0 : 0.0) * 0.8;&#10;    if (uv.y &gt; 0.78) c = vec3(fract(uv.x * 4.0 - t * 0.2)) * 0.9;&#10;    float roll = fract(uv.y - t * 0.15);&#10;    c *= 1.0 - 0.35 * smoothstep(0.9, 1.0, roll);&#10;    c += (h21(floor(uv * vec2(200.0, 120.0)) + floor(t * 30.0)) - 0.5) * 0.08;&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxRetro(vec2 uv, float t, vec3 tint)&#10;{&#10;    vec2 p = vec2(uv.x - 0.5, 1.0 - uv.y);&#10;    float hz = 0.42;&#10;    vec3 c;&#10;    if (p.y &gt; hz) {&#10;        c = mix(vec3(0.35, 0.05, 0.4), vec3(0.03, 0.0, 0.12), (p.y - hz) / (1.0 - hz));&#10;        vec2 s = vec2(p.x * 1.6, p.y - 0.62);&#10;        float r = length(s);&#10;        float gaps = step(0.5, fract((p.y - hz) * 22.0 + t * 0.6)) + step(0.7, p.y);&#10;        c = mix(c, mix(vec3(1.0, 0.25, 0.5), vec3(1.0, 0.85, 0.2), (p.y - 0.42) / 0.38), (1.0 - smoothstep(0.24, 0.25, r)) * min(gaps, 1.0));&#10;    } else {&#10;        float z = 0.08 / max(hz - p.y, 0.001);&#10;        vec2 g = vec2(p.x * z * 6.0, z + t);&#10;        vec2 f = abs(fract(g) - 0.5);&#10;        float w = 0.04 * z;&#10;        float line = max(1.0 - smoothstep(0.0, w + 0.02, 0.5 - f.x), 1.0 - smoothstep(0.0, w + 0.02, 0.5 - f.y));&#10;        c = mix(vec3(0.03, 0.0, 0.08), tint * 0.6 + vec3(0.6, 0.1, 0.8) * 0.6, line * exp(-z * 0.05));&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;&#10;vec4 fxWindow(vec2 uv, float t, vec3 tint)   // added to the photo: a lit window&#10;{&#10;    float e = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));&#10;    float f = 0.85 + 0.15 * vnoise1(t * 5.0);&#10;    float lit = (0.6 + 0.4 * smoothstep(0.0, 0.12, e)) * (1.0 - 0.3 * uv.y);   // lighter towards the ceiling lamp&#10;    return vec4(tint * f * lit * 0.8, 1.0);&#10;}&#10;&#10;vec4 fxNeon(vec2 uv, float t, vec3 tint)     // added to the photo: a neon tube along the edge&#10;{&#10;    float e = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));&#10;    float tube = 1.0 - smoothstep(0.006, 0.016, abs(e - 0.035));&#10;    float glow = exp(-abs(e - 0.035) * 30.0) * 0.5;&#10;    float on = 0.85 + 0.15 * sin(t * 40.0) * step(0.93, h11(floor(t * 3.0)));&#10;    return vec4(tint * (tube * 1.6 + glow) * on, 1.0);&#10;}&#10;&#10;// ---------- lights ----------&#10;// mode: 0 on, 1 slow blink, 2 twinkle, 3 broken tube, 4 pulse, 5 strobe, 6 candle&#10;float lampAmp(int mode, float t, float seed)&#10;{&#10;    if (mode == 1) { float s = fract(t * 0.5 + seed); return smoothstep(0.0, 0.08, s) * (1.0 - smoothstep(0.5, 0.58, s)); }&#10;    if (mode == 2) { float n = vnoise1(t * 4.0 + seed * 37.0); return 0.12 + 1.2 * n * n * n; }&#10;    if (mode == 3) {&#10;        float bad = h11(floor(t * 0.7) + seed * 91.0);&#10;        float fast = step(0.4, h11(floor(t * 17.0) + seed * 13.0));&#10;        return bad &gt; 0.55 ? fast * 0.95 : 0.9 + 0.1 * vnoise1(t * 30.0);&#10;    }&#10;    if (mode == 4) return 0.55 + 0.45 * sin(6.2832 * (t * 0.5 + seed));&#10;    if (mode == 5) { float s = fract(t * 2.0 + seed); return 1.0 - smoothstep(0.0, 0.07, s); }&#10;    if (mode == 6) return 0.7 + 0.3 * vnoise1(t * 7.0 + seed * 20.0) * (0.6 + 0.4 * vnoise1(t * 2.3 + seed * 5.0));&#10;    return 1.0;&#10;}&#10;&#10;vec3 lamp(vec2 fc, vec2 pos, float r, float amp, vec3 lc, float rays)&#10;{&#10;    vec2 d = fc - pos;&#10;    float l = length(d) / r;&#10;    float g = exp(-l * l * 18.0) * 1.6 + 0.5 / (1.0 + l * l * 10.0) * (1.0 - smoothstep(0.4, 1.4, l));&#10;    vec2 a = abs(d) / r;&#10;    g += rays * (exp(-a.x * 40.0 - a.y * 2.2) + exp(-a.y * 40.0 - a.x * 2.2)) * 0.8;&#10;    return lc * amp * g;&#10;}&#10;&#10;// light added to what is drawn so far: C is the colour times its cover, A the cover&#10;void glowAdd(inout vec3 C, inout float A, vec3 add)&#10;{&#10;    C += add;&#10;    A = max(A, clamp(max(add.r, max(add.g, add.b)), 0.0, 1.0));&#10;}&#10;&#10;// rain: thin streaks falling a little slanted, in three layers (far ones smaller, slower and fainter).&#10;// p is the place on the screen in screen heights (y up), so the drops keep their size on any sign&#10;vec4 fxRain(vec2 p, float t, vec3 tint)&#10;{&#10;    float a = 0.0;&#10;    for (int i = 0; i &lt; 3; i++) {&#10;        float fi = float(i);&#10;        float sc = 1.0 + fi * 0.8;                    // far layers: more, smaller drops&#10;        float cols = 70.0 * sc;&#10;        float x = (p.x + p.y * 0.12) * cols;          // slanted by the wind&#10;        float cx = floor(x);&#10;        float r1 = h21(vec2(cx, fi * 17.0)), r2 = h21(vec2(cx, fi * 31.0 + 5.0));&#10;        float len = 0.10 / sc;                         // a drop's streak, in screen heights&#10;        float y = p.y * (1.0 / len) * 0.25 + t * (9.0 - fi * 2.0) * (0.8 + 0.4 * r1) + r2 * 10.0;&#10;        float drop = fract(y);&#10;        float streak = smoothstep(0.0, 0.05, drop) * (1.0 - smoothstep(0.08, 0.25, drop));&#10;        float thin = 1.0 - smoothstep(0.06, 0.16, abs(fract(x) - 0.5));&#10;        float here = step(0.55, h21(vec2(cx, floor(y) + fi * 7.0)));   // not every column has a drop each time&#10;        a += streak * thin * here * (0.6 - fi * 0.17);&#10;    }&#10;    return vec4(tint, clamp(a, 0.0, 1.0));   // only the streaks cover: the picture shows between them&#10;}&#10;&#10;// ripples in water: rings that start in the middle of the sign and spread out, three at a time, fading as they go.&#10;// The crests are drawn light (tint), the troughs dark, each only as much as strength says; between the rings it is clear.&#10;// size: how far a ring gets (0.5 = to the edge of the sign)&#10;float rippleV(vec2 uv, float t, float size)   // the water's height: + crests, - troughs&#10;{&#10;    float r = length(uv - 0.5) * 2.0;             // 0 in the middle, 1 at the sides&#10;    float rmax = 0.15 + 1.25 * size;&#10;    float v = 0.0;&#10;    for (int k = 0; k &lt; 3; k++) {&#10;        float age = fract(t * 0.25 + float(k) / 3.0);&#10;        float d = r - age * rmax;                  // how far behind the front of this ring&#10;        float w = 0.05 + 0.08 * age;               // the rings widen as they spread&#10;        v += sin(d / w * 3.1416 * 1.5) * exp(-d * d / (w * w * 2.0)) * (1.0 - age) * (1.0 - age);&#10;    }&#10;    return v * (1.0 - smoothstep(0.85, 1.0, r));  // dies out before the edge of the sign&#10;}&#10;&#10;vec4 fxRipple(vec2 uv, float t, vec3 tint, float size, float strength)&#10;{&#10;    float v = rippleV(uv, t, size);&#10;    float a = clamp(abs(v) * strength * 1.6, 0.0, 1.0);&#10;    return vec4(v &gt; 0.0 ? tint : vec3(0.0), a);&#10;}&#10;&#10;// ---------- edit aids (only with a background in Image 1) ----------&#10;float lumaAt(vec2 uv) { return dot(texture(iImage0, uv).rgb, vec3(0.299, 0.587, 0.114)); }&#10;&#10;// how much of an edge the picture has here (Sobel), so windows, signs and lamps stand out to place things on&#10;float edgeAt(vec2 uv)&#10;{&#10;    vec2 e = 1.5 / iResolution.xy;&#10;    float tl = lumaAt(uv + vec2(-e.x, e.y)), t = lumaAt(uv + vec2(0.0, e.y)), tr = lumaAt(uv + e);&#10;    float l = lumaAt(uv - vec2(e.x, 0.0)), r = lumaAt(uv + vec2(e.x, 0.0));&#10;    float bl = lumaAt(uv - e), b = lumaAt(uv - vec2(0.0, e.y)), br = lumaAt(uv + vec2(e.x, -e.y));&#10;    float gx = tr + 2.0 * r + br - tl - 2.0 * l - bl;&#10;    float gy = tl + 2.0 * t + tr - bl - 2.0 * b - br;&#10;    return smoothstep(0.08, 0.3, length(vec2(gx, gy)));&#10;}&#10;&#10;// a round magnifier beside the point p (pixels): the background 4 times bigger, with a cross on p&#10;void magnifier(inout vec3 C, vec2 fc, vec2 p)&#10;{&#10;    vec2 R = iResolution.xy;&#10;    float S = R.y / 1080.0, rad = 110.0 * S;&#10;    vec2 off = vec2(p.x &gt; R.x - 300.0 * S ? -150.0 : 150.0, p.y &gt; R.y - 300.0 * S ? -150.0 : 150.0) * S;&#10;    vec2 m = p + off;&#10;    float d = length(fc - m);&#10;    if (d &gt; rad + 3.0 * S) return;&#10;    vec2 src = p + (fc - m) / 4.0;&#10;    vec3 col = texture(iImage0, src / R).rgb;&#10;    vec2 a = abs(fc - m);&#10;    float cross = (1.0 - smoothstep(0.5, 1.5, min(a.x, a.y) / S)) * step(max(a.x, a.y), 18.0 * S);&#10;    col = mix(col, vec3(0.54, 0.25, 1.0), cross);&#10;    C = mix(col, vec3(0.54, 0.25, 1.0), smoothstep(rad - 1.0, rad, d));&#10;}&#10;&#10;// ---------- v1.6 ----------&#10;float lum(vec3 c) { return dot(c, vec3(0.299, 0.587, 0.114)); }&#10;float fbm(vec2 p)&#10;{&#10;    float v = 0.0, a = 0.5;&#10;    for (int i = 0; i &lt; 5; i++) { v += a * vnoise(p); p = p * 2.03 + vec2(1.7, 9.2); a *= 0.5; }&#10;    return v;&#10;}&#10;&#10;// how an effect follows the picture under it: 1 its light and shade show through, 2 only on bright parts, 3 only on dark parts&#10;void picReact(inout vec4 s, int mode, vec3 pic)&#10;{&#10;    float l = lum(pic);&#10;    if (mode == 1) s.rgb *= 0.25 + 1.5 * l;&#10;    if (mode == 2) s.a *= smoothstep(0.3, 0.6, l);&#10;    if (mode == 3) s.a *= 1.0 - smoothstep(0.3, 0.6, l);&#10;}&#10;&#10;// clouds drifting across the board, see-through between them, fading at its edges&#10;vec4 fxClouds(vec2 uv, float t, vec3 tint)&#10;{&#10;    vec2 p = uv * vec2(3.0, 2.0) + vec2(t * 0.15, 0.0);&#10;    float n = fbm(p + 0.5 * fbm(p * 0.7 - vec2(t * 0.05, 0.0)));&#10;    float a = smoothstep(0.42, 0.75, n);&#10;    vec3 col = mix(tint * 0.55, tint, smoothstep(0.45, 0.9, n));   // lit tops, darker bellies&#10;    float e = smoothstep(0.0, 0.15, uv.x) * smoothstep(0.0, 0.15, 1.0 - uv.x) * smoothstep(0.0, 0.15, uv.y) * smoothstep(0.0, 0.15, 1.0 - uv.y);&#10;    return vec4(col, a * e);&#10;}&#10;&#10;// smoke rising from the middle of the board's bottom edge, swaying and widening as it goes up, gone at the top&#10;vec4 fxSmoke(vec2 uv, float t, vec3 tint)&#10;{&#10;    float h = 1.0 - uv.y;                          // 0 at the bottom, 1 at the top&#10;    float x = uv.x - 0.5;&#10;    float sway = (fbm(vec2(h * 1.5 - t * 0.25, 3.0)) - 0.5) * 0.5 * h;&#10;    float wdt = 0.05 + 0.32 * h;&#10;    float plume = exp(-pow((x - sway) / wdt, 2.0));&#10;    float n = fbm(vec2(x * 4.0 / (0.3 + h), h * 3.0 - t * 0.8));&#10;    float a = plume * (0.35 + 0.65 * smoothstep(0.2, 0.65, n)) * (1.0 - smoothstep(0.5, 1.0, h)) * smoothstep(0.0, 0.06, h);&#10;    return vec4(tint * (0.6 + 0.4 * n), clamp(a * 0.9, 0.0, 1.0));&#10;}&#10;&#10;// a lit rectangle (cov: how much of the pixel is inside) with a glow round it, glow 0..1 its reach&#10;vec4 fxLightBox(vec2 uv, float cov, float amp, vec3 tint, float glow)&#10;{&#10;    vec2 d = max(abs(uv - 0.5) - 0.5, 0.0);&#10;    float g = exp(-length(d) * (3.0 + 30.0 * (1.0 - glow)));&#10;    return vec4(tint * amp * (cov * 0.95 + (1.0 - cov) * g * 0.7), 1.0);&#10;}&#10;&#10;// the picture's colour round a spot (5 samples, so one odd pixel does not decide it)&#10;vec3 keyColour(vec2 k)&#10;{&#10;    vec2 e = 2.0 / iResolution.xy;&#10;    return (texture(iImage0, k).rgb + texture(iImage0, k + vec2(e.x, 0.0)).rgb + texture(iImage0, k - vec2(e.x, 0.0)).rgb +&#10;            texture(iImage0, k + vec2(0.0, e.y)).rgb + texture(iImage0, k - vec2(0.0, e.y)).rgb) / 5.0;&#10;}&#10;&#10;// light added where the picture has (nearly) the key colour: tol how near, soft how gently it fades&#10;vec4 fxKeyGlow(vec3 pic, vec3 key, float tol, float soft, float amp, vec3 tint)&#10;{&#10;    float t0 = 0.02 + 0.45 * tol;&#10;    float mk = 1.0 - smoothstep(t0, t0 + 0.02 + 0.3 * soft, length(pic - key));&#10;    return vec4(tint * mk * amp * (0.6 + 0.8 * lum(pic)), 1.0);&#10;}&#10;&#10;// ---------- v1.7: edges that tell straight from round ----------&#10;// the picture's brightness gradient (Sobel), measured e pixels apart&#10;vec2 gradAt(vec2 uv, vec2 e)&#10;{&#10;    float tl = lumaAt(uv + vec2(-e.x, e.y)), t = lumaAt(uv + vec2(0.0, e.y)), tr = lumaAt(uv + e);&#10;    float l = lumaAt(uv - vec2(e.x, 0.0)), r = lumaAt(uv + vec2(e.x, 0.0));&#10;    float bl = lumaAt(uv - e), b = lumaAt(uv - vec2(0.0, e.y)), br = lumaAt(uv + vec2(e.x, -e.y));&#10;    return vec2(tr + 2.0 * r + br - tl - 2.0 * l - bl, tl + 2.0 * t + tr - bl - 2.0 * b - br);&#10;}&#10;&#10;// Edges with a filter: 0 all (green straight, pink round, white the rest), 1 straight only, 2 round only.&#10;// An edge is straight when it runs the same way a little further along it on both sides, round when it turns&#10;// gently (a corner turns sharply and counts as neither). sens 0..1 finds fainter edges, width 0..1 draws them wider.&#10;void edgeView(inout vec3 C, vec2 uv, int filt, float sens, float width)&#10;{&#10;    vec2 px = 1.0 / iResolution.xy;&#10;    vec2 e = px * (1.0 + 3.0 * width);&#10;    vec2 g = gradAt(uv, e);&#10;    float mag = length(g);&#10;    float thr = 0.8 * pow(0.04, sens);            // sens 0: only hard edges, 1: faint ones too&#10;    float on = smoothstep(thr * 0.7, thr * 1.3, mag);&#10;    if (on &lt;= 0.0) return;&#10;    vec2 n = g / max(mag, 1e-5);&#10;    // look about 24 pixels along the edge each way; a curve has bent away from the straight line by then,&#10;    // so search a little across it for where the edge is strongest&#10;    vec2 e2 = px * 2.5 * (1.0 + width);&#10;    vec2 n0 = gradAt(uv, e2);&#10;    n0 /= max(length(n0), 1e-5);&#10;    vec2 tg = vec2(-n0.y, n0.x) * 24.0 * px * (1.0 + width);&#10;    vec2 ga = vec2(0.0), gb = vec2(0.0);&#10;    for (int k = -3; k &lt;= 3; k++) {&#10;        vec2 o = n0 * float(k) * 3.0 * px;&#10;        vec2 a = gradAt(uv + tg + o, e2), b = gradAt(uv - tg + o, e2);&#10;        if (length(a) &gt; length(ga)) ga = a;&#10;        if (length(b) &gt; length(gb)) gb = b;&#10;    }&#10;    float ma = length(ga), mb = length(gb);&#10;    // how far the edge turns on each side, in radians; a side with no edge counts as a sharp turn&#10;    float ta = ma &gt; thr * 0.5 ? acos(clamp(abs(dot(n0, ga / ma)), 0.0, 1.0)) : 2.0;&#10;    float tb = mb &gt; thr * 0.5 ? acos(clamp(abs(dot(n0, gb / mb)), 0.0, 1.0)) : 2.0;&#10;    float turn = max(ta, tb);&#10;    float straight = 1.0 - smoothstep(0.05, 0.09, turn);&#10;    // round: both sides turn, gently (a corner turns about 1.57 and is neither)&#10;    float round_ = smoothstep(0.08, 0.14, min(ta, tb)) * (1.0 - smoothstep(0.7, 1.0, turn));&#10;    vec3 green = vec3(0.25, 1.0, 0.45), pink = vec3(1.0, 0.35, 0.85);&#10;    if (filt == 1) { C = mix(C, green, on * straight * 0.9); return; }&#10;    if (filt == 2) { C = mix(C, pink, on * round_ * 0.9); return; }&#10;    vec3 col = straight &gt; 0.5 ? green : round_ &gt; 0.5 ? pink : vec3(0.85);&#10;    C = mix(C, col, on * (straight &gt; 0.5 || round_ &gt; 0.5 ? 0.9 : 0.45));&#10;}&#10;&#10;// ---------- v1.8: how much of this pixel the quad covers, measured on screen ----------&#10;// The smallest distance in pixels to the four sides (plus half a pixel), so the edge is smooth however steep the&#10;// perspective. Measuring on the board's own 0..1 (as before) broke down near its vanishing line: thin stray lines.&#10;float sideDist(vec2 p, vec2 u, vec2 v, float s)&#10;{&#10;    vec2 t = v - u;&#10;    return s * (t.x * (p.y - u.y) - t.y * (p.x - u.x)) / max(length(t), 1e-4);&#10;}&#10;float quadCov(vec2 q, vec2 a, vec2 b, vec2 c, vec2 d, vec2 R)&#10;{&#10;    vec2 p = q * R; a *= R; b *= R; c *= R; d *= R;&#10;    float area = (a.x * b.y - b.x * a.y) + (b.x * c.y - c.x * b.y) + (c.x * d.y - d.x * c.y) + (d.x * a.y - a.x * d.y);&#10;    float s = area &lt; 0.0 ? -1.0 : 1.0;&#10;    float e = min(min(sideDist(p, a, b, s), sideDist(p, b, c, s)), min(sideDist(p, c, d, s), sideDist(p, d, a, s)));&#10;    return clamp(e + 0.5, 0.0, 1.0);&#10;}&#10;&#10;// ---------- v1.9: Edge glow, the picture's own edges light up ----------&#10;// uv: where on the picture (as texture() counts), amp: the light mode, sens 0..1: fainter edges too,&#10;// width 0..1: a wider glow round them, style 0 glow, 1 a wave running over them, 2 sparkles along them.&#10;vec4 fxEdgeGlow(vec2 uv, float t, float amp, vec3 tint, float sens, float width, int style)&#10;{&#10;    vec2 px = 1.0 / iResolution.xy;&#10;    vec2 e = px * 1.5;&#10;    float thr = 0.8 * pow(0.04, sens);&#10;    float core = smoothstep(thr * 0.7, thr * 1.3, length(gradAt(uv, e)));&#10;    float halo = 0.0;   // edges a little way off, for the glow round them&#10;    float r = 3.0 + 18.0 * width;&#10;    for (int j = 0; j &lt; 12; j++) {   // at three distances, turned a little each time, so the glow has no rings in it&#10;        float a = float(j) * 2.3998;&#10;        float d = r * (0.3 + 0.35 * float(j % 3));&#10;        halo += smoothstep(thr * 0.5, thr * 1.3, length(gradAt(uv + vec2(cos(a), sin(a)) * d * px, e))) * (1.15 - 0.3 * float(j % 3));&#10;    }&#10;    halo /= 12.0;&#10;    float k = 1.0;&#10;    vec2 fc = uv * iResolution.xy;&#10;    if (style == 1)&#10;        k = 0.15 + 1.6 * pow(0.5 + 0.5 * sin((fc.x * 0.8 + fc.y) * 0.012 - t * 3.0), 6.0);&#10;    else if (style == 2)&#10;        k = 0.1 + 2.0 * step(0.86, h21(floor(fc / 5.0) + floor(t * 6.0))) * core;&#10;    return vec4(tint * (core * 1.5 + halo * (0.3 + 0.9 * width)) * amp * k, 1.0);&#10;}&#10;&#10;// ---------- Cinemnode v1.1: the picture itself moves (m: where in the board, 0..1 from its top left) ----------&#10;float edgeFade(vec2 m, float w) { return smoothstep(0.0, w, min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y))); }&#10;vec3 picAt(vec2 uv) { return texture(iImage0, uv).rgb; }&#10;&#10;vec4 fxFlow(vec2 uv, vec2 m, float t, float dir, float len)   // water runs one way: two phases, faded into each other&#10;{&#10;    float a = dir * 6.2831853;&#10;    vec2 d = vec2(sin(a), -cos(a));   // 0: down, 90: right, 180: up, 270: left&#10;    float L = (0.008 + 0.07 * len) * edgeFade(m, 0.1);&#10;    float ph = vnoise(uv * 9.0) * 0.6;&#10;    float p1 = fract(t * 0.3 + ph), p2 = fract(t * 0.3 + ph + 0.5);&#10;    float w = 1.0 - abs(2.0 * p1 - 1.0);&#10;    return vec4(mix(picAt(uv - d * L * p2), picAt(uv - d * L * p1), w), 1.0);&#10;}&#10;&#10;vec4 fxSway(vec2 uv, vec2 m, float t, float wind, float size, int style)   // 0 grass (fixed at the bottom), 1 leaves, 2 flag (fixed on the left)&#10;{&#10;    float k = 2.0 + 10.0 * (1.0 - size);&#10;    float gust = 0.65 + 0.35 * sin(t * 0.37) * sin(t * 0.23 + 1.0);&#10;    float fade = edgeFade(m, 0.15);&#10;    vec2 off;&#10;    float shade = 1.0;&#10;    if (style == 2) {&#10;        float w = sin(m.x * k - t * 4.0 + vnoise(m * 3.0 + t * 0.3) * 2.0);&#10;        off = vec2(0.15 * w, w) * m.x;&#10;        shade = 1.0 + 0.18 * wind * cos(m.x * k - t * 4.0) * m.x;&#10;    } else {&#10;        float w = style == 0 ? 1.0 - m.y : 0.55 + 0.45 * vnoise(m * k + 4.0);&#10;        off = vec2(sin(t * 2.0 + m.x * k * 0.7 + vnoise(m * k) * 3.0) + 0.5 * sin(t * 3.3 + m.y * k), 0.0) * w;&#10;    }&#10;    off *= wind * 0.018 * gust * (style == 2 ? 1.0 : fade);&#10;    return vec4(picAt(uv + vec2(off.x, -off.y)) * shade, 1.0);&#10;}&#10;&#10;vec4 fxHaze(vec2 uv, vec2 m, float t, float amt, float size)   // air that trembles, rising, strongest low down&#10;{&#10;    vec2 p = m * (6.0 + 30.0 * (1.0 - size)) + vec2(0.0, t * 1.5);&#10;    vec2 d = vec2(vnoise(p) - 0.5, vnoise(p + 17.3) - 0.5);&#10;    d *= amt * 0.014 * edgeFade(m, 0.12) * (0.4 + 0.6 * m.y);&#10;    return vec4(picAt(uv + vec2(d.x, -d.y)), 1.0);&#10;}&#10;&#10;vec4 fxReflect(vec2 q, vec2 m, float t, vec2 a, vec2 b, float wave, float clear, vec3 tint)   // the picture above the board's top edge, mirrored and rippling&#10;{&#10;    float top = mix(a.y, b.y, clamp(m.x, 0.0, 1.0));&#10;    float dy = max(q.y - top, 0.0);&#10;    float rx = (sin(dy * 260.0 / (1.0 + dy * 12.0) - t * 3.0) + 0.6 * (vnoise(vec2(q.x * 40.0, dy * 90.0 - t * 1.5)) - 0.5)) * wave * 0.008 * (0.3 + dy * 10.0);&#10;    vec2 r = vec2(q.x + rx, top - dy - 0.002);&#10;    vec3 col = picAt(vec2(r.x, 1.0 - r.y)) * mix(vec3(1.0), tint, 0.35) * 0.8;&#10;    return vec4(col, clear * smoothstep(0.0, 0.01, dy + 0.004));&#10;}&#10;&#10;vec4 fxBreathe(vec2 uv, vec2 m, float t, vec2 ctr, float amt, float soft)   // a very slow zoom and drift&#10;{&#10;    vec2 c = vec2(ctr.x, 1.0 - ctr.y);&#10;    float z = 1.0 - amt * 0.05 * (0.5 + 0.5 * sin(t * 0.5));&#10;    vec2 drift = amt * 0.004 * vec2(sin(t * 0.31), cos(t * 0.23));&#10;    vec3 moved = picAt(c + (uv - c) * z + drift);&#10;    return vec4(mix(picAt(uv), moved, soft &gt; 0.5 ? edgeFade(m, 0.15) : 1.0), 1.0);&#10;}&#10;&#10;// ---------- Cinemnode v1.1: laid over the picture ----------&#10;vec4 fxParticles(vec2 p, float t, vec3 tint, float amount, float size, int style)   // 0 snow, 1 dust, 2 fireflies (p: fc / R.y)&#10;{&#10;    vec3 c = vec3(0.0);&#10;    float a = 0.0;&#10;    for (int L = 0; L &lt; 3; L++) {&#10;        float fl = float(L);&#10;        float sc = 5.0 + fl * 5.0;&#10;        vec2 off = style == 0 ? vec2(sin(t * 0.4 + fl) * 0.6, t * (1.2 + 0.5 * fl)) :&#10;                   style == 1 ? vec2(t * 0.12, sin(t * 0.2 + fl) * 0.3) : vec2(sin(t * 0.1 + fl) * 0.3, -t * 0.08);&#10;        vec2 g = p * sc + off;&#10;        vec2 id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + fl * 31.7);&#10;        if (h &gt; 0.15 + 0.85 * amount) continue;&#10;        vec2 o = (vec2(h21(id + 3.1), h21(id + 7.7)) - 0.5) * 0.5;&#10;        if (style == 0) o.x += 0.15 * sin(t * (1.0 + h) + h * 20.0);&#10;        if (style == 2) o += 0.2 * vec2(sin(t * (0.7 + h) + h * 20.0), cos(t * (0.9 + h) + h * 13.0));&#10;        float r = (0.04 + 0.1 * size) * (0.6 + 0.4 * h) * (1.0 - fl * 0.2);&#10;        float d = length(f - o);&#10;        float core = smoothstep(r, r * 0.3, d);&#10;        float halo = style == 2 ? 0.06 * r / (d * d + 0.004) * 0.02 : 0.0;&#10;        float tw = style == 2 ? 0.5 + 0.5 * sin(t * 3.0 * (0.5 + h) + h * 40.0) : style == 1 ? 0.55 + 0.45 * sin(t * 2.0 + h * 30.0) : 1.0;&#10;        c += tint * (core + halo) * tw * (style == 1 ? 0.6 : 1.0);&#10;        a = max(a, core * tw);&#10;    }&#10;    return style == 0 ? vec4(tint, clamp(a, 0.0, 1.0)) : vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxRays(vec2 m, float t, vec3 tint, float from, float many)   // sunbeams fanning down from above the board&#10;{&#10;    vec2 d = m - vec2(0.1 + 0.8 * from, -0.4);&#10;    float a = atan(d.x, d.y);&#10;    float r = vnoise(vec2(a * (8.0 + 24.0 * many), t * 0.15)) * vnoise(vec2(a * 23.0 + 5.0, t * 0.27 + 3.0));&#10;    r = smoothstep(0.08, 0.6, r);&#10;    float fall = smoothstep(1.6, 0.3, length(d));&#10;    float side = smoothstep(0.0, 0.12, m.x) * smoothstep(1.0, 0.88, m.x) * smoothstep(0.0, 0.08, m.y) * smoothstep(1.0, 0.8, m.y);&#10;    return vec4(tint * r * fall * side * 0.8, 1.0);&#10;}&#10;&#10;vec4 fxFire(vec2 m, float t, vec3 tint, float height, float detail)   // flames rising from the bottom of the board&#10;{&#10;    float up = 1.0 - m.y;&#10;    vec2 p = vec2(m.x * (3.0 + 4.0 * detail), up * (2.0 + 3.0 * detail));&#10;    float n = fbm(p * 1.5 - vec2(0.0, t * 2.2)) * 0.8 + fbm(p * 3.0 - vec2(t * 0.3, t * 3.5)) * 0.4;&#10;    float shape = 1.0 - up / (0.25 + 0.75 * height);&#10;    float side = 1.0 - pow(abs(m.x * 2.0 - 1.0), 2.0);&#10;    float f = clamp(shape * side * 1.6 + n - 0.9, 0.0, 1.0);&#10;    f *= smoothstep(0.0, 0.15, m.x) * smoothstep(1.0, 0.85, m.x) * smoothstep(0.0, 0.2, m.y);&#10;    vec3 col = vec3(1.5, 0.42, 0.08) * f + vec3(1.0, 0.85, 0.45) * pow(f, 3.0) * 1.5;&#10;    return vec4(col * mix(vec3(1.0), tint, 0.5) * 1.3, 1.0);&#10;}&#10;&#10;vec4 fxSteam(vec2 m, float t, vec3 tint, float amount, float width)   // soft wisps going up and fading&#10;{&#10;    vec2 p = vec2((m.x - 0.5) * (2.0 + 3.0 * (1.0 - width)), 1.0 - m.y);&#10;    p.x += 0.3 * sin(p.y * 3.0 - t * 1.3) * p.y;&#10;    float n = fbm(vec2(p.x * 2.5, p.y * 2.0 - t * 0.8));&#10;    float col = smoothstep(0.8, 0.0, abs(p.x) / (0.35 + p.y * 0.8));&#10;    float a = col * smoothstep(0.35, 0.75, n) * smoothstep(1.0, 0.4, p.y) * smoothstep(0.0, 0.1, p.y) * (0.6 + 1.2 * amount);&#10;    return vec4(tint, clamp(a, 0.0, 1.0));&#10;}&#10;&#10;vec4 fxLightning(vec2 m, float t, vec3 tint, float flash, float bolt, vec3 pic)   // now and then a strike: the picture lights up, with a bolt if you like&#10;{&#10;    float k = floor(t * 0.5), f = fract(t * 0.5);&#10;    float h = h11(k * 1.7 + 0.3);&#10;    if (h &lt; 0.4) return vec4(0.0);&#10;    float amp = exp(-f * 45.0) + 0.7 * exp(-max(f - 0.06, 0.0) * 35.0) * step(0.06, f);&#10;    vec3 c = (pic * 1.8 * flash + tint * 0.35 * flash) * amp;&#10;    if (bolt &gt; 0.01) {&#10;        float x = 0.2 + 0.6 * h11(k + 9.1);&#10;        x += (vnoise1(m.y * 6.0 + k * 13.0) - 0.5) * 0.25 + (vnoise1(m.y * 25.0 + k * 7.0) - 0.5) * 0.06;&#10;        float d = abs(m.x - x);&#10;        float b = (0.0015 / (d + 0.0015) + 0.25 * exp(-d * 30.0)) * smoothstep(1.0, 0.6, m.y / (0.5 + 0.5 * h11(k + 2.2)));&#10;        c += mix(vec3(1.0), tint, 0.4) * b * bolt * amp * 1.5;&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;vec4 fxGlass(vec2 p, vec2 uv, float t, vec3 tint, float drops, float mist)   // drops on a window, running down, the picture bent in them (p: fc / R.y)&#10;{&#10;    vec2 n = vec2(0.0);&#10;    float mask = 0.0;&#10;    for (int L = 0; L &lt; 2; L++) {   // drops that sit, grow and go&#10;        float sc = 16.0 + 12.0 * float(L);&#10;        vec2 g = p * sc, id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + float(L) * 7.0);&#10;        if (h &lt; 0.15 + 0.7 * drops) {&#10;            vec2 o = (vec2(h21(id + 1.3), h21(id + 2.7)) - 0.5) * 0.6;&#10;            float life = fract(t * 0.05 + h * 7.0);&#10;            float r = (0.12 + 0.2 * h21(id + 4.1)) * smoothstep(1.0, 0.8, life) * smoothstep(0.0, 0.05, life);&#10;            vec2 d = (f - o) / max(r, 0.001);&#10;            float k = smoothstep(1.0, 0.8, length(d));&#10;            mask = max(mask, k);&#10;            n += d * k;&#10;        }&#10;    }&#10;    {   // drops that run down, leaving a trail&#10;        float sc = 7.0;&#10;        float cx = floor(p.x * sc), fx = fract(p.x * sc) - 0.5;&#10;        float h = h11(cx * 3.7);&#10;        if (h &lt; 0.2 + 0.6 * drops) {&#10;            float wob = 0.15 * sin(p.y * 9.0 + h * 20.0);&#10;            float yy = fract(p.y * 0.5 + t * (0.05 + 0.08 * h) + h);&#10;            vec2 d = vec2((fx - wob) / 0.16, (yy - 0.5) * 9.0);&#10;            float k = smoothstep(1.0, 0.8, length(d));&#10;            float trail = smoothstep(0.06, 0.0, abs(fx - wob)) * step(0.5, yy) * smoothstep(1.0, 0.5, yy) * 0.6;&#10;            mask = max(mask, max(k, trail));&#10;            n += d * k + vec2((fx - wob) * 4.0, 0.0) * trail;&#10;        }&#10;    }&#10;    vec3 blur = vec3(0.0);&#10;    for (int i = 0; i &lt; 8; i++) {&#10;        float a = float(i) * 0.785398;&#10;        blur += picAt(uv + vec2(cos(a), sin(a)) * 0.006 * mist);&#10;    }&#10;    blur /= 8.0;&#10;    vec3 drop = picAt(uv - n * 0.035) * 1.1 + tint * pow(max(0.0, dot(normalize(n + 1e-4), vec2(-0.6, 0.8))), 4.0) * 0.35 * mask;&#10;    vec3 col = mix(blur * (1.0 + 0.15 * mist), drop, mask);&#10;    return vec4(col, max(mask, clamp(mist * 1.2, 0.0, 1.0)));&#10;}&#10;&#10;vec4 fxSparkle(vec2 fc, float t, vec3 tint, float amount, float size, float S, float bright)   // glints that come and go where the water is bright&#10;{&#10;    vec2 g = fc / (S * (8.0 + 14.0 * size));&#10;    vec2 id = floor(g), f = fract(g) - 0.5;&#10;    float h = h21(id);&#10;    if (h &gt; 0.1 + 0.6 * amount) return vec4(0.0);&#10;    vec2 d = f - (vec2(h21(id + 1.7), h21(id + 4.3)) - 0.5) * 0.6;&#10;    float tw = pow(max(0.0, sin(t * 3.0 * (0.6 + h) + h * 60.0)), 24.0);&#10;    float star = pow(max(0.0, 1.0 - length(d) * 5.0), 3.0) + 0.004 / (abs(d.x) + 0.01) * smoothstep(0.3, 0.0, abs(d.y)) + 0.004 / (abs(d.y) + 0.01) * smoothstep(0.3, 0.0, abs(d.x));&#10;    return vec4(tint * min(star, 3.0) * tw * smoothstep(0.12, 0.7, bright) * 1.5, 1.0);&#10;}&#10;`;&#10;&#10;const W = 1920, H = 1080;          // the units the editor works in (stretched over the Scene)&#10;const ACC = '#8a3fff';   // Darc Sector purple (a touch lighter than #741bff, to read on the dark panels)&#10;const COLORS = [['Warm white', '#ffd59a'], ['White', '#ffffff'], ['Orange', '#ff9a3c'], ['Red', '#ff3b3b'], ['Pink', '#ff4fd8'],&#10;                ['Purple', '#a46bff'], ['Blue', '#3b7bff'], ['Cyan', '#3cf0ff'], ['Green', '#4dff7a'], ['Yellow', '#ffe14d']];&#10;// Effects by number (kept with the project, so a number never changes meaning; 5 was Image 2, now gone and shown as Plasma)&#10;const FX = ['Plasma', 'Text', 'Glitch', 'Colour bars', 'Retro', 'Plasma', 'Window light', 'Neon edge', 'Custom', 'Rain', 'Ripple',&#10;            'Clouds', 'Smoke', 'Light box', 'Colour glow', 'Edge glow',&#10;            'Flow', 'Sway', 'Heat haze', 'Reflection', 'Breathe',   // v1.1: the picture itself moves&#10;            'Particles', 'Light rays', 'Fire', 'Steam', 'Lightning', 'Rain on glass', 'Water sparkle'];   // v1.1: laid over it&#10;const FXFN = ['fxPlasma', null, 'fxGlitch', 'fxBars', 'fxRetro', 'fxPlasma', 'fxWindow', 'fxNeon', 'fxCustom', null, null,&#10;              'fxClouds', 'fxSmoke', null, null, null, null, null, null, null, null, null, null, null, null, null, null, null];&#10;const FXADD = [false, false, false, false, false, false, true, true, false, false, false, false, false, true, true, true,&#10;               false, false, false, false, false, true, true, true, false, true, false, true];   // added light&#10;const FXORDER = [0, 1, 2, 3, 4, 11, 12, 9, 10, 6, 13, 7, 14, 15, 21, 22, 23, 24, 25, 26, 27, 8];   // laid over the picture&#10;const MOVEORDER = [16, 17, 18, 19, 20];   // the picture itself moves&#10;const MOVES = fx =&gt; fx &gt;= 16 &amp;&amp; fx &lt;= 20;&#10;const NOBRIGHT = fx =&gt; MOVES(fx) || fx === 26;   // these show the picture as it is: no Brightness&#10;// what the two sliders of each v1.1 effect are called, with where they start&#10;const FXK = { 16: ['Direction', 'Length', 0, 0.5], 17: ['Wind', 'Wave size', 0.5, 0.5], 18: ['Strength', 'Size', 0.5, 0.5],&#10;              19: ['Ripples', 'Clearness', 0.4, 0.7], 20: ['Amount', null, 0.5, 0.5], 21: ['Amount', 'Size', 0.5, 0.4],&#10;              22: ['Light from', 'Rays', 0.3, 0.5], 23: ['Height', 'Detail', 0.6, 0.5], 24: ['Amount', 'Width', 0.6, 0.5],&#10;              25: ['Flash', 'Bolt', 0.7, 0.6], 26: ['Drops', 'Mist', 0.5, 0.3], 27: ['Amount', 'Size', 0.5, 0.4] };&#10;const FXSTYLES = { 17: ['Grass', 'Leaves', 'Flag'], 21: ['Snow', 'Dust', 'Fireflies'] };&#10;const ESTYLES = ['Glow', 'Running', 'Sparkle'];   // how Edge glow lights the picture's edges   // as the panel shows them&#10;const PICS = ['Off', 'Surface', 'Bright parts', 'Dark parts'];&#10;const PICS_RIPPLE = ['On top', 'In the picture'];&#10;const MODES = ['On', 'Blink', 'Twinkle', 'Broken tube', 'Pulse', 'Strobe', 'Candle'];&#10;&#10;const c = canvas(1);&#10;c.size(W, H, 'stretch');&#10;&#10;// The first time: nothing yet. &quot;+ Board&quot; and &quot;+ Light&quot; (or a double-click) add the first ones.&#10;if (!state.items) {&#10;    state.items = [];&#10;    state.next = 1;&#10;    state.edit = true;&#10;    state.sel = 0;&#10;    state.px = W - 656; state.py = 16;&#10;}&#10;if (state.lx === undefined) { state.lx = 16; state.ly = 16; state.lscroll = 0; }&#10;if (state.bg === undefined) { state.bg = ''; state.edges = false; }&#10;if (state.efilter === undefined) { state.efilter = 0; state.esens = 0.35; state.ewidth = 0.3; }&#10;const EFILTERS = ['All', 'Straight', 'Round'];&#10;if (state.snap === undefined) state.snap = true;&#10;if (state.dock === undefined) { state.dock = true; state.openP = true; state.openL = true; state.dscroll = 0; }&#10;if (state.zoom === undefined) { state.zoom = 1; state.panX = 0; state.panY = 0; }&#10;if (state.tlOpen === undefined) state.tlOpen = false;&#10;const TLH = 280;   // the timeline's height, under the picture&#10;&#10;// ---------- the timeline: what an element has, animated in a loop ----------&#10;// it.tl = { len (seconds of one loop), tracks: { key: { on, keys: [[time 0..1, value 0..1], ...] } } }, each track with keys at 0 and 1&#10;// holding the same value, so the loop has no jump. The Scene works it out on its own (straight lines between the keys), so it&#10;// plays in Perform too. key: transp, bright, k1, k2 (the effect's own sliders), size, power, x, y (a light), r, g, b.&#10;function tlOf(it) {&#10;    if (!it.tl) it.tl = { len: 4, tracks: {} };&#10;    if (it.tl.keys) it.tl = { len: it.tl.len, tracks: { transp: { on: it.tl.on, keys: it.tl.keys } } };   // from v1.2&#10;    return it.tl;&#10;}&#10;function tlTrack(it, key, now) {&#10;    const tl = tlOf(it);&#10;    if (!tl.tracks[key]) tl.tracks[key] = { on: false, keys: [[0, now], [0.5, now &gt; 0.5 ? 0 : 1], [1, now]] };&#10;    return tl.tracks[key];&#10;}&#10;const tlOn = (it, key) =&gt; !!(it.tl &amp;&amp; it.tl.tracks &amp;&amp; it.tl.tracks[key] &amp;&amp; it.tl.tracks[key].on);&#10;const tlLen = v =&gt; 0.5 + 29.5 * v * v;   // the slider (0..1) as seconds, finer at the short end&#10;const tlLenV = s =&gt; Math.sqrt((s - 0.5) / 29.5);&#10;function tlExpr(it, key) {   // the value now, in GLSL: the first key's value, plus each line's rise as time passes it&#10;    const k = it.tl.tracks[key].keys, u = 'fract(T / ' + f(it.tl.len) + ')';&#10;    let e = f(k[0][1]);&#10;    for (let i = 1; i &lt; k.length; i++) {&#10;        const dv = k[i][1] - k[i - 1][1], dt = Math.max(1e-4, k[i][0] - k[i - 1][0]);&#10;        if (Math.abs(dv) &gt; 1e-5)&#10;            e += ' + ' + f(dv) + ' * clamp((' + u + ' - ' + f(k[i - 1][0]) + ') / ' + f(dt) + ', 0.0, 1.0)';&#10;    }&#10;    return '(' + e + ')';&#10;}&#10;const AN = (it, key, still) =&gt; tlOn(it, key) ? tlExpr(it, key) : still;   // animated, or as it is&#10;function boardK(it) {   // what the effect's own two sliders are called, with where they start&#10;    if (FXK[it.fx]) return FXK[it.fx];&#10;    return { 10: ['Circle size', 'Strength', 0.6, 0.6], 13: ['Glow size', null, 0.6, 0.6], 14: ['Tolerance', 'Softness', 0.6, 0.6],&#10;             15: ['Sensitivity', 'Glow width', 0.6, 0.6] }[it.fx] || [null, null, 0.6, 0.6];&#10;}&#10;function tlProps(it) {   // what of this element the timeline can animate: [key, name, value now 0..1, how to show a value]&#10;    const pc = v =&gt; Math.round(v * 100) + '%', c255 = v =&gt; String(Math.round(v * 255));&#10;    const [r, g, b] = hexRGB(hexOf(it));&#10;    const L = [['transp', 'Transparency', it.transp || 0, pc]];&#10;    if (it.type === 'board') {&#10;        if (!NOBRIGHT(it.fx)) L.push(['bright', it.fx === 9 ? 'Amount' : 'Brightness', it.bright, pc]);&#10;        const [n1, n2, d1, d2] = boardK(it);&#10;        if (n1) L.push(['k1', n1, it.rsize === undefined ? d1 : it.rsize, it.fx === 16 ? v =&gt; Math.round(v * 360) + ' deg' : pc]);&#10;        if (n2) L.push(['k2', n2, it.rstr === undefined ? d2 : it.rstr, pc]);&#10;    } else&#10;        L.push(['size', 'Size', it.size, pc], ['power', 'Strength', it.power, pc], ['x', 'Across', it.x, pc], ['y', 'Down', it.y, pc]);&#10;    if (it.type !== 'board' || !MOVES(it.fx) || it.fx === 19)&#10;        L.push(['r', 'Red', r, c255], ['g', 'Green', g, c255], ['b', 'Blue', b, c255]);&#10;    return L;&#10;}&#10;&#10;// ---------- the view ----------&#10;// In Edit mode the picture is drawn smaller, in the free part of the canvas between the toolbar and the dock (zoomed and&#10;// moved as you like); the Scene does the same with P25, P26 (its top left, 0..1 of the canvas) and P27 (its scale).&#10;const view = { x: 0, y: 0, s: 1 };&#10;function fitView() {&#10;    if (!state.edit) { view.x = 0; view.y = 0; view.s = 1; return; }&#10;    const left = TW + 20, right = state.dock ? DW + 30 : 34, top = 20, bottom = state.tlOpen ? TLH + 16 : 20;&#10;    const aw = W - left - right, ah = H - top - bottom;&#10;    view.s = Math.min(aw / W, ah / H) * state.zoom;&#10;    view.x = left + aw / 2 - W * view.s / 2 + state.panX;&#10;    view.y = top + ah / 2 - H * view.s / 2 + state.panY;&#10;}&#10;const X = u =&gt; view.x + u * W * view.s, Y = v =&gt; view.y + v * H * view.s;   // picture (0..1) -&gt; canvas&#10;const U = x =&gt; (x - view.x) / (W * view.s), V = y =&gt; (y - view.y) / (H * view.s);   // canvas -&gt; picture&#10;const DU = d =&gt; d / (W * view.s), DV = d =&gt; d / (H * view.s);   // a drag on the canvas, in the picture&#10;// A P only takes 0 to 1, so the view is packed into that: P25 = 0.5 + x / 20, P26 = 0.5 + y / 20, P27 = scale / 10&#10;// (P27 at 0: no view, the whole Scene, as in Perform).&#10;function sendView() {&#10;    out(1, { p: state.edit ? { P25: 0.5 + view.x / W / 20, P26: 0.5 + view.y / H / 20, P27: view.s / 10 } : { P25: 0.5, P26: 0.5, P27: 0 } });&#10;}&#10;function zoomAt(x, y, k) {   // zoom by k, keeping the spot under the mouse where it is&#10;    const u = U(x), v = V(y);&#10;    state.zoom = Math.max(1, Math.min(8, state.zoom * k));&#10;    if (state.zoom === 1) { state.panX = 0; state.panY = 0; }&#10;    fitView();&#10;    if (state.zoom &gt; 1) { state.panX += x - X(u); state.panY += y - Y(v); fitView(); }&#10;    sendView(); placeAll();&#10;}&#10;&#10;// ---------- snapping ----------&#10;// the x and y lines a dragged point can snap to (in 0..1): the other elements' corners and middles, the Scene's sides and middle&#10;function snapLines(skipId) {&#10;    const xs = [0, 0.5, 1], ys = [0, 0.5, 1];&#10;    for (const t of state.items) {&#10;        if (t.id === skipId || t.hidden)&#10;            continue;&#10;        if (t.type === 'board')&#10;            for (const p of t.pts) { xs.push(p[0]); ys.push(p[1]); }&#10;        else { xs.push(t.x); ys.push(t.y); }&#10;    }&#10;    return [xs, ys];&#10;}&#10;// how far to move so the nearest point of pts lands on a line, per axis (0 when nothing is within 12 pixels)&#10;function snapDelta(pts, skipId, alt) {&#10;    if (!state.snap || alt)&#10;        return [0, 0];&#10;    const [xs, ys] = snapLines(skipId);&#10;    let bx = DU(12), by = DV(12), dx = 0, dy = 0;&#10;    for (const p of pts) {&#10;        for (const x of xs) if (Math.abs(x - p[0]) &lt; bx) { bx = Math.abs(x - p[0]); dx = x - p[0]; }&#10;        for (const y of ys) if (Math.abs(y - p[1]) &lt; by) { by = Math.abs(y - p[1]); dy = y - p[1]; }&#10;    }&#10;    return [dx, dy];&#10;}&#10;let dragFrom = null;   // the element as it was when the press began, so a drag is worked out from there (and snaps cleanly)&#10;const keep = it =&gt; JSON.parse(JSON.stringify({ pts: it.pts, x: it.x, y: it.y }));&#10;if (!state.palette) state.palette = [];&#10;if (state.cmode === undefined) state.cmode = 0;   // 0 RGB, 1 HSV&#10;let hexTyping = null;   // the code being typed on the keys, or null&#10;for (const it of state.items) if (it.fx === 5) it.fx = 0;   // Image 2 is gone&#10;const hexOf = it =&gt; it.hex || COLORS[it.color || 0][1];&#10;&#10;// ---------- the shader ----------&#10;// mainImage: in Edit mode the picture goes where the editor shows it (P25, P26 its top left, P27 its scale, packed as&#10;// sendView says) on a grey ground; with P27 at 0 it is the whole Scene, as in Perform.&#10;const VIEW_MAIN = 'void mainImage(out vec4 o, in vec2 fc)\n{\n' +&#10;    '    if (P27 &lt; 0.0001) { sceneImage(o, fc); return; }\n' +&#10;    '    vec2 R = iResolution.xy;\n' +&#10;    '    vec2 p = (vec2(fc.x / R.x, 1.0 - fc.y / R.y) - (vec2(P25, P26) - 0.5) * 20.0) / (P27 * 10.0);   // where in the picture, from its top left\n' +&#10;    '    if (p.x &lt; 0.0 || p.y &lt; 0.0 || p.x &gt; 1.0 || p.y &gt; 1.0) {\n' +&#10;    '        vec2 k = floor(fc / (12.0 * R.y / 1080.0));\n' +&#10;    '        o = vec4(vec3(0.05, 0.045, 0.075) + 0.012 * mod(k.x + k.y, 2.0), 1.0);   // the ground round it\n' +&#10;    '        return;\n    }\n' +&#10;    '    sceneImage(o, vec2(p.x, 1.0 - p.y) * R);\n' +&#10;    '    if (o.a &lt; 1.0) {   // see-through parts show a chequer, as in Photoshop\n' +&#10;    '        vec2 k = floor(p * vec2(1920.0, 1080.0) / 16.0);\n' +&#10;    '        vec3 g = vec3(0.15, 0.14, 0.19) + 0.05 * mod(k.x + k.y, 2.0);\n' +&#10;    '        o = vec4(mix(g, o.rgb, o.a), 1.0);\n    }\n}\n';&#10;const f = v =&gt; (Math.round(v * 100000) / 100000).toFixed(5);&#10;const v2 = (x, y) =&gt; 'vec2(' + f(x) + ', ' + f(y) + ')';&#10;function rgb(hex) {&#10;    const n = parseInt(hex.slice(1), 16);&#10;    return 'vec3(' + f((n &gt;&gt; 16 &amp; 255) / 255) + ', ' + f((n &gt;&gt; 8 &amp; 255) / 255) + ', ' + f((n &amp; 255) / 255) + ')';&#10;}&#10;const spd = s =&gt; '(0.05 + 4.0 * ' + s + ' * ' + s + ')';&#10;&#10;function itemCode(it, live) {&#10;    // live: the selected element reads P1.. so dragging it needs no new shader&#10;    const P = (k, v) =&gt; live ? 'P' + k : f(v);&#10;    const c3 = hexRGB(hexOf(it));&#10;    const tint = tlOn(it, 'r') || tlOn(it, 'g') || tlOn(it, 'b') ?&#10;        'vec3(' + ['r', 'g', 'b'].map((k, i) =&gt; AN(it, k, live ? 'P' + (18 + i) : f(c3[i]))).join(', ') + ')' :&#10;        live ? 'vec3(P18, P19, P20)' : rgb(hexOf(it));&#10;    const seed = f(it.seed);&#10;    const vis = '(1.0 - ' + AN(it, 'transp', P(it.type === 'board' ? 11 : 6, it.transp || 0)) + ')';   // Transparency: 0 solid, 1 gone&#10;    if (it.type === 'board') {&#10;        const pt = (i) =&gt; live ? 'vec2(P' + (2 * i + 1) + ', P' + (2 * i + 2) + ')' : v2(it.pts[i][0], it.pts[i][1]);&#10;        const k1 = AN(it, 'k1', P(12, it.rsize === undefined ? 0.6 : it.rsize)), k2 = AN(it, 'k2', P(13, it.rstr === undefined ? 0.6 : it.rstr));&#10;        const amp = 'lampAmp(' + (it.mode || 0) + ', t, ' + seed + ')';&#10;        const pic = state.bg ? (it.pic || 0) : 0;   // how it follows the picture (only with a background)&#10;        let fx;&#10;        if (it.fx === 1) {&#10;            const line = Math.min(it.text, TEXTS.length - 1);&#10;            const len = TEXTS[line].length * 0.62 * 150.0 + 60.0;&#10;            fx = 'fxText(m, t, ' + tint + ', labelText(vec2(m.x * 1000.0, (1.0 - m.y) * 250.0), ' + line + ', vec2(1000.0 - mod(t * 220.0, ' + f(1000 + len) + '), 70.0), 150.0, 0.0))';&#10;        } else if (it.fx === 9)   // rain falls straight down the screen, whatever the board's shape&#10;            fx = 'fxRain(fc / R.y, t, ' + tint + ')';&#10;        else if (it.fx === 10)    // ripples in water: rings round the middle of the board, seen in its perspective&#10;            fx = 'fxRipple(m, t, ' + tint + ', ' + k1 + ', ' + k2 + (pic === 1 ? ' * 0.35' : '') + ')';&#10;        else if (it.fx === 13)    // a lit rectangle with a glow round it, blinking as a light does&#10;            fx = 'fxLightBox(m, cov, ' + amp + ', ' + tint + ', ' + k1 + ')';&#10;        else if (it.fx === 14)    // one colour of the picture (as it is at the picked spot) lights up&#10;            fx = state.bg ? 'fxKeyGlow(texture(iImage0, uv).rgb, keyColour(' + v2(it.kx === undefined ? 0.5 : it.kx, 1 - (it.ky === undefined ? 0.5 : it.ky)) + '), ' + k1 + ', ' + k2 + ', ' + amp + ', ' + tint + ')' : 'vec4(0.0)';&#10;        else if (it.fx === 15)    // the picture's own edges inside the board light up&#10;            fx = state.bg ? 'fxEdgeGlow(uv, t, ' + amp + ', ' + tint + ', ' + k1 + ', ' + k2 + ', ' + (it.estyle || 0) + ')' : 'vec4(0.0)';&#10;        else if (it.fx &gt;= 16) {&#10;            const st = it.style || 0, bg = c =&gt; state.bg ? c : 'vec4(0.0)';&#10;            const full = it.pts.every((p, i) =&gt; Math.abs(p[0] - [0, 1, 1, 0][i]) &lt; 0.002 &amp;&amp; Math.abs(p[1] - [0, 0, 1, 1][i]) &lt; 0.002);&#10;            fx = { 16: bg('fxFlow(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   17: bg('fxSway(uv, m, t, ' + k1 + ', ' + k2 + ', ' + st + ')'),&#10;                   18: bg('fxHaze(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   19: bg('fxReflect(q, m, t, ' + pt(0) + ', ' + pt(1) + ', ' + k1 + ', ' + k2 + ', ' + tint + ')'),&#10;                   20: bg('fxBreathe(uv, m, t, (' + pt(0) + ' + ' + pt(1) + ' + ' + pt(2) + ' + ' + pt(3) + ') * 0.25, ' + k1 + ', ' + (full ? '0.0' : '1.0') + ')'),&#10;                   21: 'fxParticles(fc / R.y, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   22: 'fxRays(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   23: 'fxFire(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   24: 'fxSteam(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   25: 'fxLightning(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + (state.bg ? 'texture(iImage0, uv).rgb' : 'vec3(0.0)') + ')',&#10;                   26: 'fxGlass(fc / R.y, uv, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   27: 'fxSparkle(fc, t, ' + tint + ', ' + k1 + ', ' + k2 + ', S, ' + (state.bg ? 'lum(texture(iImage0, uv).rgb)' : '1.0') + ')' }[it.fx];&#10;        } else&#10;            fx = FXFN[it.fx] + '(m, t, ' + tint + ')';&#10;        // a ripple In the picture bends the picture under it, out from the middle of the board&#10;        const refr = it.fx === 10 &amp;&amp; pic === 1 ?&#10;            '            {   vec2 ctr = (' + pt(0) + ' + ' + pt(1) + ' + ' + pt(2) + ' + ' + pt(3) + ') * 0.25;\n' +&#10;            '                vec2 dir = normalize(q - ctr + vec2(1e-5));\n' +&#10;            '                vec2 d = dir * rippleV(m, t, ' + k1 + ') * 0.012 * ' + k2 + ';\n' +&#10;            '                C = mix(C, texture(iImage0, vec2(uv.x + d.x, uv.y - d.y)).rgb, cov * ' + vis + ');\n' +&#10;            '            }\n' : '';&#10;        const react = pic &amp;&amp; it.fx !== 10 &amp;&amp; it.fx !== 14 &amp;&amp; it.fx !== 15 &amp;&amp; it.fx &lt; 16 ? '            picReact(s, ' + pic + ', texture(iImage0, uv).rgb);\n' : '';&#10;        const glowOut = it.fx === 13;   // a light box shines past its edges&#10;        const mixl = glowOut ? 'glowAdd(C, A, s.rgb * s.a);' :&#10;                     FXADD[it.fx] &amp;&amp; !(it.fx === 21 &amp;&amp; !(it.style || 0)) ? 'glowAdd(C, A, s.rgb * s.a * cov);' : 'C = mix(C, s.rgb, s.a * cov); A = mix(A, 1.0, s.a * cov);';&#10;        return '    {   // ' + FX[it.fx] + '\n' +&#10;               '        vec2 m = quadUV(q, ' + pt(0) + ', ' + pt(1) + ', ' + pt(2) + ', ' + pt(3) + ');\n' +&#10;               '        float cov = m.x &gt; -5.0 ? quadCov(q, ' + pt(0) + ', ' + pt(1) + ', ' + pt(2) + ', ' + pt(3) + ', R) : 0.0;\n' +&#10;               '        if (' + (glowOut ? 'm.x &gt; -5.0' : 'cov &gt; 0.0') + ') {\n' +&#10;               '            float t = T * ' + spd(P(9, it.speed)) + ' + ' + seed + ' * 10.0;\n' +&#10;               '            vec4 s = ' + fx + ';\n' +&#10;               (NOBRIGHT(it.fx) ? '' : '            ' + (it.fx === 9 ? 's.a' : 's.rgb') + ' *= 2.0 * ' + AN(it, 'bright', P(10, it.bright)) + ';\n') +   // rain: Amount sets how much&#10;               react + refr +&#10;               '            s.a *= ' + vis + ';\n' +&#10;               '            ' + mixl + '\n' +&#10;               '        }\n' +&#10;               '    }\n';&#10;    }&#10;    const sz = AN(it, 'size', P(3, it.size));&#10;    return '    glowAdd(C, A, lamp(fc, vec2(' + AN(it, 'x', P(1, it.x)) + ', 1.0 - ' + AN(it, 'y', P(2, it.y)) + ') * R, (6.0 + 250.0 * ' + sz + ' * ' + sz + ') * S, ' +&#10;           '3.0 * ' + AN(it, 'power', P(5, it.power)) + ' * ' + vis + ' * lampAmp(' + it.mode + ', T * ' + spd(P(4, it.speed)) + ', ' + seed + '), ' + tint + ', ' + (it.mode === 2 ? '1.0' : '0.0') + '));   // ' + MODES[it.mode] + '\n';&#10;}&#10;&#10;function buildCode() {&#10;    let s = '// Made by the Cinemnode Script: change the Script, not this.\n' + SHARED + '\n' + CUSTOM + '\n' +&#10;            'void sceneImage(out vec4 o, in vec2 fc)\n{\n' +&#10;            '    vec2 R = iResolution.xy;\n    vec2 uv = fc / R;\n' +&#10;            (state.bg ? '    vec3 C = texture(iImage0, uv).rgb;   // the background\n    float A = 1.0;\n' :&#10;            '    vec3 C = vec3(0.0);   // the colour, times how much covers\n    float A = 0.0;        // how much covers: where it is 0 the picture under the Scene shows\n') +&#10;            '    vec2 q = vec2(uv.x, 1.0 - uv.y);   // as the editor counts: from the top left\n' +&#10;            '    float S = R.y / 1080.0, T = iTime;\n';&#10;    for (const it of state.items)&#10;        if (!it.hidden)&#10;            s += itemCode(it, it.id === state.sel);&#10;    if (state.bg)   // edit aids, switched by P14 (Edges) and P17 (the magnifier at P15, P16) with no new shader&#10;        s += '    if (P14 &gt; 0.5) edgeView(C, uv, int(P14 + 0.5) - 1, P21, P22);\n' +&#10;             '    if (P17 &gt; 0.5) magnifier(C, fc, vec2(P15, 1.0 - P16) * R);\n';&#10;    return s + '    o = A &gt; 0.0001 ? vec4(min(C / A, vec3(1.0)), A) : vec4(0.0);\n}\n\n' + VIEW_MAIN;&#10;}&#10;&#10;let sentCode = '';&#10;function sendCode() {&#10;    const code = buildCode();&#10;    if (code !== sentCode) {&#10;        sentCode = code;&#10;        out(1, { labels: TEXTS.slice(0, 16), code: code });&#10;    }&#10;    sendP();&#10;}&#10;&#10;function sendAids(loupe) {&#10;    out(1, { p: { P21: state.esens, P22: state.ewidth, P14: state.edit &amp;&amp; state.edges &amp;&amp; state.bg ? 1 + state.efilter : 0, P15: loupe ? loupe[0] : 0, P16: loupe ? loupe[1] : 0, P17: loupe &amp;&amp; state.bg ? 1 : 0 } });&#10;}&#10;let tlDirty = false;   // the timeline changed while dragging: a new shader once you let go&#10;c.on('dragend', () =&gt; { sendAids(null); if (tlDirty) { tlDirty = false; sendCode(); } });&#10;&#10;function sendP() {&#10;    const it = selected();&#10;    if (!it)&#10;        return;&#10;    if (it.type === 'board')&#10;        out(1, { p: it.pts.flat().concat([it.speed, it.bright, it.transp || 0,&#10;                                          it.rsize === undefined ? 0.6 : it.rsize, it.rstr === undefined ? 0.6 : it.rstr]) });&#10;    else&#10;        out(1, { p: [it.x, it.y, it.size, it.speed, it.power, it.transp || 0] });&#10;    const [r, g, b] = hexRGB(hexOf(it));&#10;    out(1, { p: { P18: r, P19: g, P20: b } });&#10;}&#10;&#10;// ---------- colours ----------&#10;function hexRGB(hex) { const n = parseInt(hex.slice(1), 16); return [(n &gt;&gt; 16 &amp; 255) / 255, (n &gt;&gt; 8 &amp; 255) / 255, (n &amp; 255) / 255]; }&#10;function rgbHex(r, g, b) { return '#' + [r, g, b].map(v =&gt; Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).padStart(2, '0')).join(''); }&#10;function codeOf(it) {   // #RRGGBB, with AA after it when it is see-through&#10;    const a = Math.round((1 - (it.transp || 0)) * 255);&#10;    return hexOf(it).toUpperCase() + (a &lt; 255 ? ('0' + a.toString(16)).slice(-2).toUpperCase() : '');&#10;}&#10;function parseColour(t) {   // '#f80', '#f808', '#ff8800', '#ff880080', 'ff8800', '255, 136, 0' or '255 136 0 128' -&gt; [hex, alpha 0..1 or null]&#10;    t = String(t).trim();&#10;    const nums = t.match(/^\s*(\d{1,3})[\s,;]+(\d{1,3})[\s,;]+(\d{1,3})(?:[\s,;]+(\d{1,3}))?\s*$/);&#10;    const c = v =&gt; Math.max(0, Math.min(255, +v));&#10;    if (nums) return [rgbHex(c(nums[1]) / 255, c(nums[2]) / 255, c(nums[3]) / 255), nums[4] !== undefined ? c(nums[4]) / 255 : null];&#10;    let h = t.replace(/^#/, '').toLowerCase();&#10;    if (!/^[0-9a-f]+$/.test(h) || ![3, 4, 6, 8].includes(h.length)) return null;&#10;    if (h.length &lt;= 4) h = h.split('').map(x =&gt; x + x).join('');&#10;    return ['#' + h.slice(0, 6), h.length === 8 ? parseInt(h.slice(6), 16) / 255 : null];&#10;}&#10;function applyColour(it, t) {&#10;    const c = parseColour(t);&#10;    if (!it || !c) return false;&#10;    it.hex = c[0];&#10;    if (c[1] !== null) it.transp = 1 - c[1];&#10;    return true;&#10;}&#10;function toHSV(hex) {&#10;    const [r, g, b] = hexRGB(hex), mx = Math.max(r, g, b), mn = Math.min(r, g, b), d = mx - mn;&#10;    let h = 0;&#10;    if (d &gt; 0) h = mx === r ? ((g - b) / d + 6) % 6 : mx === g ? (b - r) / d + 2 : (r - g) / d + 4;&#10;    return [h / 6, mx &gt; 0 ? d / mx : 0, mx];&#10;}&#10;function fromHSV(h, s, v) {&#10;    const k = n =&gt; (n + h * 6) % 6, fn = n =&gt; v - v * s * Math.max(0, Math.min(k(n), 4 - k(n), 1));&#10;    return rgbHex(fn(5), fn(3), fn(1));&#10;}&#10;&#10;// ---------- elements ----------&#10;const selected = () =&gt; state.items.find(it =&gt; it.id === state.sel);&#10;&#10;function addBoard(x, y) {&#10;    const w = 0.18, h = 0.14;&#10;    const it = { id: state.next++, type: 'board', fx: 0, color: 7, text: 0, speed: 0.35, bright: 0.5, seed: Math.random(), mode: 0, pic: 0,&#10;                 pts: [[x - w / 2, y - h / 2], [x + w / 2, y - h / 2], [x + w / 2, y + h / 2], [x - w / 2, y + h / 2]] };&#10;    state.items.push(it);&#10;    select(it.id);&#10;}&#10;&#10;function addLight(x, y) {&#10;    const it = { id: state.next++, type: 'light', x: x, y: y, mode: 1, color: 0, size: 0.3, speed: 0.4, power: 0.5, seed: Math.random() };&#10;    state.items.push(it);&#10;    select(it.id);&#10;}&#10;&#10;function duplicate() {&#10;    const it = selected();&#10;    if (!it)&#10;        return;&#10;    const n = JSON.parse(JSON.stringify(it));&#10;    n.id = state.next++;&#10;    n.seed = Math.random();&#10;    if (n.type === 'board')&#10;        n.pts = n.pts.map(p =&gt; [p[0] + 0.03, p[1] + 0.03]);&#10;    else { n.x += 0.03; n.y += 0.03; }&#10;    state.items.push(n);&#10;    select(n.id);&#10;}&#10;&#10;function remove(id) {&#10;    const it = state.items.find(t =&gt; t.id === id);&#10;    if (!it || it.locked)&#10;        return;&#10;    state.items = state.items.filter(it =&gt; it.id !== id);&#10;    if (state.sel === id)&#10;        state.sel = 0;&#10;    sendCode();&#10;    rebuild();&#10;}&#10;&#10;// a press on another element makes it the selected one at once (its shader reads P from then on), but its&#10;// handles are drawn anew only when the mouse lets go, so the drag that started with the press goes on&#10;let pending = false;&#10;function pick(id) {&#10;    if (state.sel === id)&#10;        return;&#10;    state.sel = id;&#10;    sendCode();&#10;    pending = true;&#10;}&#10;c.on('release', () =&gt; { if (tlDirty) { tlDirty = false; sendCode(); } if (pending) { pending = false; rebuild(); } });&#10;&#10;function select(id) {&#10;    sure = false;&#10;    hexTyping = null;&#10;    state.sel = id;&#10;    sendCode();&#10;    rebuild();&#10;}&#10;&#10;function centre(it) {&#10;    if (it.type !== 'board')&#10;        return [it.x, it.y];&#10;    return [it.pts.reduce((a, p) =&gt; a + p[0], 0) / 4, it.pts.reduce((a, p) =&gt; a + p[1], 0) / 4];&#10;}&#10;&#10;// scale (and turn, in degrees) a sign round its middle; the turn is worked out in pixels so it stays square&#10;function transform(it, k, deg) {&#10;    const [cx, cy] = centre(it);&#10;    const a = deg * Math.PI / 180, ca = Math.cos(a), sa = Math.sin(a);&#10;    it.pts = it.pts.map(p =&gt; {&#10;        const dx = (p[0] - cx) * W, dy = (p[1] - cy) * H;&#10;        return [cx + k * (dx * ca - dy * sa) / W, cy + k * (dx * sa + dy * ca) / H];&#10;    });&#10;}&#10;&#10;// ---------- drawing the editor ----------&#10;let layer = null, handles = null, picking = false;&#10;const clampN = v =&gt; Math.max(-0.5, Math.min(1.5, v));&#10;&#10;function rebuild() {&#10;    if (layer)&#10;        layer.remove();&#10;    layer = c.group({});&#10;    handles = {};&#10;    fitView();&#10;    sendView();&#10;    if (state.edit) {&#10;        const bg = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#00000000', interactive: true, cursor: state.zoom &gt; 1 ? 'grab' : 'default' });&#10;        let panFrom = null, panned = false;&#10;        bg.on('click', () =&gt; { if (!panned &amp;&amp; state.sel) select(0); panned = false; });&#10;        bg.on('doubleclick', e =&gt; addLight(U(e.x), V(e.y)));&#10;        bg.on('press', () =&gt; { panFrom = [state.panX, state.panY]; panned = false; });&#10;        bg.on('drag', e =&gt; { if (!panFrom || state.zoom &lt;= 1) return; panned = true;&#10;            state.panX = panFrom[0] + e.totalX; state.panY = panFrom[1] + e.totalY; fitView(); sendView(); placeAll(); });&#10;        bg.on('wheel', e =&gt; zoomAt(e.x, e.y, e.delta &gt; 0 ? 1.15 : 1 / 1.15));&#10;        for (const it of state.items)&#10;            if (!it.hidden)&#10;                drawHandles(it);&#10;        drawToolbar();&#10;        drawDock();&#10;        if (state.tlOpen)&#10;            drawTimeline();&#10;        if (picking) {&#10;            const sheet = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#00000000', cursor: 'crosshair', interactive: true,&#10;                                       tooltip: 'Click the colour to light up' });&#10;            sheet.on('move', e =&gt; sendAids([U(e.x), V(e.y)]));&#10;            sheet.on('click', e =&gt; { e.stop(); const it = selected(); picking = false;&#10;                if (it) { it.kx = U(e.x); it.ky = V(e.y); } sendAids(null); sendCode(); rebuild(); });&#10;            sheet.on('rightclick', e =&gt; { e.stop(); picking = false; sendAids(null); rebuild(); });&#10;        }&#10;    } else {&#10;        const bg = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#00000000', interactive: true });&#10;        bg.on('doubleclick', () =&gt; setEdit(true));&#10;    }&#10;}&#10;&#10;function boardPoints(it) {&#10;    return it.pts.map(p =&gt; [X(p[0]), Y(p[1])]);&#10;}&#10;&#10;function drawHandles(it) {&#10;    const sel = it.id === state.sel;&#10;    const col = sel ? ACC : '#ffffffaa';&#10;    if (it.locked) {   // on lock: only its outline, which the mouse goes through&#10;        if (it.type === 'board')&#10;            layer.polygon({ x: 0, y: 0, points: boardPoints(it), fill: '#00000000', stroke: col, strokeWidth: 1, opacity: 0.4, interactive: false });&#10;        else&#10;            layer.circle({ x: X(it.x), y: Y(it.y), r: 6, fill: '#00000000', stroke: col, strokeWidth: 1.5, opacity: 0.5, interactive: false });&#10;        return;&#10;    }&#10;    if (it.type === 'board') {&#10;        const h = {};&#10;        h.poly = layer.polygon({ x: 0, y: 0, points: boardPoints(it), fill: sel ? '#8a3fff1c' : '#ffffff08',&#10;                                 stroke: col, strokeWidth: sel ? 2.5 : 1.5, cursor: 'move',&#10;                                 tooltip: 'Drag: move - wheel: bigger/smaller - Shift + wheel: rotate - right-click: delete' });&#10;        h.poly.on('press', () =&gt; { pick(it.id); dragFrom = keep(it); });&#10;        h.poly.on('drag', e =&gt; { const cur = selected(); if (!cur || !dragFrom) return;&#10;            const moved = dragFrom.pts.map(p =&gt; [p[0] + DU(e.totalX), p[1] + DV(e.totalY)]);&#10;            const [sx, sy] = snapDelta(moved, cur.id, e.alt);&#10;            cur.pts = moved.map(p =&gt; [clampN(p[0] + sx), clampN(p[1] + sy)]); moveHandles(cur); });&#10;        h.poly.on('wheel', e =&gt; { if (it.id !== state.sel) select(it.id); const cur = selected();&#10;            if (e.shift) transform(cur, 1, e.delta &gt; 0 ? 2 : -2); else transform(cur, e.delta &gt; 0 ? 1.04 : 1 / 1.04, 0);&#10;            moveHandles(cur); e.stop(); });&#10;        h.poly.on('rightclick', () =&gt; remove(it.id));&#10;        h.name = layer.text({ x: X(it.pts[0][0]), y: Y(it.pts[0][1]) - 8, text: FX[it.fx], size: 15, fill: col,&#10;                              baseline: 'bottom', interactive: false, shadow: '#000000c0' });&#10;        h.dots = it.pts.map((p, i) =&gt; {&#10;            const d = layer.circle({ x: X(p[0]), y: Y(p[1]), r: sel ? 11 : 7, fill: sel ? ACC : '#ffffff60',&#10;                                     stroke: '#000000', strokeWidth: 1.5, cursor: 'crosshair', tooltip: 'Drag this corner' });&#10;            d.on('press', () =&gt; { pick(it.id); dragFrom = keep(it); });&#10;            d.on('drag', e =&gt; { const cur = selected(); if (!cur || !dragFrom) return;&#10;                const [sx, sy] = snapDelta([[U(e.x), V(e.y)]], cur.id, e.alt);&#10;                const to = [clampN(U(e.x) + sx), clampN(V(e.y) + sy)];&#10;                if (!!cur.scaleCorners !== !!e.ctrl) {&#10;                    // scale the whole board from the opposite corner, as far as the corner has moved along its diagonal (in pixels)&#10;                    const a = dragFrom.pts[(i + 2) % 4], o = dragFrom.pts[i];&#10;                    const vx = (o[0] - a[0]) * W, vy = (o[1] - a[1]) * H, ux = (to[0] - a[0]) * W, uy = (to[1] - a[1]) * H;&#10;                    const k = Math.max(0.05, (ux * vx + uy * vy) / Math.max(1e-6, vx * vx + vy * vy));&#10;                    cur.pts = dragFrom.pts.map(p =&gt; [clampN(a[0] + (p[0] - a[0]) * k), clampN(a[1] + (p[1] - a[1]) * k)]);&#10;                } else&#10;                    cur.pts[i] = to;&#10;                moveHandles(cur); sendAids(cur.pts[i]); });&#10;            return d;&#10;        });&#10;        handles[it.id] = h;&#10;    } else {&#10;        const h = {};&#10;        const r = (6 + 250 * it.size * it.size) * view.s;&#10;        h.ring = layer.circle({ x: X(it.x), y: Y(it.y), r: r, fill: '#00000000', stroke: col + (sel ? '' : ''), strokeWidth: 1, opacity: 0.5, interactive: false });&#10;        h.dot = layer.circle({ x: X(it.x), y: Y(it.y), r: sel ? 12 : 8, fill: sel ? ACC : '#ffffff60', stroke: '#000000', strokeWidth: 1.5,&#10;                               cursor: 'move', tooltip: 'Light - drag: move - wheel: size - right-click: delete' });&#10;        h.dot.on('press', () =&gt; { pick(it.id); dragFrom = keep(it); });&#10;        h.dot.on('drag', e =&gt; { const cur = selected(); if (!cur || !dragFrom || tlOn(cur, 'x') || tlOn(cur, 'y')) return;&#10;            const p = [dragFrom.x + DU(e.totalX), dragFrom.y + DV(e.totalY)];&#10;            const [sx, sy] = snapDelta([p], cur.id, e.alt);&#10;            cur.x = clampN(p[0] + sx); cur.y = clampN(p[1] + sy); moveHandles(cur); sendAids([cur.x, cur.y]); });&#10;        h.dot.on('wheel', e =&gt; { if (it.id !== state.sel) select(it.id); const cur = selected(); if (tlOn(cur, 'size')) { e.stop(); return; }&#10;            cur.size = Math.max(0, Math.min(1, cur.size + (e.delta &gt; 0 ? 0.02 : -0.02))); moveHandles(cur); refreshSliders(); e.stop(); });&#10;        h.dot.on('rightclick', () =&gt; remove(it.id));&#10;        handles[it.id] = h;&#10;    }&#10;}&#10;&#10;// a drag or a wheel moved the selected element: move its handles and send its P, with no new drawing or shader&#10;function moveHandles(it) {&#10;    place(it);&#10;    sendP();&#10;}&#10;function place(it) {   // put an element's handles where it is on the canvas now&#10;    const h = handles[it.id];&#10;    if (h &amp;&amp; it.type === 'board') {&#10;        h.poly.set({ points: boardPoints(it) });&#10;        h.dots.forEach((d, i) =&gt; d.set({ x: X(it.pts[i][0]), y: Y(it.pts[i][1]) }));&#10;        h.name.set({ x: X(it.pts[0][0]), y: Y(it.pts[0][1]) - 8 });&#10;    } else if (h) {&#10;        h.dot.set({ x: X(it.x), y: Y(it.y) });&#10;        h.ring.set({ x: X(it.x), y: Y(it.y), r: (6 + 250 * it.size * it.size) * view.s });&#10;    }&#10;}&#10;function placeAll() {   // the view moved: every handle follows (locked ones are drawn again)&#10;    if (state.items.some(it =&gt; it.locked &amp;&amp; !it.hidden)) { rebuild(); return; }&#10;    state.items.forEach(place);&#10;}&#10;&#10;// ---------- the Layers panel ----------&#10;const itemName = it =&gt; (it.type === 'board' ? 'Board ' : 'Light ') + it.id + ' - ' + (it.type === 'board' ? FX[it.fx] : MODES[it.mode]);&#10;&#10;function moveItem(it, d) {   // d +1: one to the front (drawn later), -1: one to the back&#10;    const a = state.items, i = a.indexOf(it), j = i + d;&#10;    if (j &lt; 0 || j &gt;= a.length)&#10;        return;&#10;    a[i] = a[j]; a[j] = it;&#10;    sendCode();&#10;    rebuild();&#10;}&#10;&#10;function eye(g, x, y, on) {&#10;    const col = on ? '#f1ecff' : '#5c5774';&#10;    g.circle({ x: x, y: y, rx: 9, ry: 5.5, fill: '#00000000', stroke: col, strokeWidth: 1.5, interactive: false });&#10;    g.circle({ x: x, y: y, r: 2.5, fill: col, interactive: false });&#10;    if (!on)&#10;        g.line({ x1: x - 9, y1: y + 7, x2: x + 9, y2: y - 7, width: 1.5, stroke: col, interactive: false });&#10;}&#10;&#10;function padlock(g, x, y, on) {&#10;    const col = on ? ACC : '#5c5774';&#10;    g.arc({ x: on ? x : x + 4, y: y - 3, r: 4.5, width: 1.8, start: -90, end: 90, stroke: col, interactive: false });&#10;    g.rect({ x: x - 6, y: y - 2, w: 12, h: 9, radius: 2, fill: col, interactive: false });&#10;}&#10;&#10;const LROWS = 12;&#10;function drawLayers(g, y, LW) {   // the list of elements, in the dock under Properties; returns where it ends&#10;    const RH = 30;&#10;    const list = state.items.slice().reverse();   // the front first&#10;    state.lscroll = Math.max(0, Math.min(state.lscroll || 0, list.length - LROWS));&#10;    if (!list.length) {&#10;        g.text({ x: 16, y: y + 10, text: 'Nothing yet: add a board or a light (toolbar).', size: 13, baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;        y += 30;&#10;    }&#10;    list.slice(state.lscroll, state.lscroll + LROWS).forEach(it =&gt; {&#10;        const sel = it.id === state.sel;&#10;        const row = g.group({ x: 8, y: y });&#10;        const rb = row.rect({ w: LW - 16, h: RH - 4, radius: 6, fill: sel ? '#8a3fff38' : '#00000000', stroke: sel ? ACC : '#00000000', strokeWidth: 1, cursor: 'pointer', tooltip: 'Select' });&#10;        rb.on('click', e =&gt; { e.stop(); select(it.id); });&#10;        rb.on('wheel', e =&gt; { e.stop(); state.lscroll += e.delta &gt; 0 ? -1 : 1; rebuild(); });&#10;        const eb = row.rect({ x: 2, y: 0, w: 28, h: RH - 4, fill: '#00000000', cursor: 'pointer', tooltip: it.hidden ? 'Show' : 'Hide' });&#10;        eb.on('click', e =&gt; { e.stop(); it.hidden = !it.hidden; sendCode(); rebuild(); });&#10;        eye(row, 16, (RH - 4) / 2, !it.hidden);&#10;        row.text({ x: 38, y: (RH - 4) / 2, text: itemName(it), size: 13, baseline: 'middle', fill: it.hidden ? '#5c5774' : sel ? ACC : '#f1ecff', interactive: false });&#10;        const lb = row.rect({ x: LW - 100, y: 0, w: 28, h: RH - 4, fill: '#00000000', cursor: 'pointer', tooltip: it.locked ? 'Unlock' : 'Lock' });&#10;        lb.on('click', e =&gt; { e.stop(); it.locked = !it.locked; rebuild(); });&#10;        padlock(row, LW - 86, (RH - 4) / 2, !!it.locked);&#10;        const up = row.triangle({ x1: LW - 60, y1: 18, x2: LW - 48, y2: 18, x3: LW - 54, y3: 8, fill: '#b8b2d0', cursor: 'pointer', tooltip: 'Bring forward' });&#10;        up.on('click', e =&gt; { e.stop(); moveItem(it, 1); });&#10;        const dn = row.triangle({ x1: LW - 40, y1: 8, x2: LW - 28, y2: 8, x3: LW - 34, y3: 18, fill: '#b8b2d0', cursor: 'pointer', tooltip: 'Send backward' });&#10;        dn.on('click', e =&gt; { e.stop(); moveItem(it, -1); });&#10;        y += RH;&#10;    });&#10;    if (list.length &gt; LROWS) {&#10;        g.text({ x: 16, y: y + 8, text: (state.lscroll + 1) + '-' + Math.min(list.length, state.lscroll + LROWS) + ' of ' + list.length + ' - scroll for more',&#10;                 size: 11, baseline: 'middle', fill: '#5c5774', interactive: false });&#10;        y += 20;&#10;    }&#10;    return y + 6;&#10;}&#10;&#10;// ---------- the toolbar: down the left side, as in Photoshop ----------&#10;const TW = 64;&#10;function icon(g, kind, col) {   // a small picture of what a tool does, drawn round (24, 20)&#10;    const o = { interactive: false };&#10;    const line = (x1, y1, x2, y2) =&gt; g.line(Object.assign({ x1: x1, y1: y1, x2: x2, y2: y2, width: 2, stroke: col }, o));&#10;    const plus = () =&gt; { line(39, 5, 39, 15); line(34, 10, 44, 10); };&#10;    if (kind === 'board') {&#10;        g.polygon(Object.assign({ points: [[12, 12], [32, 9], [33, 30], [11, 27]], fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        plus();&#10;    } else if (kind === 'light') {&#10;        g.circle(Object.assign({ x: 21, y: 21, r: 5, fill: col }, o));&#10;        g.circle(Object.assign({ x: 21, y: 21, r: 10, fill: '#00000000', stroke: col, strokeWidth: 1.5 }, o));&#10;        plus();&#10;    } else if (kind === 'copy') {&#10;        g.rect(Object.assign({ x: 12, y: 8, w: 15, h: 17, radius: 2, fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        g.rect(Object.assign({ x: 20, y: 14, w: 15, h: 17, radius: 2, fill: '#14121f', stroke: col, strokeWidth: 2 }, o));&#10;    } else if (kind === 'delete') {&#10;        g.rect(Object.assign({ x: 16, y: 13, w: 16, h: 19, radius: 2, fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        line(12, 11, 36, 11); line(21, 7, 27, 7);&#10;    } else if (kind === 'picture') {&#10;        g.rect(Object.assign({ x: 11, y: 9, w: 26, h: 22, radius: 2, fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        g.triangle(Object.assign({ x1: 14, y1: 29, x2: 22, y2: 17, x3: 30, y3: 29, fill: col }, o));&#10;        g.circle(Object.assign({ x: 31, y: 15, r: 2.5, fill: col }, o));&#10;    } else if (kind === 'edges') {&#10;        g.rect(Object.assign({ x: 10, y: 10, w: 13, h: 19, fill: '#00000000', stroke: '#40ff73', strokeWidth: 2 }, o));&#10;        g.circle(Object.assign({ x: 31, y: 20, r: 7, fill: '#00000000', stroke: '#ff59d9', strokeWidth: 2 }, o));&#10;    } else if (kind === 'snap') {   // a magnet&#10;        g.arc(Object.assign({ x: 24, y: 17, r: 8, width: 5, start: 90, end: 270, stroke: col }, o));&#10;        g.rect(Object.assign({ x: 13.5, y: 22, w: 5, h: 7, fill: '#ff5a5a' }, o));&#10;        g.rect(Object.assign({ x: 29.5, y: 22, w: 5, h: 7, fill: '#ff5a5a' }, o));&#10;    } else if (kind === 'clear') {&#10;        line(15, 10, 33, 28); line(33, 10, 15, 28);&#10;    } else if (kind === 'panels') {&#10;        g.rect(Object.assign({ x: 11, y: 9, w: 26, h: 22, radius: 2, fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        g.rect(Object.assign({ x: 27, y: 9, w: 10, h: 22, fill: col }, o));&#10;    } else if (kind === 'timeline') {   // a line with keys on it&#10;        line(9, 30, 19, 14); line(19, 14, 29, 24); line(29, 24, 39, 10);&#10;        [[19, 14], [29, 24]].forEach(([x, y]) =&gt; g.rect(Object.assign({ x: x - 3, y: y - 3, w: 6, h: 6, fill: col }, o)));&#10;    } else if (kind === 'fit') {   // a frame with its corners&#10;        line(11, 9, 18, 9); line(11, 9, 11, 15); line(37, 9, 30, 9); line(37, 9, 37, 15);&#10;        line(11, 31, 18, 31); line(11, 31, 11, 25); line(37, 31, 30, 31); line(37, 31, 37, 25);&#10;        g.circle(Object.assign({ x: 24, y: 20, r: 4, fill: col }, o));&#10;    } else if (kind === 'done') {&#10;        line(14, 19, 21, 26); line(21, 26, 34, 11);&#10;    }&#10;}&#10;&#10;function tool(g, y, kind, label, tip, fn, on, accent) {&#10;    const b = g.group({ x: 8, y: y, cursor: 'pointer', tooltip: tip });&#10;    const bg = b.rect({ w: 48, h: 50, radius: 8, fill: accent ? ACC : on ? '#8a3fff40' : '#00000000', stroke: on ? ACC : '#00000000', strokeWidth: 1 });&#10;    const col = accent ? '#ffffff' : on ? ACC : '#dcd6f0';&#10;    icon(b, kind, col);&#10;    b.text({ x: 24, y: 42, text: label, size: 10, align: 'center', baseline: 'middle', fill: col, interactive: false });&#10;    b.on('enter', () =&gt; { if (!on &amp;&amp; !accent) bg.set({ fill: '#ffffff14' }); });&#10;    b.on('leave', () =&gt; { if (!on &amp;&amp; !accent) bg.set({ fill: '#00000000' }); });&#10;    b.on('click', e =&gt; { e.stop(); fn(); });&#10;    return y + 56;&#10;}&#10;&#10;function drawToolbar() {&#10;    const g = layer.group({ x: 0, y: 0 });&#10;    g.rect({ w: TW, h: H, fill: '#14121ff4', stroke: '#2f2850', strokeWidth: 1, interactive: true });&#10;    g.text({ x: TW / 2, y: 20, text: 'CN', size: 15, align: 'center', baseline: 'middle', fill: ACC, interactive: false });&#10;    const sep = y =&gt; { g.line({ x1: 12, y1: y + 2, x2: TW - 12, y2: y + 2, width: 1, stroke: '#2f2850', interactive: false }); return y + 10; };&#10;    let y = 40;&#10;    y = tool(g, y, 'board', 'Board', 'Add a board (a sign or a screen with an effect)', () =&gt; addBoard(0.5, 0.5));&#10;    y = tool(g, y, 'light', 'Light', 'Add a light (double-clicking the picture does too)', () =&gt; addLight(0.5, 0.5));&#10;    y = tool(g, y, 'copy', 'Copy', 'Copy the selected element', duplicate);&#10;    y = tool(g, y, 'delete', 'Delete', 'Delete the selected element (or right-click it)', () =&gt; { if (state.sel) remove(state.sel); });&#10;    y = sep(y);&#10;    y = tool(g, y, 'picture', 'Picture', 'Choose a background picture', () =&gt; out(2));&#10;    if (state.bg)&#10;        y = tool(g, y, 'edges', 'Edges', 'Show the edges in the picture (set them up in Properties)', () =&gt; { state.edges = !state.edges; sendAids(null); rebuild(); }, state.edges);&#10;    y = tool(g, y, 'fit', state.zoom &gt; 1 ? Math.round(state.zoom * 100) + '%' : 'Fit', 'Show the whole picture (wheel on an empty spot zooms, dragging it moves the picture)',&#10;             () =&gt; { state.zoom = 1; state.panX = 0; state.panY = 0; rebuild(); }, state.zoom &gt; 1);&#10;    y = tool(g, y, 'timeline', 'Timeline', 'Animate the selected element in a loop: its Transparency, colour and the rest', () =&gt; { state.tlOpen = !state.tlOpen; rebuild(); }, state.tlOpen);&#10;    y = tool(g, y, 'snap', 'Snap', 'Snap to the other elements and the sides (Alt while dragging: no snap)', () =&gt; { state.snap = !state.snap; rebuild(); }, state.snap);&#10;    y = sep(y);&#10;    tool(g, y, 'clear', sure ? 'Sure?' : 'Clear', sure ? 'Click again: everything not locked goes' : 'Delete everything that is not locked', () =&gt; {&#10;        if (!sure) { sure = true; rebuild(); return; }&#10;        sure = false; state.items = state.items.filter(t =&gt; t.locked); state.sel = 0; sendCode(); rebuild(); }, sure);&#10;    tool(g, H - 120, 'panels', 'Panels', state.dock ? 'Hide the panels' : 'Show the panels', () =&gt; { state.dock = !state.dock; rebuild(); }, state.dock);&#10;    tool(g, H - 62, 'done', 'Done', 'Leave edit mode (double-click the Scene to come back)', () =&gt; setEdit(false), false, true);&#10;}&#10;&#10;// ---------- the panel ----------&#10;let sliders = [];&#10;&#10;function button(g, x, y, w, label, fn, on) {&#10;    const b = g.group({ x: x, y: y, cursor: 'pointer' });&#10;    const bg = b.rect({ w: w, h: 30, radius: 6, fill: on ? ACC : '#1a1628', stroke: on ? ACC : '#2f2850', strokeWidth: 1 });&#10;    b.text({ x: w / 2, y: 15, text: label, size: 14, align: 'center', baseline: 'middle', fill: on ? '#ffffff' : '#f1ecff', interactive: false });&#10;    b.on('enter', () =&gt; { if (!on) bg.set({ stroke: ACC }); });&#10;    b.on('leave', () =&gt; { if (!on) bg.set({ stroke: '#2f2850' }); });&#10;    b.on('click', e =&gt; { e.stop(); fn(); });&#10;    return b;&#10;}&#10;&#10;function chips(g, x, y, w, names, cur, fn) {&#10;    let cx = x, cy = y;&#10;    names.forEach((n, i) =&gt; {&#10;        const bw = Math.max(54, n.length * 8.2 + 20);&#10;        if (cx + bw &gt; x + w) { cx = x; cy += 36; }&#10;        button(g, cx, cy, bw, n, () =&gt; fn(i), i === cur);&#10;        cx += bw + 6;&#10;    });&#10;    return cy + 36;&#10;}&#10;&#10;function swatches(g, x, y, it) {&#10;    if (tlOn(it, 'r') || tlOn(it, 'g') || tlOn(it, 'b'))   // the timeline animates the colour: no swatches or sliders&#10;        return lockedRow(g, x, y, 'Colour', 'animated on the timeline (' + ['r', 'g', 'b'].filter(k =&gt; tlOn(it, k)).map(k =&gt; ({ r: 'Red', g: 'Green', b: 'Blue' })[k]).join(', ') + ')') + 4;&#10;    const cur = hexOf(it).toLowerCase();&#10;    const set = hex =&gt; { it.hex = hex; sendCode(); rebuild(); };&#10;    const all = COLORS.map(([n, hex]) =&gt; [n, hex, false]).concat(state.palette.map(hex =&gt; [hex + ' - right-click forgets it', hex, true]));&#10;    let cx = x;&#10;    all.forEach(([n, hex, mine], i) =&gt; {&#10;        if (cx &gt; x + CW - 48) { cx = x; y += 32; }&#10;        const on = hex.toLowerCase() === cur;&#10;        const s = g.circle({ x: cx + 14, y: y + 14, r: mine ? 10 : 12, fill: hex, stroke: on ? '#ffffff' : mine ? '#ffffff60' : '#00000080',&#10;                             strokeWidth: on ? 3 : 1, cursor: 'pointer', tooltip: n });&#10;        s.on('click', e =&gt; { e.stop(); set(hex); });&#10;        if (mine)&#10;            s.on('rightclick', e =&gt; { e.stop(); state.palette = state.palette.filter(p =&gt; p !== hex); rebuild(); });&#10;        cx += 34;&#10;    });&#10;    if (cx &gt; x + CW - 48) { cx = x; y += 32; }&#10;    const add = g.group({ x: cx + 14, y: y + 14, cursor: 'pointer', tooltip: 'Keep this colour in your palette' });&#10;    add.circle({ r: 12, fill: '#1a1628', stroke: ACC, strokeWidth: 1 });&#10;    add.text({ text: '+', size: 18, align: 'center', baseline: 'middle', fill: ACC, interactive: false });&#10;    add.on('click', e =&gt; { e.stop(); if (!state.palette.includes(hexOf(it)) &amp;&amp; state.palette.length &lt; 24) state.palette.push(hexOf(it)); rebuild(); });&#10;    y += 34;&#10;    // the colour as a code, and RGB or HSV&#10;    y = codeField(g, x, y, it);&#10;    if (state.cmode === 0) {   // Red, Green and Blue, 0 to 255: the shader follows at once (P18-P20)&#10;        let rgb = hexRGB(hexOf(it));&#10;        const mixer = (k, label) =&gt; slider(g, x, y, CW, label, () =&gt; rgb[k], v =&gt; { rgb[k] = Math.round(v * 255) / 255; it.hex = rgbHex(rgb[0], rgb[1], rgb[2]); },&#10;                                           v =&gt; String(Math.round(v * 255)));&#10;        y = mixer(0, 'Red'); y = mixer(1, 'Green'); y = mixer(2, 'Blue');&#10;    } else {   // Hue, Saturation and Value&#10;        let hsv = toHSV(hexOf(it));&#10;        const mixer = (k, label, f) =&gt; slider(g, x, y, CW, label, () =&gt; hsv[k], v =&gt; { hsv[k] = v; it.hex = fromHSV(hsv[0], hsv[1], hsv[2]); }, f);&#10;        y = mixer(0, 'Hue', v =&gt; Math.round(v * 360) + ' deg'); y = mixer(1, 'Saturation', v =&gt; Math.round(v * 100) + '%'); y = mixer(2, 'Value', v =&gt; Math.round(v * 100) + '%');&#10;    }&#10;    return y + 4;&#10;}&#10;&#10;function codeField(g, x, y, it) {   // the code (#RRGGBB or #RRGGBBAA); a click opens keys to type one&#10;    const typing = hexTyping !== null;&#10;    const f = g.group({ x: x, y: y, cursor: 'text', tooltip: 'Click to type a colour code: #RGB, #RGBA, #RRGGBB or #RRGGBBAA' });&#10;    f.rect({ w: 170, h: 30, radius: 6, fill: '#0b0a12', stroke: typing ? ACC : '#2f2850', strokeWidth: 1 });&#10;    const chip = f.rect({ x: 6, y: 6, w: 18, h: 18, radius: 4, fill: hexOf(it), interactive: false });&#10;    const shown = typing ? '#' + hexTyping + '_' : codeOf(it);&#10;    const code = f.text({ x: 32, y: 15, text: shown, size: 15, baseline: 'middle', fill: typing ? ACC : '#f1ecff', interactive: false });&#10;    if (!typing)&#10;        sliders.push(() =&gt; { chip.set({ fill: hexOf(it) }); code.set({ text: codeOf(it) }); });   // follows the sliders&#10;    f.on('click', e =&gt; { e.stop(); hexTyping = typing ? null : ''; rebuild(); });&#10;    ['RGB', 'HSV'].forEach((n, i) =&gt; button(g, x + CW - 132 + i * 68, y, 62, n, () =&gt; { state.cmode = i; rebuild(); }, state.cmode === i));&#10;    y += 40;&#10;    if (!typing)&#10;        return y;&#10;    const keys = '0123456789ABCDEF'.split('');&#10;    const KW = 36, gap = 5, per = Math.floor((CW + gap) / (KW + gap));&#10;    keys.forEach((k, i) =&gt; {&#10;        button(g, x + (i % per) * (KW + gap), y + Math.floor(i / per) * 36, KW, k, () =&gt; { if (hexTyping.length &lt; 8) { hexTyping += k; rebuild(); } }, false);&#10;    });&#10;    y += Math.ceil(keys.length / per) * 36;&#10;    button(g, x, y, 60, 'Back', () =&gt; { hexTyping = hexTyping.slice(0, -1); rebuild(); }, false);&#10;    button(g, x + 66, y, 90, 'Cancel', () =&gt; { hexTyping = null; rebuild(); }, false);&#10;    const ok = [3, 4, 6, 8].includes(hexTyping.length);&#10;    button(g, x + 162, y, 70, 'OK', () =&gt; { if (ok &amp;&amp; applyColour(it, hexTyping)) { hexTyping = null; sendCode(); rebuild(); } }, ok);&#10;    g.text({ x: x + 244, y: y + 15, text: '3, 4, 6 or 8 digits', size: 12, baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;    return y + 42;&#10;}&#10;&#10;function lockedRow(g, x, y, label, note) {   // a setting the timeline animates: its name, and a link to the timeline instead of a slider&#10;    g.text({ x: x, y: y + 11, text: label, size: 13, baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;    const b = g.group({ x: x + 110, y: y, cursor: 'pointer', tooltip: 'Locked: the timeline animates it. Click to open the timeline.' });&#10;    b.circle({ x: 5, y: 11, r: 4.5, fill: ACC });&#10;    b.text({ x: 16, y: 11, text: note || 'animated on the timeline', size: 13, baseline: 'middle', fill: ACC });&#10;    b.on('click', e =&gt; { e.stop(); state.tlOpen = true; rebuild(); });&#10;    return y + 30;&#10;}&#10;function aslider(g, x, y, w, label, it, key, get, setv, fmt) {   // a slider, locked while the timeline animates what it sets&#10;    return tlOn(it, key) ? lockedRow(g, x, y, label) : slider(g, x, y, w, label, get, setv, fmt);&#10;}&#10;&#10;function transpRow(panel, y, it, PW) {   // the Transparency slider (locked while the timeline animates it), and a light's animated place&#10;    if (tlOn(it, 'transp'))&#10;        y = lockedRow(panel, 16, y, 'Transparency');&#10;    else&#10;        y = slider(panel, 16, y, PW - 32, 'Transparency', () =&gt; it.transp || 0, v =&gt; it.transp = v, v =&gt; Math.round(v * 100) + '%');&#10;    if (tlOn(it, 'x') || tlOn(it, 'y'))   // a light's place has no slider: say so here&#10;        y = lockedRow(panel, 16, y, 'Position', 'animated on the timeline (' + [['x', 'Across'], ['y', 'Down']].filter(k =&gt; tlOn(it, k[0])).map(k =&gt; k[1]).join(', ') + ')');&#10;    return y;&#10;}&#10;&#10;function drawTimeline() {&#10;    const x0 = TW, w = W - TW - (state.dock ? DW : 0), y0 = H - TLH;&#10;    const g = layer.group({ x: x0, y: y0 });&#10;    g.rect({ w: w, h: TLH, fill: '#14121ff4', stroke: '#2f2850', strokeWidth: 1, interactive: true });&#10;    const it = selected();&#10;    g.text({ x: 16, y: 20, text: 'TIMELINE', size: 13, baseline: 'middle', fill: ACC, interactive: false });&#10;    if (!it) {&#10;        g.text({ x: 110, y: 20, text: 'Select a board or a light to animate what it has.', size: 13, baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;        return;&#10;    }&#10;    const tl = tlOf(it), props = tlProps(it);&#10;    let prop = props.find(p =&gt; p[0] === state.tlProp) || props[0];&#10;    const [key, name, now, show] = prop;&#10;    const tr = tlTrack(it, key, now);&#10;    g.text({ x: 110, y: 20, text: itemName(it), size: 13, baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;    button(g, w - 480, 6, 110, tr.on ? 'Animated' : 'Animate', () =&gt; { tr.on = !tr.on; sendCode(); rebuild(); }, tr.on);&#10;    button(g, w - 364, 6, 110, 'Reset keys', () =&gt; { delete tl.tracks[key]; tlTrack(it, key, now).on = tr.on; sendCode(); rebuild(); }, false);&#10;    // the loop's length (for all of this element's tracks): its own little slider, in seconds&#10;    g.text({ x: w - 236, y: 21, text: 'loop', size: 12, baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;    const lw = 120, lx = w - 128, val = g.text({ x: lx - 6, y: 21, text: tl.len.toFixed(1) + ' s', size: 12, align: 'right', baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;    const track = g.rect({ x: lx, y: 15, w: lw, h: 12, radius: 6, fill: '#1a1628', stroke: '#2f2850', strokeWidth: 1, cursor: 'ew-resize', tooltip: 'How long one loop takes' });&#10;    const fill = g.rect({ x: lx, y: 15, w: lw * tlLenV(tl.len), h: 12, radius: 6, fill: ACC, interactive: false });&#10;    const setLen = ex =&gt; { const v = Math.max(0, Math.min(1, (ex - x0 - lx) / lw)); tl.len = Math.round(tlLen(v) * 10) / 10; fill.set({ w: lw * tlLenV(tl.len) }); val.set({ text: tl.len.toFixed(1) + ' s' }); tlDirty = true; };&#10;    track.on('press', e =&gt; { e.stop(); setLen(e.x); });&#10;    track.on('drag', e =&gt; { e.stop(); setLen(e.x); });&#10;    // what to animate: one chip each, a dot on the ones that are animated&#10;    let cx = 16;&#10;    props.forEach(p =&gt; {&#10;        const on = tlOn(it, p[0]), label = (on ? '    ' : '') + p[1];&#10;        const bw = Math.max(54, p[1].length * 7.6 + 18 + (on ? 16 : 0));&#10;        button(g, cx, 40, bw, label, () =&gt; { state.tlProp = p[0]; rebuild(); }, p[0] === key);&#10;        if (on)   // a round dot: this one is animated&#10;            g.circle({ x: cx + 13, y: 55, r: 4.5, fill: p[0] === key ? '#ffffff' : ACC, interactive: false });&#10;        cx += bw + 6;&#10;    });&#10;    // the graph: time across (one loop), the value up&#10;    const gx = 56, gy = 84, gw = w - gx - 24, gh = TLH - gy - 30;&#10;    const area = g.rect({ x: gx, y: gy, w: gw, h: gh, fill: '#0b0a12', stroke: '#2f2850', strokeWidth: 1, cursor: 'crosshair', interactive: true,&#10;                          tooltip: 'Click to add a key - drag a key - right-click a key to remove it' });&#10;    for (let i = 0; i &lt;= 4; i++) {&#10;        const lx2 = gx + gw * i / 4;&#10;        g.line({ x1: lx2, y1: gy, x2: lx2, y2: gy + gh, width: 1, stroke: '#2f285080', interactive: false });&#10;        g.text({ x: lx2, y: gy + gh + 13, text: (tl.len * i / 4).toFixed(1) + ' s', size: 11, align: i === 0 ? 'left' : i === 4 ? 'right' : 'center', baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;    }&#10;    g.line({ x1: gx, y1: gy + gh / 2, x2: gx + gw, y2: gy + gh / 2, width: 1, stroke: '#2f285080', interactive: false });&#10;    [[1, gy], [0.5, gy + gh / 2], [0, gy + gh]].forEach(([v, ty]) =&gt;&#10;        g.text({ x: gx - 8, y: ty, text: show(v), size: 11, align: 'right', baseline: 'middle', fill: '#7f7a99', interactive: false }));&#10;    const KX = u =&gt; gx + u * gw, KY = v =&gt; gy + (1 - v) * gh;&#10;    // the other animated tracks, faint, to line things up with&#10;    props.forEach(p =&gt; {&#10;        if (p[0] === key || !tlOn(it, p[0])) return;&#10;        const k = tl.tracks[p[0]].keys;&#10;        for (let i = 1; i &lt; k.length; i++)&#10;            g.line({ x1: KX(k[i - 1][0]), y1: KY(k[i - 1][1]), x2: KX(k[i][0]), y2: KY(k[i][1]), width: 1, stroke: '#5c577490', interactive: false });&#10;    });&#10;    const col = tr.on ? ACC : '#7f7a99';&#10;    const lines = [], dots = [];&#10;    const draw = () =&gt; {&#10;        tr.keys.forEach((k, i) =&gt; {&#10;            if (i) lines[i - 1].set({ x1: KX(tr.keys[i - 1][0]), y1: KY(tr.keys[i - 1][1]), x2: KX(k[0]), y2: KY(k[1]) });&#10;            dots[i].set({ x: KX(k[0]), y: KY(k[1]) });&#10;        });&#10;    };&#10;    tr.keys.forEach((k, i) =&gt; { if (i) lines.push(g.line({ x1: 0, y1: 0, x2: 0, y2: 0, width: 2, stroke: col, interactive: false })); });&#10;    tr.keys.forEach((k, i) =&gt; {&#10;        const end = i === 0 || i === tr.keys.length - 1;&#10;        const d = g.circle({ x: 0, y: 0, r: 7, fill: end ? '#14121f' : col, stroke: col, strokeWidth: 2, cursor: end ? 'ns-resize' : 'move',&#10;                             tooltip: end ? 'Start and end of the loop (they move together)' : 'Drag - right-click removes' });&#10;        d.on('drag', e =&gt; {&#10;            e.stop();&#10;            const v = Math.max(0, Math.min(1, 1 - (e.y - y0 - gy) / gh));&#10;            if (end) { tr.keys[0][1] = v; tr.keys[tr.keys.length - 1][1] = v; }&#10;            else {&#10;                const lo = tr.keys[i - 1][0] + 0.01, hi = tr.keys[i + 1][0] - 0.01;&#10;                k[0] = Math.max(lo, Math.min(hi, (e.x - x0 - gx) / gw));&#10;                k[1] = v;&#10;            }&#10;            draw();&#10;            tlDirty = true;&#10;        });&#10;        d.on('rightclick', e =&gt; { e.stop(); if (!end) { tr.keys.splice(i, 1); sendCode(); rebuild(); } });&#10;        d.on('click', e =&gt; e.stop());&#10;        dots.push(d);&#10;    });&#10;    draw();&#10;    area.on('click', e =&gt; {   // a new key where you click&#10;        e.stop();&#10;        const u = Math.max(0.01, Math.min(0.99, (e.x - x0 - gx) / gw)), v = Math.max(0, Math.min(1, 1 - (e.y - y0 - gy) / gh));&#10;        if (tr.keys.some(k =&gt; Math.abs(k[0] - u) &lt; 0.01)) return;&#10;        tr.keys.push([u, v]);&#10;        tr.keys.sort((a, b) =&gt; a[0] - b[0]);&#10;        tr.on = true;&#10;        sendCode(); rebuild();&#10;    });&#10;    if (!tr.on)&#10;        g.text({ x: gx + gw / 2, y: gy + gh / 2, text: 'Click Animate (or the graph) to animate ' + name, size: 13, align: 'center', baseline: 'middle', fill: '#5c5774', interactive: false });&#10;}&#10;&#10;function slider(g, x, y, w, label, get, setv, fmt) {   // fmt: how to show its value, beside the name&#10;    g.text({ x: x, y: y + 11, text: label, size: 13, baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;    const val = fmt ? g.text({ x: x + 102, y: y + 11, text: fmt(get()), size: 12, align: 'right', baseline: 'middle', fill: '#7f7a99', interactive: false }) : null;&#10;    const show = () =&gt; { if (val) val.set({ text: fmt(get()) }); };&#10;    const tx = x + 110, tw = w - 110;&#10;    const track = g.rect({ x: tx, y: y + 5, w: tw, h: 12, radius: 6, fill: '#1a1628', stroke: '#2f2850', strokeWidth: 1, cursor: 'ew-resize' });&#10;    const fill = g.rect({ x: tx, y: y + 5, w: tw * get(), h: 12, radius: 6, fill: ACC, interactive: false });&#10;    const set = ex =&gt; { const v = Math.max(0, Math.min(1, (ex - tx) / tw)); setv(v); refreshSliders(); sendP(); };&#10;    track.on('press', e =&gt; { e.stop(); set(e.x - panel.get('x')); });&#10;    track.on('drag', e =&gt; { e.stop(); set(e.x - panel.get('x')); });&#10;    sliders.push(() =&gt; { fill.set({ w: tw * get() }); show(); });&#10;    return y + 30;&#10;}&#10;&#10;function refreshSliders() { sliders.forEach(s =&gt; s()); }&#10;&#10;let panel = null, sure = false;&#10;// ---------- the dock: Properties and Layers down the right side, each folds in, the whole dock folds away ----------&#10;const DW = 520, CW = DW - 32;   // the dock's width and the width of what is in it&#10;function section(g, y, name, sub, open, fn) {   // a header that folds its section in and out&#10;    const h = g.group({ x: 0, y: y, cursor: 'pointer', tooltip: open ? 'Fold in' : 'Fold out' });&#10;    h.rect({ w: DW, h: 32, fill: '#1d1830' });&#10;    h.triangle(open ? { x1: 14, y1: 12, x2: 24, y2: 12, x3: 19, y3: 20, fill: '#b8b2d0', interactive: false }&#10;                    : { x1: 15, y1: 11, x2: 15, y2: 21, x3: 23, y3: 16, fill: '#b8b2d0', interactive: false });&#10;    h.text({ x: 34, y: 16, text: name, size: 13, baseline: 'middle', fill: ACC, interactive: false });&#10;    if (sub)&#10;        h.text({ x: 34 + name.length * 9 + 14, y: 16, text: sub, size: 12, baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;    h.on('click', e =&gt; { e.stop(); fn(); rebuild(); });&#10;    return y + 40;&#10;}&#10;&#10;function dockTab(g, x, open) {   // the little tab on the dock's edge that folds it away or brings it back&#10;    const t = g.group({ x: x, y: H / 2 - 48, cursor: 'pointer', tooltip: open ? 'Hide the panels' : 'Show the panels' });&#10;    t.rect({ w: 22, h: 96, radius: 6, fill: '#14121ff4', stroke: '#2f2850', strokeWidth: 1 });&#10;    t.text({ x: 11, y: 48, text: open ? '&gt;' : '&lt;', size: 20, align: 'center', baseline: 'middle', fill: ACC, interactive: false });&#10;    t.on('click', e =&gt; { e.stop(); state.dock = !open; rebuild(); });&#10;}&#10;&#10;function drawDock() {&#10;    sliders = [];&#10;    panel = null;&#10;    if (!state.dock) {&#10;        dockTab(layer, W - 22, false);&#10;        return;&#10;    }&#10;    panel = layer.group({ x: W - DW, y: 0 });&#10;    const bg = panel.rect({ w: DW, h: H, fill: '#14121ff4', stroke: '#2f2850', strokeWidth: 1, interactive: true });&#10;    dockTab(panel, -22, true);&#10;    const g = panel.group({ x: 0, y: -(state.dscroll || 0) });   // what is in it, scrolled by the wheel when it is too long&#10;    const it = selected();&#10;    let y = 0;&#10;    y = section(g, y, 'PROPERTIES', it ? itemName(it) : 'Scene', state.openP, () =&gt; state.openP = !state.openP);&#10;    if (state.openP)&#10;        y = drawProps(g, y, it);&#10;    y = section(g, y, 'LAYERS', 'top = front', state.openL, () =&gt; state.openL = !state.openL);&#10;    if (state.openL)&#10;        y = drawLayers(g, y, DW);&#10;    const most = Math.max(0, y + 20 - H);&#10;    if ((state.dscroll || 0) &gt; most) { state.dscroll = most; g.set({ y: -most }); }&#10;    bg.on('wheel', e =&gt; {&#10;        e.stop();&#10;        const s = Math.max(0, Math.min(most, (state.dscroll || 0) + (e.delta &gt; 0 ? -60 : 60)));&#10;        if (s !== state.dscroll) { state.dscroll = s; g.set({ y: -s }); }&#10;    });&#10;}&#10;&#10;function drawProps(panel, y, it) {   // what the selected element (or with none, the Scene) has to set; returns where it ends&#10;    const PW = DW;&#10;    if (state.bg &amp;&amp; state.edges) {   // what the edges show: straight ones (rectangles), round ones (circles), or all, coloured by kind&#10;        panel.text({ x: 16, y: y + 6, text: 'EDGES - green straight, pink round', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, EFILTERS, state.efilter, i =&gt; { state.efilter = i; sendAids(null); rebuild(); });&#10;        y = slider(panel, 16, y, PW - 32, 'Sensitivity', () =&gt; state.esens, v =&gt; { state.esens = v; sendAids(null); });&#10;        y = slider(panel, 16, y, PW - 32, 'Edge width', () =&gt; state.ewidth, v =&gt; { state.ewidth = v; sendAids(null); });&#10;        y += 8;&#10;    }&#10;    if (!it) {&#10;        panel.text({ x: 16, y: y + 6, text: 'BACKGROUND', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y += 18;&#10;        button(panel, 16, y, 150, 'Choose...', () =&gt; out(2), false);&#10;        if (state.bg)&#10;            button(panel, 172, y, 150, 'No background', () =&gt; setBackground(''), false);&#10;        panel.text({ x: 16, y: y + 46, text: state.bg ? state.bg.split(/[\\/]/).pop() : 'none: the Scene is see-through', size: 12, baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;        y += 66;&#10;        panel.text({ x: 16, y: y + 8, text: 'Click a board or a light to set it up.', size: 13, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        panel.text({ x: 16, y: y + 30, text: 'Double-click the picture for a new light.', size: 13, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        return y + 54;&#10;    } else if (it.type === 'board') {&#10;        panel.text({ x: 16, y: y + 6, text: 'BOARD - effect', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        const choose = fx =&gt; { it.fx = fx; picking = false; if (FXK[fx]) { it.rsize = FXK[fx][2]; it.rstr = FXK[fx][3]; } sendCode(); rebuild(); };&#10;        y = chips(panel, 16, y + 18, PW - 32, FXORDER.map(k =&gt; FX[k]), FXORDER.indexOf(it.fx), i =&gt; choose(FXORDER[i]));&#10;        panel.text({ x: 16, y: y + 6, text: 'MOVING PICTURE' + (state.bg ? '' : ' - needs a background'), size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, MOVEORDER.map(k =&gt; FX[k]), MOVEORDER.indexOf(it.fx), i =&gt; choose(MOVEORDER[i]));&#10;        if (it.fx === 13 || it.fx === 14 || it.fx === 15) {&#10;            panel.text({ x: 16, y: y + 6, text: 'light mode', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, MODES, it.mode || 0, i =&gt; { it.mode = i; sendCode(); rebuild(); });&#10;        }&#10;        if (it.fx === 14) {&#10;            button(panel, 16, y + 2, 190, picking ? 'Click the picture...' : 'Pick colour from picture', () =&gt; { picking = !picking; rebuild(); }, picking);&#10;            panel.text({ x: 216, y: y + 17, text: state.bg ? 'lights that colour up in the board' : 'needs a background',&#10;                         size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y += 40;&#10;        } else if (it.fx === 15) {&#10;            panel.text({ x: 16, y: y + 6, text: 'style' + (state.bg ? '' : ' (needs a background)'), size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, ESTYLES, it.estyle || 0, i =&gt; { it.estyle = i; sendCode(); rebuild(); });&#10;        } else if (FXSTYLES[it.fx]) {&#10;            panel.text({ x: 16, y: y + 6, text: 'kind', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, FXSTYLES[it.fx], it.style || 0, i =&gt; { it.style = i; sendCode(); rebuild(); });&#10;        } else if (it.fx &lt; 16) {&#10;            panel.text({ x: 16, y: y + 6, text: 'picture' + (state.bg ? '' : ' (needs a background)'), size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, it.fx === 10 ? PICS_RIPPLE : PICS, Math.min(it.pic || 0, it.fx === 10 ? 1 : 3),&#10;                      i =&gt; { it.pic = i; sendCode(); rebuild(); });&#10;        }&#10;        if (it.fx === 1) {&#10;            panel.text({ x: 16, y: y + 6, text: 'text (edit the list at the top of the Script)', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, TEXTS, it.text, i =&gt; { it.text = i; sendCode(); rebuild(); });&#10;        }&#10;        button(panel, 16, y + 2, 130, 'Full screen', () =&gt; { if (it.locked) return; it.pts = [[0, 0], [1, 0], [1, 1], [0, 1]]; sendP(); rebuild(); });&#10;        panel.text({ x: 162, y: y + 17, text: 'corners', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        button(panel, 218, y + 2, 76, 'Shape', () =&gt; { it.scaleCorners = false; rebuild(); }, !it.scaleCorners);&#10;        button(panel, 300, y + 2, 76, 'Scale', () =&gt; { it.scaleCorners = true; rebuild(); }, !!it.scaleCorners);&#10;        if (it.locked)&#10;            panel.text({ x: 390, y: y + 17, text: 'locked', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y += 40;&#10;        if (!MOVES(it.fx) || it.fx === 19)   // the moving picture has no colour of its own (Reflection: a tint)&#10;            y = swatches(panel, 16, y + 4, it);&#10;        y = slider(panel, 16, y, PW - 32, 'Speed', () =&gt; it.speed, v =&gt; it.speed = v);&#10;        if (!NOBRIGHT(it.fx))&#10;            y = aslider(panel, 16, y, PW - 32, it.fx === 9 ? 'Amount' : 'Brightness', it, 'bright', () =&gt; it.bright, v =&gt; it.bright = v);&#10;        if (FXK[it.fx]) {&#10;            const [n1, n2, d1, d2] = FXK[it.fx];&#10;            y = aslider(panel, 16, y, PW - 32, n1, it, 'k1', () =&gt; it.rsize === undefined ? d1 : it.rsize, v =&gt; it.rsize = v,&#10;                       it.fx === 16 ? v =&gt; Math.round(v * 360) + ' deg' : null);&#10;            if (n2)&#10;                y = aslider(panel, 16, y, PW - 32, n2, it, 'k2', () =&gt; it.rstr === undefined ? d2 : it.rstr, v =&gt; it.rstr = v);&#10;        }&#10;        if (it.fx === 13)&#10;            y = aslider(panel, 16, y, PW - 32, 'Glow size', it, 'k1', () =&gt; it.rsize === undefined ? 0.6 : it.rsize, v =&gt; it.rsize = v);&#10;        if (it.fx === 14) {&#10;            y = aslider(panel, 16, y, PW - 32, 'Tolerance', it, 'k1', () =&gt; it.rsize === undefined ? 0.6 : it.rsize, v =&gt; it.rsize = v);&#10;            y = aslider(panel, 16, y, PW - 32, 'Softness', it, 'k2', () =&gt; it.rstr === undefined ? 0.6 : it.rstr, v =&gt; it.rstr = v);&#10;        }&#10;        if (it.fx === 15) {&#10;            y = aslider(panel, 16, y, PW - 32, 'Sensitivity', it, 'k1', () =&gt; it.rsize === undefined ? 0.6 : it.rsize, v =&gt; it.rsize = v);&#10;            y = aslider(panel, 16, y, PW - 32, 'Glow width', it, 'k2', () =&gt; it.rstr === undefined ? 0.6 : it.rstr, v =&gt; it.rstr = v);&#10;        }&#10;        if (it.fx === 10) {&#10;            y = aslider(panel, 16, y, PW - 32, 'Circle size', it, 'k1', () =&gt; it.rsize === undefined ? 0.6 : it.rsize, v =&gt; it.rsize = v);&#10;            y = aslider(panel, 16, y, PW - 32, 'Strength', it, 'k2', () =&gt; it.rstr === undefined ? 0.6 : it.rstr, v =&gt; it.rstr = v);&#10;        }&#10;        y = transpRow(panel, y, it, PW);&#10;    } else {&#10;        panel.text({ x: 16, y: y + 6, text: 'LIGHT - mode', size: 12, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, MODES, it.mode, i =&gt; { it.mode = i; sendCode(); rebuild(); });&#10;        y = swatches(panel, 16, y + 4, it);&#10;        y = aslider(panel, 16, y, PW - 32, 'Size', it, 'size', () =&gt; it.size, v =&gt; { it.size = v; moveHandles(it); });&#10;        y = slider(panel, 16, y, PW - 32, 'Speed', () =&gt; it.speed, v =&gt; it.speed = v);&#10;        y = aslider(panel, 16, y, PW - 32, 'Strength', it, 'power', () =&gt; it.power, v =&gt; it.power = v);&#10;        y = transpRow(panel, y, it, PW);&#10;    }&#10;    panel.text({ x: 16, y: y + 8, text: 'drag corners (Ctrl: scale) - drag inside - Alt: no snap', size: 11, fill: '#5c5774', baseline: 'middle', interactive: false });&#10;    panel.text({ x: 16, y: y + 26, text: 'wheel = scale - Shift+wheel = rotate - right-click = delete', size: 11, fill: '#5c5774', baseline: 'middle', interactive: false });&#10;    return y + 44;&#10;}&#10;&#10;function setEdit(on) {&#10;    state.edit = !!on;&#10;    sendAids(null);&#10;    rebuild();&#10;}&#10;&#10;function setBackground(path) {&#10;    state.bg = path;&#10;    out(1, { image1: path });&#10;    sendCode();&#10;    sendAids(null);&#10;    rebuild();&#10;}&#10;&#10;function onInput(n, value) {&#10;    if (n === 3 &amp;&amp; typeof value === 'string' &amp;&amp; value.trim().length) {   // a colour code from a Text Input&#10;        const it = selected();&#10;        if (applyColour(it, value)) { hexTyping = null; sendCode(); rebuild(); }&#10;    }&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length)&#10;        setBackground(value);&#10;    if (n === 1)&#10;        setEdit(value === undefined ? !state.edit : (value === true || (typeof value === 'number' &amp;&amp; value &gt; 0.5) || value === 'on'));&#10;}&#10;&#10;function onStart() {&#10;    sentCode = '';&#10;    if (state.bg)&#10;        out(1, { image1: state.bg });&#10;    sendCode();&#10;    sendAids(null);&#10;    rebuild();&#10;}&#10;" inputs="3" outputs="2" live="1"/>
        </node>
        <node id="3" type="File" title="Background File" expanded="0" x="-1500.0" y="0.0" w="320.0" h="140.0">
          <state pickMode="0" triggerOnLoad="1"/>
        </node>
        <node id="4" type="widget.textinput" title="Colour Code" expanded="0" x="-1500.0" y="300.0" w="420.0" h="130.0">
          <state placeholder="#RRGGBBAA or 255, 128, 0" emitOnChange="1" textSize="18" sendLabel="Apply"/>
        </node>
      </nodes>
      <ui>
        <selection primary="0"/>
        <edgeSelection hasPrimary="0"/>
      </ui>
      <edges>
        <e fn="2" fp="20" tn="1" tp="6"/>
        <e fn="2" fp="21" tn="3" tp="1"/>
        <e fn="3" fp="4" tn="2" tp="1"/>
        <e fn="4" fp="3" tn="2" tp="2"/>
      </edges>
      <panel width="1920" height="1080" locked="1" zoom="1" performScale="1" gridSize="5" gridEnabled="0" toolbarExpanded="1" toolbarX="-1" toolbarY="-1" toolbarW="0" toolbarH="0" panelBgColour="FF000000" gridColour="0">
        <entry nodeId="1" x="0.0" y="0.0" w="1920.0" h="1080.0" z="2" auto="0" locked="1"/>
      </panel>
      <audioPreview loop="0" autoplay="1" gain="1.0"/>
    </marionietoworld.MNodes_State>
  </state>
</MNPreset>
