<?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="1793206993246" modifiedAt="1793206993246" 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="25">
        <node id="1" type="visual.gpucanvas" title="Cinemnode" expanded="0" x="0.0" y="0.0" w="1920.0" h="1080.0">
          <state pcount="58" speed="1.0" code="// Made by the Cinemnode Script: change the Script, not this.&#10;// LZ is 0, but the compiler cannot know it: loops stay loops instead of being unrolled, so the shader compiles faster&#10;#define LZ min(iFrame, 0)&#10;// the picture, read with no mipmap guess: works the same inside those loops on every graphics driver&#10;// your own shader with black as see-through: as bright as its brightest colour, so it lies over the picture as light does&#10;// Cinemnode (was Scene Kit): shared helpers and effects. The Script adds mainImage with every element.&#10;// a colour round the colour wheel&#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;&#10;// v8.2: the same with the board's corners fixed: the Script works the inverse out once (M), with the vanishing line's&#10;// side in its sign, so a pixel needs one matrix times a vector&#10;&#10;// ---------- effects for a sign: each gives a colour and how much of it covers ----------&#10;&#10;&#10;&#10;&#10;&#10;&#10;&#10;&#10;// ---------- lights ----------&#10;// mode: 0 on, 1 slow blink, 2 twinkle, 3 broken tube, 4 pulse, 5 strobe, 6 candle, 7 traffic light (its colour changes, see trafficCol),&#10;// 8 aircraft (a double flash now and then), 9 lens flare (on, with a flare drawn by fxFlare)&#10;&#10;&#10;&#10;// light added to what is drawn so far: C is the colour times its cover, A the cover&#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;&#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;&#10;&#10;// ---------- edit aids (only with a background in Image 1) ----------&#10;&#10;// how much of an edge the picture has here (Sobel), so windows, signs and lamps stand out to place things on&#10;&#10;// a round magnifier beside the point p (pixels): the background 4 times bigger, with a cross on p&#10;&#10;// ---------- v1.6 ----------&#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;&#10;// clouds drifting across the board, see-through between them, fading at its edges&#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;&#10;// a lit rectangle (cov: how much of the pixel is inside) with a glow round it, glow 0..1 its reach&#10;&#10;// the picture's colour round a spot (5 samples, so one odd pixel does not decide it)&#10;&#10;// light added where the picture has (nearly) the key colour: tol how near, soft how gently it fades&#10;&#10;// ---------- v1.7: edges that tell straight from round ----------&#10;// the picture's brightness gradient (Sobel), measured e pixels apart&#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;&#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;&#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;&#10;// ---------- Cinemnode v1.1: the picture itself moves (m: where in the board, 0..1 from its top left) ----------&#10;&#10;&#10;&#10;&#10;&#10;&#10;// ---------- Cinemnode v1.1: laid over the picture ----------&#10;// v5.6: snow, dust in the sunlight, fireflies, leaves, blossom and bubbles, made to look real: five depths, the near ones&#10;// bigger, faster and out of focus, each thing with its own shape, turn and way of moving (p: fc / R.y)&#10;&#10;&#10;&#10;&#10;&#10;// one layer of drops sliding down a window: they stick, then slip on, leaving a wet way of small beads where they wiped the mist&#10;// (p: fc / R.y, up is +y). xy: the way out from the middle of what is there (0..1), z: how much is drop, w: its size&#10;// small drops that sit still: a shower lays them, they slowly dry (gone where a running drop went)&#10;&#10;&#10;// ---------- v3.5: the sound on In A, and the DAW's beat (P28 its place in quarter notes, P29 playing, P30 the bar's ramp) ----------&#10;// a band of the spectrum (first row of iChannel0, low notes on the left), 0..1 across it&#10;// sens 0..1 (P31): how loud it must be before it moves anything, 0 only loud parts, 1 soft ones too&#10;// v6.8: how loud, from an Envelope Follower in the patch (P55 all, P56 low, P57 mid, P58 high: linear), as the Audio panel's meters: 0 at -60 dB, 1 at 0 dB&#10;&#10;// v5.3: for the music and stage effects. The spectrum at x (0..1, low notes left, spread the way we hear: more room for the lows)&#10;// the waveform at x (0..1), -1..1&#10;// the kick: on the DAW's beat while it plays, otherwise the bass&#10;// how loud it is now, 0..1&#10;&#10;&#10;&#10;&#10;float AU1, AU2, AU3, AU4, AU5, AU6;   // the sound and the beat (Audio panel), worked out at the top of sceneImage&#10;float MDW = 0.0;   // how much a MilkDrop window opened this pixel (no chequer there in Edit: the player shows)&#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;    vec2 qa = q * vec2(R.x / R.y, 1.0);   // q with square pixels, for the masks&#10;    C = mix(C, vec3(0.0), P24); A = mix(A, 1.0, P24);   // scene change: to black&#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 (less where a MilkDrop window lets the player show)&#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;        float a = mix(1.0, o.a, MDW);&#10;        o = vec4(mix(g, o.rgb, o.a / a), a);&#10;    }&#10;}&#10;" zones="" zonevalues="" labels=" " 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 v3.0 (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 an element for&#10;// its menu (make square, copy and paste its size, duplicate, front and back, hide, lock, delete). Undo and Redo&#10;// (toolbar) go back and forth through the last 80 changes.&#10;// Pictures as layers (Image in the toolbar): any file, PNG with see-through parts too, always over the effects. The&#10;// Script draws them, so they need no shader; their timeline plays on the Script's tick (Tick: 30 a second).&#10;// Masks (Mask in the toolbar): a shape of as many points as you like (double-click its edge for one more, right-click a&#10;// point to take it away; boards too: with 4 points a board is a picture in perspective, with more or fewer&#10;// it is a shape cut out of a straight box round it, turned as the board was) where the effects do not show: all of them, or only the ones you pick. Soft edge, inside or outside.&#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;// v7.6: Layers is pinned at the bottom of the dock (8 rows, its own scrollbar); its wheel redraws only its rows.&#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 = `// LZ is 0, but the compiler cannot know it: loops stay loops instead of being unrolled, so the shader compiles faster&#10;#define LZ min(iFrame, 0)&#10;// the picture, read with no mipmap guess: works the same inside those loops on every graphics driver&#10;vec4 tex0(vec2 uv) { return textureLod(iImage0, uv, 0.0); }&#10;// your own shader with black as see-through: as bright as its brightest colour, so it lies over the picture as light does&#10;vec4 seeThrough(vec4 c) { float a = clamp(max(c.r, max(c.g, c.b)), 0.0, 1.0); return vec4(c.rgb / max(a, 1e-4), a); }&#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;// a colour round the colour wheel&#10;vec3 hueCol(float h) { return clamp(abs(fract(h + vec3(0.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0) - 1.0, 0.0, 1.0); }&#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;// v8.2: the same with the board's corners fixed: the Script works the inverse out once (M), with the vanishing line's&#10;// side in its sign, so a pixel needs one matrix times a vector&#10;vec2 quadUVm(vec2 p, mat3 M)&#10;{&#10;    vec3 r = M * vec3(p, 1.0);&#10;    if (r.z &lt;= 0.0) return vec2(-10.0);   // beyond the vanishing line (or no shape at all)&#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, 7 traffic light (its colour changes, see trafficCol),&#10;// 8 aircraft (a double flash now and then), 9 lens flare (on, with a flare drawn by fxFlare)&#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;    if (mode == 8) { float s = fract(t * 0.6 + seed); return 1.0 - smoothstep(0.0, 0.04, s) + (1.0 - smoothstep(0.12, 0.16, s)) * step(0.1, s); }&#10;    return 1.0;&#10;}&#10;&#10;vec3 trafficCol(float t)   // red, then green, then amber, round again&#10;{&#10;    float s = mod(t, 8.0);&#10;    return s &lt; 3.5 ? vec3(1.0, 0.08, 0.05) : s &lt; 7.0 ? vec3(0.1, 1.0, 0.35) : vec3(1.0, 0.6, 0.05);&#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;    if (rays &lt; 0.5 &amp;&amp; l &gt; 1.45) return vec3(0.0);   // past its reach it adds nothing: skip the rest&#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 + LZ; 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 + LZ; 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(tex0(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 = tex0(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 + LZ; 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 (tex0(k).rgb + tex0(k + vec2(e.x, 0.0)).rgb + tex0(k - vec2(e.x, 0.0)).rgb +&#10;            tex0(k + vec2(0.0, e.y)).rgb + tex0(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 + LZ; 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 tex0(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, int style)   // 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;    if (style == 1) {   // a wet street: the lights stretched down in streaks, barely rippling&#10;        col = vec3(0.0);&#10;        for (int i = 0; i &lt; 8 + LZ; i++)&#10;            col += picAt(vec2(q.x + rx * 0.3, 1.0 - (top - dy * (0.6 + 0.08 * float(i)) - 0.002)));&#10;        col = col / 8.0 * mix(vec3(1.0), tint, 0.35) * 0.9;&#10;    }&#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;// v5.6: snow, dust in the sunlight, fireflies, leaves, blossom and bubbles, made to look real: five depths, the near ones&#10;// bigger, faster and out of focus, each thing with its own shape, turn and way of moving (p: fc / R.y)&#10;vec3 leafCol(float h)   // autumn: orange, yellow, red and brown&#10;{&#10;    return h &lt; 0.3 ? vec3(0.86, 0.38, 0.1) : h &lt; 0.55 ? vec3(0.92, 0.66, 0.16) : h &lt; 0.8 ? vec3(0.62, 0.14, 0.07) : vec3(0.42, 0.27, 0.12);&#10;}&#10;vec4 fxNature(vec2 p, float t, vec3 tint, float amount, float size, int style)&#10;{&#10;    vec3 add = vec3(0.0), col = tint;&#10;    float a = 0.0;&#10;    if (style == 1) {   // the shaft of sunlight the dust floats in, a soft haze&#10;        float sh = 0.5 + 0.5 * sin((p.x * 0.8 - p.y * 0.6) * 4.0 + 1.3 * vnoise(vec2(p.x * 2.0, t * 0.05)));&#10;        add += tint * 0.05 * smoothstep(0.4, 1.0, sh);&#10;    }&#10;    for (int L = 0; L &lt; 5 + LZ; L++) {&#10;        float z = (float(L) + 0.5) / 5.0;                         // 0 far .. 1 near&#10;        float sc = mix(16.0, 3.0, z) / (0.6 + 0.8 * size);        // cells across the height: few and big near by&#10;        vec2 v = style == 0 ? vec2(0.03, -mix(0.04, 0.22, z)) :  // how it goes (screen heights a second): snow drifts down&#10;                 style == 1 ? vec2(0.01, 0.006) :                  // dust hangs in the air&#10;                 style == 2 ? vec2(0.0, 0.01) :&#10;                 style == 3 ? vec2(0.06, -mix(0.06, 0.2, z)) :     // leaves fall, swinging&#10;                 style == 4 ? vec2(0.1, -mix(0.04, 0.14, z)) :     // blossom drifts on the wind&#10;                 vec2(0.0, mix(0.05, 0.22, z));                    // bubbles rise&#10;        vec2 g = (p - v * t) * sc + vec2(float(L) * 17.3, float(L) * 5.1);&#10;        vec2 id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + float(L) * 31.7);&#10;        float dens = style == 2 ? 0.45 : style == 3 ? 0.28 : style == 4 ? 0.4 : style == 8 ? 0.25 : 0.75;&#10;        if (h &gt; (0.1 + 0.9 * amount) * dens) continue;&#10;        float h2 = h21(id + 3.1), h3 = h21(id + 7.7), px = fwidth(g.x);&#10;        float blur = smoothstep(0.65, 1.0, z) * 0.5;               // the nearest are out of focus&#10;        vec2 o = (vec2(h2, h3) - 0.5) * 0.3;&#10;        float ph = t * (0.6 + 0.8 * h) + h * 40.0;&#10;        if (style == 0) o += 0.12 * vec2(sin(ph * 0.7), cos(ph * 0.5) * 0.5);&#10;        if (style == 1 || style == 2) o += 0.18 * (vec2(vnoise1(ph * 0.4), vnoise1(ph * 0.33 + 9.0)) - 0.5) * 2.0;&#10;        if (style == 3) o.x += 0.18 * sin(ph * 1.3);                // the swing of a falling leaf&#10;        if (style == 4) o += 0.1 * vec2(sin(ph), sin(ph * 1.7));&#10;        if (style == 8) o.x += 0.08 * sin(ph * 2.0);&#10;        vec2 d = f - o;&#10;        if (style == 0) {         // a soft flake&#10;            float r = (0.05 + 0.07 * h2) * (1.0 + blur);&#10;            float k = smoothstep(r + px, r * (0.3 - blur * 0.6), length(d)) * (1.0 - 0.45 * blur) * (0.55 + 0.45 * z);&#10;            if (k &gt; a) { a = k; col = tint; }&#10;        } else if (style == 1) {  // a mote of dust: only bright where the sunlight catches it&#10;            float r = 0.02 + 0.03 * h2 + blur * 0.08;&#10;            float sh = 0.5 + 0.5 * sin(((p.x * 0.8 - p.y * 0.6)) * 4.0 + 1.3 * vnoise(vec2(p.x * 2.0, t * 0.05)));&#10;            float glint = 0.5 + 0.5 * sin(ph * 3.0);&#10;            add += tint * smoothstep(r + px, 0.0, length(d)) * smoothstep(0.35, 0.95, sh) * (0.8 + 1.2 * glint) * (1.0 - 0.6 * blur);&#10;        } else if (style == 2) {  // a firefly: it lights up for a while, then is dark&#10;            float blink = smoothstep(0.55, 0.95, sin(t * (0.5 + 0.4 * h2) + h * 30.0));&#10;            float dd = length(d), r = 0.02 + 0.015 * h3;&#10;            vec3 fc = mix(vec3(0.8, 1.0, 0.35), tint, 0.35);&#10;            add += fc * blink * (1.5 * smoothstep(r + px, 0.0, dd) + 0.6 * exp(-dd / (0.06 + blur * 0.1)) ) * (0.6 + 0.6 * z);&#10;        } else if (style == 3 || style == 4) {   // a leaf or a petal, tumbling: its face turns to you and away&#10;            float an = ph * (style == 3 ? 0.9 : 1.3), flip = cos(ph * (style == 3 ? 1.7 : 2.3));&#10;            d = mat2(cos(an), -sin(an), sin(an), cos(an)) * d;&#10;            float r = style == 3 ? 0.3 : 0.15;&#10;            vec2 q = d / r;&#10;            q.y /= max(abs(flip), 0.12);&#10;            float inside;&#10;            vec3 pc;&#10;            if (style == 3) {     // a leaf: pointed at both ends, a darker vein down the middle&#10;                float w = 0.42 * pow(max(1.0 - q.x * q.x, 0.0), 0.7);&#10;                inside = smoothstep(0.03 + px / r, 0.0, abs(q.y) - w) * step(abs(q.x), 1.0);&#10;                pc = leafCol(h2) * mix(vec3(1.0), tint, 0.35) * (1.0 - 0.35 * smoothstep(0.05, 0.0, abs(q.y)) * step(0.0, flip));&#10;                pc *= flip &gt; 0.0 ? 1.0 : 0.7;                        // the back is duller&#10;                inside *= step(-1.25, q.x) * (q.x &lt; -1.0 ? smoothstep(0.03, 0.0, abs(q.y)) : 1.0);   // and a little stalk&#10;                inside = max(inside, smoothstep(0.04, 0.0, abs(q.y)) * step(q.x, -1.0) * step(-1.3, q.x));&#10;            } else {              // a petal: round, a little notch at its tip, white towards it, pink at its base&#10;                float e = length(q * vec2(1.0, 1.4)) - 1.0;&#10;                float notch = length(q - vec2(1.05, 0.0)) - 0.28;&#10;                inside = smoothstep(0.04 + px / r, 0.0, max(e, -notch));&#10;                pc = mix(mix(vec3(1.0, 0.72, 0.82), tint, 0.3), vec3(1.0, 0.97, 0.98), smoothstep(-0.8, 0.9, q.x)) * (flip &gt; 0.0 ? 1.0 : 0.85);&#10;            }&#10;            float k = inside * (1.0 - 0.4 * blur);&#10;            if (k &gt; a) { a = k; col = pc * (0.75 + 0.25 * z); }&#10;        } else {                  // a bubble: a thin skin catching colours, a window of light on it&#10;            float r = 0.08 + 0.1 * h2, dd = length(d);&#10;            float rim = smoothstep(r * 0.72, r, dd) * smoothstep(r + px, r - px, dd);&#10;            float spot = smoothstep(r * 0.22, 0.0, length(d - vec2(-0.4, 0.4) * r));&#10;            vec3 irid = mix(tint, 0.6 + 0.4 * hueCol(dd / r * 1.3 + h + t * 0.05), 0.5);&#10;            float k = max(rim * 0.7 + 0.05 * step(dd, r), spot);&#10;            if (k &gt; a) { a = k; col = mix(irid, vec3(1.0), spot); }&#10;        }&#10;    }&#10;    return style == 1 || style == 2 ? vec4(add, 1.0) : vec4(col, clamp(a, 0.0, 1.0));&#10;}&#10;vec4 fxParticles(vec2 p, float t, vec3 tint, float amount, float size, int style)&#10;{&#10;    if (style &lt;= 4 || style == 8) return fxNature(p, t, tint, amount, size, style);   // v5.6: these are new   // 0 snow, 1 dust, 2 fireflies, 3 leaves, 4 blossom, 5 hail, 6 sand, 7 stars (p: fc / R.y). 1, 2 and 7 add light; the rest cover&#10;    vec3 c = vec3(0.0), col = tint;&#10;    float a = 0.0;&#10;    for (int L = 0; L &lt; 3 + LZ; L++) {&#10;        float fl = float(L);&#10;        float sc = (style == 7 ? 14.0 : style == 5 ? 9.0 : 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) :&#10;                   style == 2 ? vec2(sin(t * 0.1 + fl) * 0.3, -t * 0.08) :&#10;                   style == 3 || style == 4 ? vec2(t * 0.35 + sin(t * 0.5 + fl) * 0.8, t * (style == 3 ? 0.7 : 0.45) * (1.0 + 0.3 * fl)) :&#10;                   style == 5 ? vec2(t * 0.3, t * (5.0 + 1.5 * fl)) :&#10;                   style == 6 ? vec2(-t * (4.0 + 1.5 * fl), sin(t * 0.7 + fl) * 0.25) : vec2(fl * 3.1, 0.0);&#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 || style == 3 || style == 4) 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;        vec2 d = f - o;&#10;        if (style == 3 || style == 4) {   // a leaf or a petal, turning and tumbling&#10;            float an = t * (1.0 + h) * 2.0 + h * 6.0;&#10;            d = mat2(cos(an), -sin(an), sin(an), cos(an)) * d;&#10;            d.y /= 0.35 + 0.4 * abs(sin(t * 2.0 + h * 10.0));&#10;            r *= style == 3 ? 1.6 : 1.1;&#10;        }&#10;        if (style == 6) { d.x /= 5.0; r *= 0.5; }&#10;        if (style == 5) r *= 0.5;&#10;        if (style == 7) r *= 0.35;&#10;        float dd = length(d);&#10;        float core = smoothstep(r, r * 0.3, dd);&#10;        float halo = style == 2 ? 0.06 * r / (dd * dd + 0.004) * 0.02 : style == 7 ? 0.0004 / (dd * dd + 0.0004) * 0.3 : 0.0;&#10;        float tw = style == 2 ? 0.5 + 0.5 * sin(t * 3.0 * (0.5 + h) + h * 40.0) :&#10;                   style == 1 ? 0.55 + 0.45 * sin(t * 2.0 + h * 30.0) :&#10;                   style == 7 ? 0.35 + 0.65 * pow(vnoise1(t * 3.0 + h * 50.0), 2.0) : 1.0;&#10;        vec3 pc = style == 3 ? mix(tint, tint * vec3(0.7, 0.5, 0.3), h21(id + 9.0)) :&#10;                  style == 4 ? mix(tint, vec3(1.0), 0.4 * h21(id + 9.0)) :&#10;                  style == 6 ? tint * (0.7 + 0.3 * h) : tint;&#10;        c += pc * (core + halo) * tw * (style == 1 ? 0.6 : 1.0);&#10;        if (core * tw &gt; a) { a = core * tw; col = pc; }&#10;    }&#10;    bool covers = style == 0 || style == 3 || style == 4 || style == 5 || style == 6;&#10;    return covers ? vec4(col, clamp(a * (style == 6 ? 0.7 : 1.0), 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, int style)   // flames rising from the bottom of the board (1: a rocket's jet, down from the top)&#10;{&#10;    if (style == 1) {&#10;        float down = m.y, w = abs(m.x - 0.5) * 2.0;&#10;        float len = 0.3 + 0.7 * height;&#10;        float n = fbm(vec2(m.x * 6.0, m.y * 4.0 - t * 9.0));&#10;        float body = smoothstep(0.45 + 0.4 * detail * n, 0.0, w / (0.25 + down * 0.9)) * smoothstep(len, len * 0.3, down + n * 0.15);&#10;        float core = smoothstep(0.35, 0.0, w / (0.12 + down * 0.3)) * smoothstep(len * 0.5, 0.0, down);&#10;        vec3 col = vec3(1.4, 0.55, 0.15) * body + vec3(0.8, 0.9, 1.4) * core * 1.5;&#10;        return vec4(col * mix(vec3(1.0), tint, 0.5) * (0.9 + 0.1 * sin(t * 60.0)), 1.0);&#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, int style)   // 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 (style == 1) {   // in the clouds: parts of them light up from inside, no bolt&#10;        float lit = smoothstep(0.4, 0.8, fbm(m * 3.0 + vec2(k * 3.7, k * 1.3)));&#10;        return vec4((pic * 2.2 * flash + tint * 0.5 * flash) * amp * lit, 1.0);&#10;    }&#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;// one layer of drops sliding down a window: they stick, then slip on, leaving a wet way of small beads where they wiped the mist&#10;// (p: fc / R.y, up is +y). xy: the way out from the middle of what is there (0..1), z: how much is drop, w: its size&#10;vec4 glassRun(vec2 p, float t, float sc, float seed, float amount, inout float clear)&#10;{&#10;    vec2 a = vec2(1.0, 3.0);                                  // a lane is three times as tall as wide&#10;    vec2 g = p * sc / a;&#10;    g.y += h11(floor(g.x) * 1.7 + seed) * 3.0;                // the lanes out of step&#10;    vec2 id = floor(g), f = (fract(g) - 0.5) * a;             // f in lane widths: x -0.5..0.5, y -1.5..1.5&#10;    float h = h21(id + seed);&#10;    float T = t * (0.07 + 0.08 * h) + h * 5.0, fr = fract(T), cyc = floor(T);&#10;    float h2 = h21(id + cyc * 1.31 + seed);&#10;    if (h2 &gt; 0.1 + 0.6 * amount) return vec4(0.0);&#10;    float y = 1.3 - 2.6 * (fr - sin(6.2832 * fr) / 6.2832);   // down in fits and starts&#10;    float bx = (h21(id + cyc + 3.1) - 0.5) * 0.45, wig = h * 20.0;&#10;    float x = bx + 0.06 * sin(y * 3.0 + wig);&#10;    float r = (0.13 + 0.09 * h2) * smoothstep(0.0, 0.06, fr) * smoothstep(1.0, 0.92, fr);&#10;    vec2 d = (f - vec2(x, y)) / max(r, 1e-3);&#10;    d.x *= 1.0 + 0.35 * max(d.y, 0.0);                        // round below, a little narrower on top&#10;    float drop = smoothstep(1.0, 0.8, length(d));&#10;    // behind it: the mist wiped away, and beads left on the glass&#10;    float above = f.y - y, xp = bx + 0.06 * sin(f.y * 3.0 + wig), dx = f.x - xp;&#10;    float way = step(0.0, above) * exp(-above * 0.9) * smoothstep(1.0, 0.92, fr);&#10;    clear = max(clear, smoothstep(r * 0.9, r * 0.35, abs(dx)) * way);&#10;    float k = floor(f.y * 8.0), bh = h21(vec2(id.x * 3.1 + k, id.y + cyc * 7.7 + seed));&#10;    float br = r * (0.18 + 0.22 * bh);&#10;    vec2 bd = vec2(dx + (bh - 0.5) * r * 0.4, (fract(f.y * 8.0) - 0.5) / 8.0) / max(br, 1e-4);&#10;    float bead = smoothstep(1.0, 0.7, length(bd)) * way * step(0.45, bh) * step(r * 1.5, above);&#10;    return drop &gt;= bead ? vec4(clamp(d, -1.0, 1.0), drop, r / sc) : vec4(bd, bead, br / sc);&#10;}&#10;// small drops that sit still: a shower lays them, they slowly dry (gone where a running drop went)&#10;vec4 glassBeads(vec2 p, float t, float sc, float seed, float amount)&#10;{&#10;    vec2 g = p * sc, id = floor(g), f = fract(g) - 0.5;&#10;    float h = h21(id + seed);&#10;    if (h &gt; 0.15 + 0.75 * amount) return vec4(0.0);&#10;    vec2 o = (vec2(h21(id + 1.3 + seed), h21(id + 2.7 + seed)) - 0.5) * 0.5;&#10;    float life = fract(t * 0.025 + h * 7.0);&#10;    float r = (0.14 + 0.2 * h21(id + 4.1 + seed)) * smoothstep(0.0, 0.01, life) * (1.0 - 0.5 * life) * smoothstep(1.0, 0.85, life);&#10;    vec2 d = (f - o) / max(r, 1e-3);&#10;    return vec4(d, smoothstep(1.0, 0.7, length(d)), r / sc);&#10;}&#10;vec4 fxGlass(vec2 p, vec2 uv, float t, vec3 tint, float drops, float mist, float asp)   // rain on a window: fine beads, drops that slide down and wipe a way through the mist (asp: R.y / R.x)&#10;{&#10;    float clear = 0.0;&#10;    vec4 s = glassRun(p, t, 20.0, 0.0, drops, clear);&#10;    vec4 b = glassRun(p + vec2(0.31, 0.0), t * 1.15, 30.0, 5.3, drops, clear); if (b.z &gt; s.z) s = b;&#10;    vec4 c = glassBeads(p, t, 80.0, 1.7, drops); c.z *= 1.0 - clear; if (c.z &gt; s.z) s = c;&#10;    vec4 e = glassBeads(p, t, 150.0, 8.1, drops); e.z *= 1.0 - clear; if (e.z &gt; s.z) s = e;&#10;    vec4 w = glassBeads(p, t, 260.0, 3.9, drops * 0.8); w.z *= 1.0 - clear; if (w.z &gt; s.z) s = w;&#10;    vec2 n = s.xy; float mask = s.z, l = min(length(n), 1.0);&#10;    // the glass: misted, a little pale, sharp again where a drop went&#10;    float fog = mist * (1.0 - 0.9 * clear);&#10;    vec3 blur = vec3(0.0);&#10;    for (int i = 0; i &lt; 12 + LZ; i++) {&#10;        float an = float(i) * 2.39996, rr = (0.002 + 0.012 * fog) * sqrt((float(i) + 0.5) / 12.0);&#10;        blur += picAt(uv + vec2(cos(an) * asp, sin(an)) * rr);&#10;    }&#10;    blur /= 12.0;&#10;    vec3 glass = mix(blur, blur * 0.85 + vec3(0.07), 0.5 * fog);&#10;    // a drop is a little lens: the picture in it sharp and upside down, a dark rim, a glint of the light&#10;    vec3 inDrop = picAt(uv + vec2(n.x * asp, -n.y) * s.w * 3.5) * (1.0 - 0.5 * smoothstep(0.55, 1.0, l));&#10;    float big = smoothstep(0.002, 0.009, s.w);   // the fine beads only darken and bend; bigger drops catch the light&#10;    inDrop += tint * big * (0.45 * smoothstep(0.3, 0.0, length(n - vec2(-0.3, 0.45))) + 0.15 * smoothstep(0.6, 0.95, l) * max(0.0, -n.y));&#10;    return vec4(mix(glass, inDrop, mask), max(mask, clamp(fog * 1.3, 0.0, 1.0)));&#10;}&#10;&#10;vec4 fxSparkle(vec2 fc, vec2 m, float t, vec3 tint, float amount, float size, float S, float bright, int style)   // glints that come and go where the water is bright (1: a moon's path down the middle)&#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 * (style == 1 ? 1.4 : 1.0)) 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;    float where = style == 1 ? exp(-pow((m.x - 0.5) / (0.06 + 0.25 * m.y), 2.0)) : smoothstep(0.12, 0.7, bright);&#10;    return vec4(tint * min(star, 3.0) * tw * where * 1.5, 1.0);&#10;}&#10;&#10;// ---------- v3.5: the sound on In A, and the DAW's beat (P28 its place in quarter notes, P29 playing, P30 the bar's ramp) ----------&#10;// a band of the spectrum (first row of iChannel0, low notes on the left), 0..1 across it&#10;float auSpec(float a, float b)&#10;{&#10;    float s = 0.0;&#10;    for (int i = 0; i &lt; 8 + LZ; i++)&#10;        s += textureLod(iChannel0, vec2(mix(a, b, (float(i) + 0.5) / 8.0), 0.25), 0.0).x;&#10;    return s / 8.0;&#10;}&#10;// sens 0..1 (P31): how loud it must be before it moves anything, 0 only loud parts, 1 soft ones too&#10;float auLift(float v, float sens)&#10;{&#10;    float lo = 0.7 - 0.6 * sens;&#10;    return clamp((v - lo) / (1.0 - lo), 0.0, 1.0);&#10;}&#10;// v6.8: how loud, from an Envelope Follower in the patch (P55 all, P56 low, P57 mid, P58 high: linear), as the Audio panel's meters: 0 at -60 dB, 1 at 0 dB&#10;float auDb(float v) { return clamp((20.0 * log(max(v, 1e-5)) / log(10.0) + 60.0) / 60.0, 0.0, 1.0); }&#10;&#10;// v5.3: for the music and stage effects. The spectrum at x (0..1, low notes left, spread the way we hear: more room for the lows)&#10;float auAt(float x) { return textureLod(iChannel0, vec2(0.003 + 0.6 * x * x, 0.25), 0.0).x; }&#10;// the waveform at x (0..1), -1..1&#10;float auWave(float x) { return textureLod(iChannel0, vec2(x, 0.75), 0.0).x * 2.0 - 1.0; }&#10;// the kick: on the DAW's beat while it plays, otherwise the bass&#10;float auKick() { return P29 &gt; 0.5 ? exp(-fract(P28) * 6.0) : auLift(auDb(P56), P31); }&#10;// how loud it is now, 0..1&#10;float auLevel() { return auLift(auDb(P55), P31); }&#10;&#10;// ==== on demand: each block below goes into the shader only when an element uses it (the Script picks them by name) ====&#10;&#10;// @@ fxCloudShadow&#10;vec4 fxCloudShadow(vec2 uv, vec2 m, float t, float dark, float size)   // shadows of clouds drifting over the land&#10;{&#10;    vec2 p = uv * vec2(1.78, 1.0) * (1.5 + 4.0 * (1.0 - size)) + vec2(t * 0.08, t * 0.02);&#10;    float n = smoothstep(0.35, 0.7, fbm(p));&#10;    return vec4(picAt(uv) * (1.0 - dark * 0.6 * n * edgeFade(m, 0.12)), 1.0);&#10;}&#10;&#10;// @@ fxDappled&#10;vec4 fxDappled(vec2 uv, vec2 m, float t, vec3 tint, float amt, float size)   // sun through leaves: bright patches that shift&#10;{&#10;    vec2 p = uv * vec2(1.78, 1.0) * (6.0 + 20.0 * (1.0 - size));&#10;    float n = vnoise(p + vec2(sin(t * 0.7), cos(t * 0.5)) * 0.6 + t * 0.1) * vnoise(p * 1.7 - t * 0.13 + 3.0);&#10;    float spot = smoothstep(0.2, 0.5, n);&#10;    vec3 c = picAt(uv) * (1.0 + amt * (spot * 1.4 - 0.3) * edgeFade(m, 0.12) * mix(vec3(1.0), tint, 0.5));&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxDayNight&#10;vec4 fxDayNight(vec2 uv, float night, float blue, vec3 tint)   // 0 day, 0.5 golden hour, 1 night (bright windows stay lit): animate it&#10;{&#10;    vec3 c = picAt(uv);&#10;    float l = lum(c);&#10;    vec3 golden = c * vec3(1.15, 0.95, 0.72);&#10;    vec3 dark = mix(vec3(l) * vec3(0.22, 0.3, 0.5 + 0.3 * blue), c, smoothstep(0.7, 0.95, l));&#10;    vec3 r = night &lt; 0.5 ? mix(c, golden, night * 2.0) : mix(golden, dark, night * 2.0 - 1.0);&#10;    return vec4(r * mix(vec3(1.0), tint, 0.25 * night), 1.0);&#10;}&#10;&#10;// @@ fxSwell&#10;vec4 fxSwell(vec2 uv, vec2 m, float t, float amt, float tilt)   // the sea's horizon rising, falling and tilting&#10;{&#10;    float y = (sin(t * 0.8) * 0.006 + sin(t * 1.3 + 1.0) * 0.003) * amt;&#10;    float r = sin(t * 0.6) * 0.006 * tilt;&#10;    return vec4(picAt(uv + vec2(0.0, y + r * (uv.x - 0.5)) * edgeFade(m, 0.08)), 1.0);&#10;}&#10;&#10;// @@ fxHandheld&#10;vec4 fxHandheld(vec2 uv, float t, float amt, float zoom)   // a camera held by hand: a little zoomed in so its edges never show&#10;{&#10;    vec2 sh = vec2(vnoise1(t * 0.7) - 0.5, vnoise1(t * 0.6 + 7.0) - 0.5) * 0.012 * amt;&#10;    float z = 1.0 - (0.015 + 0.03 * zoom) * max(amt, 0.3);&#10;    return vec4(picAt(vec2(0.5) + (uv - 0.5) * z + sh), 1.0);&#10;}&#10;&#10;// @@ fxFringe&#10;vec4 fxFringe(vec2 uv, float t, float amt, float wob)   // colour fringes towards the edges, as a cheap lens has&#10;{&#10;    vec2 d = (uv - 0.5) * 0.012 * amt * (1.0 + wob * 0.5 * sin(t * 1.5));&#10;    return vec4(picAt(uv + d).r, picAt(uv).g, picAt(uv - d).b, 1.0);&#10;}&#10;&#10;// @@ fxBloom&#10;vec4 fxBloom(vec2 uv, float t, vec3 tint, float amt, float size)   // the bright parts glow softly into what is round them&#10;{&#10;    vec3 c = picAt(uv), b = vec3(0.0);&#10;    float r = 0.004 + 0.02 * size;&#10;    for (int i = 0; i &lt; 12 + LZ; i++) {&#10;        float a = float(i) * 0.5236;&#10;        for (int j = 1; j &lt;= 2; j++)&#10;            b += max(picAt(uv + vec2(cos(a) / 1.78, sin(a)) * r * float(j)) - 0.6, 0.0);&#10;    }&#10;    return vec4(c + b / 24.0 * amt * 4.0 * mix(vec3(1.0), tint, 0.5), 1.0);&#10;}&#10;&#10;// @@ fxLightTrails&#10;vec4 fxLightTrails(vec2 m, float t, vec3 tint, float amount, float len, int style)   // cars' lights drawn out in streaks along the board&#10;{&#10;    vec3 c = vec3(0.0);&#10;    for (int L = 0; L &lt; 4 + LZ; L++) {&#10;        float fl = float(L), dir = L &lt; 2 ? 1.0 : -1.0;&#10;        float lane = exp(-pow((m.y - (0.2 + fl * 0.2)) / 0.025, 2.0));&#10;        float x = m.x * dir * 2.5 - t * (0.5 + 0.15 * fl);&#10;        float id = floor(x), f = fract(x);&#10;        if (h11(id + fl * 13.0) &gt; 0.2 + 0.8 * amount) continue;&#10;        float streak = smoothstep(0.0, 0.03, f) * smoothstep(0.1 + 0.8 * len, 0.0, f);&#10;        vec3 col = style == 0 ? (dir &gt; 0.0 ? vec3(1.0, 0.9, 0.75) : vec3(1.0, 0.12, 0.06)) : tint;&#10;        c += col * lane * streak * 1.6;&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxTV&#10;vec4 fxTV(vec2 m, float t, vec3 tint, float flick, float colour)   // a television's light on the walls of a room&#10;{&#10;    float k = floor(t * 3.0), h = h11(k), h2 = h11(k + 0.5);&#10;    float b = 0.5 + 0.5 * h + flick * 0.4 * (h11(floor(t * 20.0)) - 0.5);&#10;    vec3 c = mix(vec3(0.75, 0.85, 1.0), vec3(h, h2, 1.0 - h * 0.5), colour);&#10;    float soft = smoothstep(0.0, 0.3, min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y))) * 0.6 + 0.4;&#10;    return vec4(c * mix(vec3(1.0), tint, 0.5) * b * soft * 0.8, 1.0);&#10;}&#10;&#10;// @@ fxFog&#10;vec4 fxFog(vec2 m, float t, vec3 tint, float thick, float height, int style)   // 0 fog creeping along the ground, 1 a bank of mist&#10;{&#10;    float n = fbm(vec2(m.x * 3.0 - t * 0.15, m.y * 2.0)) * 0.6 + fbm(vec2(m.x * 7.0 + t * 0.1, m.y * 5.0)) * 0.4;&#10;    float lay = style == 0 ? smoothstep(1.0 - 0.9 * height, 1.0, m.y) : 1.0 - abs(m.y - 0.5) * 2.0 * (1.0 - 0.6 * height);&#10;    float sides = smoothstep(0.0, 0.15, m.x) * smoothstep(1.0, 0.85, m.x);&#10;    return vec4(tint, clamp(lay * (n * 1.4 - 0.2) * (0.4 + 0.9 * thick) * sides, 0.0, 1.0));&#10;}&#10;&#10;// @@ fxRainbow&#10;vec4 fxRainbow(vec2 m, float t, float strength, float width)   // a bow from the board's bottom corners, coming and going&#10;{&#10;    vec2 p = vec2(m.x - 0.5, 1.0 - m.y);&#10;    float band = (length(p) / 0.5 - 0.75) / (0.08 + 0.15 * width);&#10;    if (band &lt; 0.0 || band &gt; 1.0) return vec4(0.0);&#10;    vec3 c = clamp(abs(fract((1.0 - band) * 0.8 + vec3(0.0, 0.667, 0.333)) * 6.0 - 3.0) - 1.0, 0.0, 1.0);&#10;    float fade = sin(band * 3.1416) * (0.55 + 0.45 * sin(t * 0.3)) * smoothstep(0.0, 0.25, p.y);&#10;    return vec4(c * fade * strength * 0.7, 1.0);&#10;}&#10;&#10;// @@ fxShore&#10;vec4 fxShore(vec2 uv, vec2 m, float t, vec3 tint, float reach, float foam)   // waves running up the beach: the sea at the board's top, the sand at its bottom&#10;{&#10;    float cyc = t * 0.1, k = floor(cyc), ph = fract(cyc);&#10;    float run = ph &lt; 0.35 ? 1.0 - pow(1.0 - ph / 0.35, 2.0) : 1.0 - smoothstep(0.35, 1.0, ph);   // up quickly, back slowly&#10;    float most = 0.12 + reach * (0.55 + 0.25 * h11(k));&#10;    float wig = (fbm(vec2(m.x * 3.0 + k * 7.1, k)) - 0.5) * 0.12;   // the front is never straight&#10;    float front = 0.08 + (most - 0.08) * run + wig;&#10;    float d = front - m.y;   // above 0: under the water&#10;    float under = smoothstep(-0.004, 0.006, d), deep = smoothstep(0.0, 0.3, d);&#10;    vec2 bend = vec2(vnoise(m * vec2(20.0, 12.0) + t * 0.6), vnoise(m * vec2(20.0, 12.0) - t * 0.5 + 4.0)) - 0.5;&#10;    vec3 water = picAt(uv + bend * 0.006 * under) * mix(vec3(1.0), tint, 0.35 + 0.4 * deep) * (0.9 + 0.1 * deep);&#10;    float lace = smoothstep(0.5, 0.62, fbm(m * vec2(28.0, 16.0) + vec2(k * 3.0, t * 0.15))) * smoothstep(0.3, 0.6, fbm(m * vec2(9.0, 5.0) + k));&#10;    float foamAmt = clamp(smoothstep(0.014, 0.0, abs(d)) * 0.9 + lace * exp(-max(d, 0.0) / (0.03 + 0.1 * (1.0 - run))) * under * (0.4 + 0.8 * foam), 0.0, 1.0);&#10;    float wet = (1.0 - under) * smoothstep(most + wig + 0.01, most + wig - 0.05, m.y) * 0.22 * (0.3 + 0.7 * run) * (0.5 + 0.5 * fbm(m * vec2(14.0, 7.0)));   // sand the water just left&#10;    vec3 col = mix(water, vec3(0.96, 0.97, 1.0), foamAmt);&#10;    float a = max(under * (0.3 + 0.45 * deep), foamAmt);&#10;    float soft = smoothstep(0.0, 0.12, m.x) * smoothstep(1.0, 0.88, m.x) * smoothstep(0.0, 0.15, m.y);   // no hard board edges&#10;    if (a &lt; wet) return vec4(vec3(0.05, 0.04, 0.02), wet * soft);&#10;    return vec4(col, a * soft);&#10;}&#10;&#10;// @@ fxCaustics&#10;vec4 fxCaustics(vec2 m, float t, vec3 tint, float amt, float size)   // the net of light that water throws on a bottom or a wall&#10;{&#10;    vec2 p = m * (3.0 + 8.0 * (1.0 - size));&#10;    float c = 0.0;&#10;    for (int i = 0; i &lt; 2 + LZ; i++) {   // two nets drifting apart, their thin bright lines where the warped noise crosses its middle&#10;        float fi = float(i);&#10;        vec2 w = p * (1.0 + 0.6 * fi) + vec2(t * 0.25, -t * 0.18) * (fi * 2.0 - 1.0);&#10;        w += vec2(vnoise(w * 0.7 + t * 0.2), vnoise(w * 0.7 - t * 0.17 + 5.0)) * 1.6;&#10;        float n = abs(vnoise(w) - 0.5);&#10;        c += pow(1.0 - smoothstep(0.0, 0.07, n), 2.0) * (0.7 - 0.25 * fi);&#10;    }&#10;    return vec4(tint * c * amt * 1.4 * edgeFade(m, 0.1), 1.0);&#10;}&#10;&#10;// @@ fxBeacon&#10;vec4 fxBeacon(vec2 m, float t, vec3 tint, float width, float reach, int style)   // 0 a lighthouse's beam going round its middle, 1 a searchlight sweeping up from its bottom&#10;{&#10;    vec2 o = style == 0 ? vec2(0.5) : vec2(0.5, 1.0);&#10;    vec2 d = (m - o) * vec2(1.6, 1.0);&#10;    float ang = style == 0 ? t * 0.8 : -1.5708 + 0.7 * sin(t * 0.5);&#10;    float da = abs(mod(atan(d.y, d.x) - ang + 3.1416, 6.2832) - 3.1416);&#10;    float beam = smoothstep(0.04 + 0.2 * width, 0.0, da) * exp(-length(d) * (3.0 - 2.5 * reach));&#10;    return vec4(tint * (beam * 0.9 + exp(-length(d) * 40.0)), 1.0);&#10;}&#10;&#10;// @@ fxFrost&#10;vec4 fxFrost(vec2 uv, vec2 m, float t, vec3 tint, float grow, float blur)   // ice growing in from the window's edges: animate Grow&#10;{&#10;    float e = min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y));&#10;    float n = fbm(m * 12.0) * 0.5 + fbm(m * 40.0) * 0.3;&#10;    float L = grow * 0.55;&#10;    float ice = smoothstep(L + 0.02, L - 0.04, e + (n - 0.4) * 0.2);&#10;    float lines = pow(1.0 - abs(fract(n * 8.0) - 0.5) * 2.0, 6.0);&#10;    vec3 bl = vec3(0.0);&#10;    for (int i = 0; i &lt; 6 + LZ; i++) {&#10;        float a = float(i) * 1.0472;&#10;        bl += picAt(uv + vec2(cos(a) / 1.78, sin(a)) * 0.008 * blur);&#10;    }&#10;    vec3 c = mix(bl / 6.0, vec3(0.85, 0.92, 1.0) * mix(vec3(1.0), tint, 0.5), 0.35 + 0.4 * lines);&#10;    return vec4(c, ice);&#10;}&#10;&#10;// @@ fxDrips&#10;vec4 fxDrips(vec2 p, vec2 uv, float t, vec3 tint, float amount, float size)   // drops hitting a window, then running down a wandering way, smaller and smaller till gone (p: fc / R.y)&#10;{&#10;    float mask = 0.0;&#10;    vec2 n = vec2(0.0);&#10;    for (int i = 0; i &lt; 24 + LZ; i++) {&#10;        float fi = float(i);&#10;        if (fi &gt; 4.0 + 19.0 * amount) break;&#10;        float per = 4.0 + 4.0 * h11(fi * 3.7), cyc = t / per + h11(fi * 1.3), k = floor(cyc), ph = fract(cyc);&#10;        float h = h11(k * 7.9 + fi * 13.1);&#10;        vec2 s = vec2(0.02 + 1.74 * h, 0.35 + 0.65 * h11(k * 3.3 + fi));   // where it lands&#10;        float r0 = (0.012 + 0.03 * size) * (0.6 + 0.7 * h11(k + fi * 5.0));&#10;        float hit = smoothstep(0.0, 0.03, ph), slide = max(ph - 0.06, 0.0) / 0.94;&#10;        float fall = pow(slide, 1.3) * (0.3 + 0.4 * h11(fi + k * 2.1));   // how far down it has run&#10;        float wobble = (vnoise1(fall * 14.0 + h * 40.0) - 0.5) * 0.05 + (vnoise1(fall * 40.0 + h * 9.0) - 0.5) * 0.012;&#10;        vec2 head = vec2(s.x + wobble, s.y - fall);&#10;        float r = r0 * hit * (1.0 - 0.7 * slide) * smoothstep(1.0, 0.85, ph);&#10;        vec2 d = (p - head) / vec2(r, r * 1.2);&#10;        d.y -= 0.25 * smoothstep(0.0, 1.0, slide) * max(d.y, 0.0);   // a little tail upward while it runs&#10;        float drop = smoothstep(1.0, 0.75, length(d));&#10;        // the thin wet trail it leaves, along the way it went, drying behind it&#10;        float back = s.y - p.y;&#10;        if (back &gt; 0.0 &amp;&amp; back &lt; fall) {&#10;            float wx = s.x + (vnoise1(back * 14.0 + h * 40.0) - 0.5) * 0.05 + (vnoise1(back * 40.0 + h * 9.0) - 0.5) * 0.012;&#10;            float w = r0 * 0.4 * (1.0 - 0.5 * back / max(fall, 1e-3));&#10;            float tr = smoothstep(w, w * 0.3, abs(p.x - wx)) * 0.6 * (1.0 - 0.7 * slide) * smoothstep(0.0, 0.02, fall - back);&#10;            if (tr &gt; mask) { mask = tr; n = vec2((p.x - wx) / max(w, 1e-4) * 0.3, 0.0); }&#10;        }&#10;        if (drop &gt; mask) { mask = drop; n = d; }&#10;    }&#10;    vec3 c = picAt(uv - n * 0.03) * 1.05 + tint * pow(max(0.0, dot(normalize(n + 1e-4), vec2(-0.5, 0.85))), 6.0) * 0.6 * step(0.3, mask);&#10;    return vec4(c * (1.0 - 0.25 * smoothstep(0.6, 1.0, length(n)) * step(0.3, mask)), mask);&#10;}&#10;&#10;// @@ fxSweep&#10;vec4 fxSweep(vec2 m, float t, vec3 tint, float width, float often)   // headlights of a car going by, sweeping over a wall&#10;{&#10;    float per = 6.0 - 4.0 * often, ph = fract(t / per), h = h11(floor(t / per));&#10;    float pos = h &gt; 0.5 ? -0.4 + ph * 1.8 : 1.4 - ph * 1.8;&#10;    float d = (m.x - pos) / (0.08 + 0.3 * width);&#10;    return vec4(tint * exp(-d * d) * (0.7 + 0.3 * m.y), 1.0);&#10;}&#10;&#10;// @@ fxFlare&#10;vec3 fxFlare(vec2 q, vec2 src, float t, vec3 tint, float amt)   // a lens flare from a light: a glow, a streak and ghosts towards the middle&#10;{&#10;    vec2 asp = vec2(1.78, 1.0), d = (q - src) * asp;&#10;    float core = pow(0.02 / (length(d) + 0.02), 1.5);&#10;    float streak = 0.004 / (abs(d.y) + 0.004) * exp(-abs(d.x) * 3.0);&#10;    vec3 c = tint * (core + streak * 0.6);&#10;    vec2 axis = vec2(0.5) - src;&#10;    for (int i = 1; i &lt;= 4; i++) {&#10;        float fi = float(i);&#10;        vec2 gp = src + axis * (0.4 + fi * 0.45);&#10;        float r = 0.02 + 0.03 * mod(fi, 2.0);&#10;        c += mix(tint, vec3(0.4, 0.7, 1.0) * fi / 4.0, 0.5) * smoothstep(r, r * 0.6, length((q - gp) * asp)) * 0.15;&#10;    }&#10;    return c * amt * (0.9 + 0.1 * sin(t * 2.0));&#10;}&#10;&#10;// @@ fxShooting&#10;vec4 fxShooting(vec2 m, float t, vec3 tint, float often, float len)   // now and then a meteor streaks across&#10;{&#10;    vec3 c = vec3(0.0);&#10;    for (int i = 0; i &lt; 3 + LZ; i++) {&#10;        float fi = float(i), per = 3.0 + 6.0 * (1.0 - often) + fi;&#10;        float k = floor((t + fi * 1.7) / per), ph = fract((t + fi * 1.7) / per) * per;&#10;        if (ph &gt; 1.2) continue;&#10;        float h = h11(k * 3.1 + fi);&#10;        vec2 s = vec2(0.1 + 0.8 * h, 0.05 + 0.4 * h11(k + fi + 5.0));&#10;        vec2 dir = normalize(vec2(h11(k + 2.0) &gt; 0.5 ? 1.0 : -1.0, 0.45));&#10;        vec2 d = m - (s + dir * ph * 0.6);&#10;        float along = dot(d, -dir), across = abs(d.x * dir.y - d.y * dir.x);&#10;        float tr = step(0.0, along) * smoothstep(0.05 + 0.25 * len, 0.0, along) * smoothstep(0.004, 0.0, across) * smoothstep(1.2, 0.6, ph);&#10;        c += tint * (tr + exp(-length(d) * 120.0) * smoothstep(1.2, 0.8, ph)) * 1.5;&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxStarTrails&#10;vec4 fxStarTrails(vec2 q, vec2 ctr, float t, vec3 tint, float amount, float len)   // stars drawn out in arcs round the board's middle, turning&#10;{&#10;    vec2 d = (q - ctr) * vec2(1.78, 1.0);&#10;    float r = length(d), a = atan(d.y, d.x);&#10;    float ring = floor(r * 300.0), fr = fract(r * 300.0);&#10;    float h = h11(ring);&#10;    if (h &gt; 0.15 + 0.5 * amount) return vec4(0.0);&#10;    float arc = 0.2 + 2.5 * len, da = mod(a - h11(ring + 3.0) * 6.2832 - t * 0.05, 6.2832);&#10;    float on = step(da, arc) * (da / arc);&#10;    return vec4(tint * on * smoothstep(0.5, 0.1, abs(fr - 0.5)) * (0.5 + 0.5 * h11(ring + 7.0)), 1.0);&#10;}&#10;&#10;// @@ fxNebula&#10;vec4 fxNebula(vec2 m, float t, vec3 tint, float amt, float detail)   // coloured gas clouds, slowly turning and pulsing&#10;{&#10;    vec2 p = m * (2.0 + 3.0 * detail);&#10;    float n = fbm(p + vec2(fbm(p + t * 0.03), fbm(p + 3.0 - t * 0.02)) * 1.5);&#10;    vec3 c = mix(tint, tint.brg, smoothstep(0.3, 0.8, fbm(p * 1.7 + 5.0)));&#10;    float a = smoothstep(0.35, 0.85, n) * edgeFade(m, 0.2) * (0.85 + 0.15 * sin(t * 0.6));&#10;    return vec4(c * a * amt * 1.2, 1.0);&#10;}&#10;&#10;// @@ fxAurora&#10;vec4 fxAurora(vec2 m, float t, vec3 tint, float amt, float height)   // northern lights: curtains that wave, green below and purple above&#10;{&#10;    vec3 c = vec3(0.0);&#10;    for (int i = 0; i &lt; 3 + LZ; i++) {&#10;        float fi = float(i);&#10;        float y = 0.45 + 0.08 * fi + 0.12 * sin(m.x * 3.0 + t * 0.3 + fi * 2.0) + 0.05 * sin(m.x * 7.0 - t * 0.5 + fi);&#10;        float d = y - m.y;&#10;        float rays = 0.6 + 0.4 * vnoise(vec2(m.x * 60.0 + fi * 10.0, t * 0.5));&#10;        vec3 col = mix(mix(vec3(0.2, 1.0, 0.5), tint, 0.5), vec3(0.7, 0.2, 0.9), clamp(d * 3.0, 0.0, 1.0));&#10;        c += col * exp(-max(d, 0.0) / (0.08 + 0.3 * height)) * smoothstep(-0.005, 0.01, d) * rays * 0.6;&#10;    }&#10;    return vec4(c * amt * edgeFade(m, 0.15), 1.0);&#10;}&#10;&#10;// @@ fxPlanetBands&#10;vec4 fxPlanetBands(vec2 m, float t, vec3 tint, float strength, float bands)   // a planet in the board's circle, its cloud bands going round&#10;{&#10;    vec2 p = m * 2.0 - 1.0;&#10;    float r2 = dot(p, p);&#10;    if (r2 &gt; 1.0) return vec4(0.0);&#10;    float z = sqrt(1.0 - r2);&#10;    float lon = atan(p.x, z) / 3.1416 + t * 0.03;&#10;    float n = fbm(vec2(lon * 4.0 + t * 0.02, p.y * (4.0 + 10.0 * bands)));&#10;    float b = sin(p.y * (6.0 + 20.0 * bands) + n * 3.0) * 0.5 + 0.5;&#10;    vec3 c = mix(tint * 0.6, tint * 1.1, b) * (0.35 + 0.65 * z);&#10;    return vec4(c, strength * smoothstep(1.0, 0.97, r2));&#10;}&#10;&#10;// @@ fxGrain&#10;vec4 fxGrain(vec2 fc, float t, float amt, float size)   // film grain, new every frame&#10;{&#10;    float n = h21(floor(fc / (1.0 + 2.0 * size)) + floor(t * 24.0) * vec2(17.0, 31.0)) - 0.5;&#10;    return vec4(vec3(n &gt; 0.0 ? 1.0 : 0.0), abs(n) * amt * 0.5);&#10;}&#10;&#10;// @@ fxVignette&#10;vec4 fxVignette(vec2 m, float t, vec3 tint, float amt, float breathe)   // darker towards the edges, gently breathing&#10;{&#10;    float v = smoothstep(0.35, 0.75 - 0.05 * breathe * sin(t * 0.8), length(m - 0.5));&#10;    return vec4(tint * 0.1, v * amt);&#10;}&#10;&#10;// @@ fxOldFilm&#10;vec4 fxOldFilm(vec2 uv, vec2 m, float t, float amt, float scratches)   // old film: sepia, flicker, a jumping frame, scratches and dust&#10;{&#10;    float k = floor(t * 18.0);&#10;    vec3 c = picAt(uv + vec2(0.0, (h11(k) - 0.5) * 0.004 * amt));&#10;    c = mix(c, vec3(lum(c)) * vec3(1.07, 0.95, 0.78), amt) * (1.0 - amt * 0.12 * h11(k + 3.0));&#10;    for (int i = 0; i &lt; 3 + LZ; i++)&#10;        if (h11(k + float(i)) &lt; scratches)&#10;            c = mix(c, vec3(0.9), smoothstep(0.002, 0.0, abs(m.x - h11(k * 0.3 + float(i) * 7.0))) * 0.6);&#10;    c = mix(c, vec3(0.05), step(0.998, h21(floor(uv * vec2(400.0, 225.0)) + k)) * scratches);&#10;    return vec4(c * (1.0 - 0.4 * amt * smoothstep(0.4, 0.75, length(m - 0.5))), 1.0);&#10;}&#10;&#10;// ---------- v3.5: for a room with a fire, a candle and a view ----------&#10;// @@ fxFirelight&#10;vec4 fxFirelight(vec2 uv, vec2 m, float t, vec3 tint, float flick, float reach)   // the fire's warm light flickering over what is in the board, strongest at its bottom&#10;{&#10;    float f = 0.55 + 0.45 * (0.6 * vnoise1(t * 3.1) + 0.4 * vnoise1(t * 7.3 + 4.0));   // a fire's light, never quite still&#10;    f = mix(0.8, f, flick);&#10;    float fall = exp(-length((m - vec2(0.5, 1.0)) * vec2(1.2, 1.0)) * (4.0 - 3.4 * reach));&#10;    vec3 pic = picAt(uv);&#10;    float lit = fall * f * edgeFade(m, 0.2);&#10;    return vec4(pic * (1.0 + lit * 1.6 * tint) + tint * lit * 0.06, 1.0);&#10;}&#10;&#10;// @@ fxFlame&#10;vec4 fxFlame(vec2 uv, vec2 m, float t, float amt, float size)   // the flame in the picture itself licks and wavers: still at its foot, freest at its tip&#10;{&#10;    float k = 3.0 + 9.0 * (1.0 - size);&#10;    float up = 1.0 - m.y;   // 0 at the bottom of the board, 1 at its top&#10;    vec2 n = vec2(vnoise(vec2(m.x * k, m.y * k * 1.5 + t * 3.0)), vnoise(vec2(m.x * k + 7.0, m.y * k * 1.5 + t * 2.4))) - 0.5;&#10;    vec2 off = vec2(n.x * 1.4, -abs(n.y) * 1.2 - 0.25 * (0.5 + 0.5 * sin(t * 5.0 + m.x * 6.0))) * up * up * amt * 0.02;&#10;    float e = edgeFade(m, 0.12);&#10;    float bright = 1.0 + 0.12 * amt * (vnoise1(t * 6.0) - 0.5) * e;&#10;    return vec4(picAt(uv + vec2(off.x, -off.y) * e) * bright, 1.0);&#10;}&#10;&#10;// @@ fxEmbers&#10;vec4 fxEmbers(vec2 m, float t, vec3 tint, float amount, float height)   // glowing sparks rising from the bottom of the board, wavering, dying out&#10;{&#10;    vec3 c = vec3(0.0);&#10;    for (int L = 0; L &lt; 3 + LZ; L++) {&#10;        float fl = float(L);&#10;        float sc = 7.0 + fl * 5.0;&#10;        vec2 g = vec2(m.x * sc, (1.0 - m.y) * sc * 0.6 - t * (0.9 + 0.4 * fl));&#10;        vec2 id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + fl * 17.3);&#10;        if (h &gt; 0.1 + 0.6 * amount) continue;&#10;        vec2 o = (vec2(h21(id + 2.3), h21(id + 5.9)) - 0.5) * 0.6;&#10;        o.x += 0.25 * sin(t * (2.0 + 3.0 * h) + h * 30.0);&#10;        float life = 1.0 - smoothstep(0.1 + 0.85 * height, 0.15 + 0.9 * height, 1.0 - m.y + h * 0.15);   // they die out on the way up&#10;        float tw = 0.6 + 0.4 * sin(t * (8.0 + 6.0 * h) + h * 50.0);&#10;        float r = (0.07 + 0.05 * h) * (1.0 - fl * 0.2), dd = length(f - o);&#10;        c += tint * (smoothstep(r, r * 0.3, dd) * 1.6 + exp(-dd * dd * 40.0) * 0.5) * life * tw * (1.0 - fl * 0.25);&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxBirds&#10;vec4 fxBirds(vec2 m, float t, vec3 tint, float many, float size)   // small birds crossing the board now and then, flapping&#10;{&#10;    float a = 0.0;&#10;    for (int i = 0; i &lt; 6 + LZ; i++) {&#10;        float fi = float(i);&#10;        if (fi &gt; 1.0 + many * 5.0) break;&#10;        float per = 9.0 + 6.0 * h11(fi * 3.7);   // a pass every so many seconds, each bird its own&#10;        float ph = t / per + h11(fi * 9.1);&#10;        float k = floor(ph), u = fract(ph);&#10;        float dir = h11(k + fi * 5.3) &lt; 0.5 ? 1.0 : -1.0;&#10;        float y = 0.15 + 0.6 * h11(k * 1.7 + fi) + 0.05 * sin(u * 9.0 + fi);&#10;        vec2 p = vec2(dir &gt; 0.0 ? -0.1 + u * 1.2 : 1.1 - u * 1.2, y);&#10;        float s = (0.02 + 0.05 * size) * (0.7 + 0.5 * h11(fi * 2.1));&#10;        vec2 d = (m - p) / s;&#10;        d.x *= dir;&#10;        float flap = sin(t * (9.0 + 3.0 * h11(fi)) + fi * 2.0);&#10;        float wing = abs(d.x) &lt; 1.0 ? abs(d.y + 0.15 - abs(d.x) * 0.55 * flap) : 9.0;   // a V that beats up and down&#10;        a = max(a, smoothstep(0.22, 0.06, wing) * smoothstep(1.0, 0.8, abs(d.x)));&#10;    }&#10;    return vec4(tint * 0.18, a);&#10;}&#10;&#10;// @@ fxDrift&#10;vec4 fxDrift(vec2 uv, vec2 m, float t, float dir, float dist)   // clouds drifting slowly sideways, seamlessly&#10;{&#10;    float L = 0.02 + 0.12 * dist;&#10;    float sp = (dir - 0.5) * 2.0;   // left .. right&#10;    float ph = vnoise(uv * 4.0) * 0.3;&#10;    float p1 = fract(t * 0.05 + ph), p2 = fract(t * 0.05 + ph + 0.5);&#10;    float w = 1.0 - abs(2.0 * p1 - 1.0);&#10;    float e = edgeFade(m, 0.12);&#10;    vec2 d = vec2(sp * L * e, 0.0);&#10;    return vec4(mix(picAt(uv - d * p2), picAt(uv - d * p1), w), 1.0);&#10;}&#10;&#10;// @@ fxSunGlow&#10;vec4 fxSunGlow(vec2 m, float t, vec3 tint, float size, float pulse)   // a soft glow round the sun in the middle of the board, slowly breathing&#10;{&#10;    vec2 d = (m - 0.5) * 2.0;&#10;    float r = length(d);&#10;    float b = 1.0 + pulse * (0.25 * sin(t * 0.9) + 0.12 * sin(t * 2.3 + 1.0));&#10;    float glow = exp(-r * r * (6.0 - 4.5 * size)) * 0.55 + exp(-r * (14.0 - 8.0 * size)) * 0.6;&#10;    float sh = 0.85 + 0.15 * vnoise(vec2(atan(d.y, d.x) * 3.0, t * 0.6));   // a faint shimmer in it&#10;    return vec4(tint * glow * b * sh * smoothstep(1.0, 0.6, r), 1.0);&#10;}&#10;&#10;// ---------- v5.3: music and stage. They read the sound on In A (iChannel0) and the DAW's beat ----------&#10;// @@ fxSpectrum&#10;vec4 fxSpectrum(vec2 m, float t, vec3 tint, float bars, float height, int style)   // 0 bars, 1 LED blocks, 2 mirrored, 3 a line&#10;{&#10;    float y = style == 2 ? abs(m.y - 0.5) * 2.0 : 1.0 - m.y, hgt = 0.3 + 0.9 * height;&#10;    if (style == 3) {&#10;        float v = auLift(auAt(m.x), P31) * hgt, d = abs(y - v);&#10;        float a = smoothstep(0.012, 0.0, d) + 0.35 * smoothstep(0.07, 0.0, d) + step(y, v) * 0.18 * y / max(v, 1e-3);&#10;        return vec4(mix(tint, vec3(1.0), 0.3 * smoothstep(0.012, 0.0, d)), clamp(a, 0.0, 1.0));&#10;    }&#10;    float n = floor(8.0 + 56.0 * bars), i = floor(m.x * n), fx = fract(m.x * n);&#10;    float v = auLift(auAt((i + 0.5) / n), P31) * hgt;&#10;    float gap = smoothstep(0.06, 0.14, fx) * smoothstep(0.94, 0.86, fx);&#10;    float on = step(y, v) * gap;&#10;    vec3 c = mix(tint, vec3(1.0), 0.45 * smoothstep(0.4, 1.0, y));&#10;    if (style == 1) {&#10;        on *= step(0.25, fract(y * 20.0));&#10;        c = y &gt; 0.8 ? vec3(1.0, 0.2, 0.15) : y &gt; 0.6 ? vec3(1.0, 0.8, 0.2) : tint;&#10;        on += 0.08 * gap * step(0.25, fract(y * 20.0));   // the unlit blocks, faint&#10;    }&#10;    float glow = gap * smoothstep(v + 0.06, v, y) * step(v, y) * 0.35;   // a soft light over each bar&#10;    return vec4(c, clamp(on + glow, 0.0, 1.0));&#10;}&#10;&#10;// @@ fxScope&#10;vec4 fxScope(vec2 m, float t, vec3 tint, float gain, float glow, int style)   // the waveform, as an oscilloscope draws it: 0 a line, 1 a circle&#10;{&#10;    float g = 0.2 + 1.2 * gain, d;&#10;    if (style == 1) {&#10;        vec2 p = m - 0.5;&#10;        float a = atan(p.y, p.x) / 6.2832 + 0.5, r = 0.28 + 0.12 * g * auWave(a);&#10;        d = abs(length(p) - r);&#10;    } else {&#10;        d = 1.0;   // the nearest the line comes, from short pieces of it either side&#10;        vec2 pa = vec2(m.x - 0.05, 0.5 - 0.4 * g * auWave(m.x - 0.05));&#10;        for (int k = 1; k &lt;= 20 + LZ; k++) {&#10;            float x = m.x - 0.05 + float(k) * 0.005;&#10;            vec2 pb = vec2(x, 0.5 - 0.4 * g * auWave(x)), ab = pb - pa, ap = m - pa;&#10;            d = min(d, length(ap - ab * clamp(dot(ap, ab) / dot(ab, ab), 0.0, 1.0)));&#10;            pa = pb;&#10;        }&#10;    }&#10;    float a = smoothstep(0.006, 0.0, d) + (0.15 + 0.6 * glow) * exp(-d * (60.0 - 40.0 * glow));&#10;    return vec4(mix(tint, vec3(1.0), 0.5 * smoothstep(0.006, 0.0, d)), clamp(a, 0.0, 1.0));&#10;}&#10;&#10;// @@ fxLaser&#10;vec4 fxLaser(vec2 m, float t, vec3 tint, float beams, float sweep, int style)   // laser beams through haze, fanning from below: 0 a fan, 1 crossing from both corners, 2 in colours&#10;{&#10;    float n = floor(3.0 + 13.0 * beams), haze = 0.55 + 0.45 * fbm(m * 5.0 + vec2(t * 0.15, -t * 0.05));&#10;    float kick = 0.5 + 0.8 * auKick(), a = 0.0;&#10;    vec3 c = vec3(0.0);&#10;    for (int i = 0; i &lt; 16 + LZ; i++) {&#10;        float fi = float(i);&#10;        if (fi &gt;= n) break;&#10;        vec2 src = style == 1 ? vec2(mod(fi, 2.0) &lt; 1.0 ? 0.08 : 0.92, 1.0) : vec2(0.5, 1.0);&#10;        float side = style == 1 ? (mod(fi, 2.0) &lt; 1.0 ? 1.0 : -1.0) : 0.0;&#10;        float base = style == 1 ? side * (0.25 + 0.9 * (floor(fi / 2.0) + 0.5) / ceil(n / 2.0)) : (fi + 0.5) / n * 2.4 - 1.2;&#10;        float an = base + sweep * 0.6 * sin(t * 0.7 + fi * 0.9) * (style == 1 ? side : 1.0);&#10;        vec2 dir = vec2(sin(an), -cos(an)), p = m - src;&#10;        float along = dot(p, dir), across = abs(p.x * dir.y - p.y * dir.x);&#10;        float b = step(0.0, along) * (smoothstep(0.003, 0.0, across) + 0.35 * exp(-across * 160.0)) * exp(-along * 0.6);&#10;        vec3 col = style == 2 ? hueCol(fi / n + t * 0.03) : tint;&#10;        c += col * b; a += b;&#10;    }&#10;    float src = exp(-length((m - vec2(0.5, 1.0)) * vec2(1.0, 2.0)) * 40.0) * (style == 1 ? 0.0 : 1.0);&#10;    return vec4(c / max(a, 1e-4), clamp((a * haze + src) * kick, 0.0, 1.0));&#10;}&#10;&#10;// @@ fxHeads&#10;vec4 fxHeads(vec2 m, float t, vec3 tint, float lights, float swing, int style)   // moving heads along the top, their beams swinging through haze: 0 one colour, 1 in colours&#10;{&#10;    float n = floor(2.0 + 6.0 * lights), haze = 0.5 + 0.5 * fbm(m * 4.0 + vec2(t * 0.1, 0.0));&#10;    float lift = 0.6 + 0.6 * auLevel(), a = 0.0;&#10;    vec3 c = vec3(0.0);&#10;    for (int i = 0; i &lt; 8 + LZ; i++) {&#10;        float fi = float(i);&#10;        if (fi &gt;= n) break;&#10;        vec2 h = vec2((fi + 0.5) / n, 0.0);&#10;        float an = swing * 0.7 * sin(t * 0.6 + (mod(fi, 2.0) &lt; 1.0 ? 0.0 : 3.1416) + fi * 0.4);&#10;        vec2 dir = vec2(sin(an), cos(an)), p = m - h;&#10;        float along = dot(p, dir), across = abs(p.x * dir.y - p.y * dir.x), w = 0.012 + along * 0.14;&#10;        float b = step(0.0, along) * smoothstep(w, w * 0.4, across) * exp(-along * 1.1) * (0.6 + 0.4 * haze);&#10;        b += exp(-length(p) * 60.0);   // the lamp itself&#10;        vec3 col = style == 1 ? hueCol(fi / n + t * 0.02) : tint;&#10;        c += col * b; a += b;&#10;    }&#10;    return vec4(c / max(a, 1e-4), clamp(a * lift, 0.0, 1.0));&#10;}&#10;&#10;// @@ fxDisco&#10;vec4 fxDisco(vec2 m, float t, vec3 tint, float spots, float size, int style)   // the spots of a mirror ball going round over the walls: 0 white, 1 in colours&#10;{&#10;    float n = 6.0 + 18.0 * spots, a = 0.0;&#10;    vec3 c = vec3(0.0);&#10;    for (int L = 0; L &lt; 2 + LZ; L++) {&#10;        float fl = float(L), sc = n * (1.0 + 0.6 * fl);&#10;        vec2 g = vec2(m.x * sc + t * (0.6 + 0.3 * fl) * (1.0 - 0.5 * abs(m.y - 0.5)), m.y * sc * 0.7);&#10;        vec2 id = floor(g), f = fract(g) - 0.5;&#10;        float h = h21(id + fl * 9.0);&#10;        if (h &gt; 0.55) continue;&#10;        vec2 o = (vec2(h21(id + 3.1), h21(id + 7.7)) - 0.5) * 0.5;&#10;        float r = (0.08 + 0.25 * size) * (0.6 + 0.6 * h21(id + 1.9));&#10;        float s = smoothstep(r, r * 0.4, length((f - o) * vec2(1.0, 1.3))) * (0.6 + 0.4 * sin(t * 3.0 + h * 40.0));&#10;        c += (style == 1 ? hueCol(h * 3.0) : tint) * s; a += s;&#10;    }&#10;    return vec4(c / max(a, 1e-4), clamp(a * (0.7 + 0.5 * auLevel()), 0.0, 1.0));&#10;}&#10;&#10;// @@ fxStrobe&#10;vec4 fxStrobe(vec2 m, float t, vec3 tint, float rate, float len, int style)   // flashes: 0 on the beat (or the kick), 1 steady, 2 at random&#10;{&#10;    float on;&#10;    if (style == 0) {&#10;        float sub = exp2(floor(rate * 3.99));   // 1, 2, 4 or 8 a beat&#10;        on = P29 &gt; 0.5 ? step(fract(P28 * sub), 0.04 + 0.3 * len) : step(0.7, auKick());&#10;    } else if (style == 1)&#10;        on = step(fract(t * (1.0 + 10.0 * rate)), 0.05 + 0.4 * len);&#10;    else&#10;        on = step(h11(floor(t * 14.0)), 0.1 + 0.5 * rate) * step(fract(t * 14.0), 0.2 + 0.7 * len);&#10;    return vec4(tint, on);&#10;}&#10;&#10;// @@ fxBump&#10;vec4 fxBump(vec2 uv, vec2 m, vec2 ctr, float strength, int style, float soft)   // the picture bumps towards you: 0 on the kick, 1 with the level&#10;{&#10;    vec2 c = vec2(ctr.x, 1.0 - ctr.y);&#10;    float z = 1.0 - strength * 0.08 * (style == 0 ? auKick() : auLevel());&#10;    vec3 moved = picAt(c + (uv - c) * z);&#10;    return vec4(mix(picAt(uv), moved, soft &gt; 0.5 ? edgeFade(m, 0.15) : 1.0), 1.0);&#10;}&#10;&#10;// @@ fxWash&#10;vec4 fxWash(vec2 m, float t, vec3 tint, float strength, float change, int style)   // coloured stage light washing up (0) or down (1), breathing with the music&#10;{&#10;    float e = style == 0 ? 1.0 - m.y : m.y;&#10;    float g = exp(-e * 2.5) * (0.6 + 0.4 * vnoise(vec2(m.x * 3.0 + t * 0.15, t * 0.1)));&#10;    vec3 c = mix(tint, hueCol(t * 0.03 + m.x * 0.3), change);&#10;    return vec4(c, clamp(g * strength * 1.4 * (0.35 + 0.9 * auLevel()), 0.0, 1.0));&#10;}&#10;&#10;// @@ fxRings&#10;vec4 fxRings(vec2 m, float t, vec3 tint, float size, float thick)   // rings going out from the middle, one each beat (with no DAW playing: steady, as loud as the sound)&#10;{&#10;    float ph = P29 &gt; 0.5 ? fract(P28) : fract(t * 0.5), lv = P29 &gt; 0.5 ? 1.0 : 0.3 + 0.9 * auLevel(), a = 0.0;&#10;    float d = length(m - 0.5) * 2.0, w = 0.01 + 0.06 * thick;&#10;    for (int k = 0; k &lt; 3 + LZ; k++) {&#10;        float r = (ph + float(k)) / 3.0 * (0.4 + 0.8 * size) * 1.5;&#10;        a += smoothstep(w, 0.0, abs(d - r)) * (1.0 - (ph + float(k)) / 3.0);&#10;    }&#10;    return vec4(tint, clamp(a * lv, 0.0, 1.0));&#10;}&#10;&#10;// @@ fxMeter&#10;vec4 fxMeter(vec2 m, float t, vec3 tint, float segs, float glow, int style)   // a level meter of LEDs: 0 up, 1 across&#10;{&#10;    float n = floor(8.0 + 24.0 * segs), x = style == 0 ? 1.0 - m.y : m.x, w = style == 0 ? m.x : 1.0 - m.y;&#10;    float lv = auLevel(), i = floor(x * n), on = step(i / n, lv - 0.001);&#10;    float seg = step(0.2, fract(x * n)) * smoothstep(0.0, 0.05, w) * smoothstep(1.0, 0.95, w);&#10;    vec3 c = i / n &gt; 0.85 ? vec3(1.0, 0.2, 0.15) : i / n &gt; 0.65 ? vec3(1.0, 0.8, 0.2) : tint;&#10;    return vec4(c, clamp(seg * (0.1 + 0.9 * on) + on * glow * 0.3, 0.0, 1.0));&#10;}&#10;&#10;// ---------- v5.5: your own text, in a style. A template: the Script makes one of these for each text board, ----------&#10;// with TXT(p) its own lines (labelText, 1 on the letters). p in text units: the board is V across and up, S the letters' size&#10;// @@ fxTextN&#10;float txtBlur(vec2 p, float r)   // the letters, softened over r: turned a little differently at each pixel, so no copies show&#10;{&#10;    float g = 0.0, a0 = h21(floor(p * 7.0 / r * 8.0)) * 6.2832;&#10;    for (int i = 0; i &lt; 20 + LZ; i++) {&#10;        float a = a0 + float(i) * 2.39996, rr = r * pow((float(i) + 0.5) / 20.0, 0.75);&#10;        g += TXT(p + vec2(cos(a), sin(a)) * rr) * (1.2 - rr / r);&#10;    }&#10;    return g / 14.0;&#10;}&#10;vec4 fxTextN(vec2 m, float t, vec3 tint, float glow, float flick, int style, int motion, vec2 V, float S, float scroll)&#10;{&#10;    // 0 neon, 1 neon outline, 2 hologram, 3 LED dots, 4 light box, 5 halo letters, 6 LED screen&#10;    vec2 p = vec2(m.x, 1.0 - m.y) * V;&#10;    if (motion == 1) p.x += mod(t * S * 1.5, scroll);   // the line runs by from the right, over and over&#10;    float on = 1.0;&#10;    if (motion == 2) {   // switched on now and then: it stutters into light, then burns&#10;        float k = fract(t * 0.08);&#10;        on = k &lt; 0.12 ? step(0.5, h11(floor(t * 20.0))) * 0.8 + 0.2 * step(0.08, k) : 1.0;&#10;    }&#10;    // a tube that is going: now and then a stretch of letters stutters&#10;    on *= 1.0 - flick * 0.85 * step(0.9, h11(floor(t * 11.0) + floor(p.x / S * 1.4) * 7.3)) * step(0.6, h11(floor(t * 0.7) + floor(p.x / S * 1.4)));&#10;    float c = TXT(p);&#10;    if (style == 0 || style == 1) {   // neon: a white-hot tube, its colour round it&#10;        float g = txtBlur(p, S * (0.1 + 0.5 * glow));&#10;        if (style == 1) {&#10;            float d = txtBlur(p, S * 0.07);&#10;            c = smoothstep(0.08, 0.3, d) * (1.0 - smoothstep(0.3, 0.7, c));   // only the edge of each letter: the tube bent round it&#10;        }&#10;        vec3 col = mix(tint, vec3(1.0), 0.65) * c + tint * g * 2.0;&#10;        float a = clamp(c + g * (1.2 + glow), 0.0, 1.0) * on;&#10;        return vec4(col / max(c + g * 2.0, 1e-3), a);&#10;    }&#10;    if (style == 2) {   // a hologram: see-through, in lines, the colours a little apart, now and then torn&#10;        p.x += step(0.95, h11(floor(t * 13.0) + floor(p.y / S * 6.0))) * S * 0.15;&#10;        vec2 e = vec2(S * 0.025, 0.0);&#10;        vec3 rgb = vec3(TXT(p + e), c, TXT(p - e));&#10;        float lines = 0.65 + 0.35 * sin(p.y / S * 50.0 - t * 6.0);&#10;        float g = txtBlur(p, S * (0.1 + 0.4 * glow));&#10;        vec3 col = mix(tint, vec3(1.0), 0.3) * rgb * lines + tint * g;&#10;        float a = clamp(max(rgb.r, max(rgb.g, rgb.b)) * lines * 0.85 + g * 0.8, 0.0, 1.0) * on;&#10;        return vec4(col / max(a, 1e-3), a);&#10;    }&#10;    if (style == 3) {   // LED dots on a dark panel&#10;        float pitch = S / 8.0;&#10;        vec2 cell = (floor(p / pitch) + 0.5) * pitch;&#10;        float lit = step(0.5, TXT(cell)) * on, dot = smoothstep(0.42, 0.3, length(fract(p / pitch) - 0.5));&#10;        float g = txtBlur(p, S * 0.2 * glow) * on;&#10;        vec3 col = vec3(0.02) + tint * (dot * (0.07 + 1.1 * lit) + g * 0.5);&#10;        return vec4(col, 1.0);&#10;    }&#10;    if (style == 4) {   // a light box: the panel lit from inside, the letters in colour&#10;        float lit = 0.85 + 0.15 * (1.0 - length(m - 0.5)), frame = smoothstep(0.0, 0.015, min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y)) );&#10;        vec3 panel = vec3(0.97, 0.96, 0.92) * lit * (0.25 + 0.75 * on);&#10;        vec3 ink = lum(tint) &gt; 0.75 ? vec3(0.06) : tint * 0.85;   // white on white would not read: then black letters&#10;        vec3 col = mix(panel, ink * (0.3 + 0.7 * on), c);&#10;        return vec4(mix(vec3(0.05), col, frame), 1.0);&#10;    }&#10;    if (style == 5) {   // halo letters: dark letters standing off the wall, lit from behind&#10;        float g = txtBlur(p + vec2(0.0, S * 0.02), S * (0.15 + 0.6 * glow)) * on;&#10;        return vec4(mix(tint * 1.4, vec3(0.03), c), clamp(c + g * 1.6, 0.0, 1.0));&#10;    }&#10;    // 6: a video screen: red, green and blue in rows of little pixels, black between&#10;    float pitch = S / 16.0;&#10;    vec2 cell = (floor(p / pitch) + 0.5) * pitch, f = fract(p / pitch);&#10;    float lit = TXT(cell) * on, sub = floor(f.x * 3.0);&#10;    vec3 mask = vec3(sub == 0.0, sub == 1.0, sub == 2.0) * step(0.12, f.y) * step(f.y, 0.88);&#10;    float g = txtBlur(p, S * 0.15 * glow) * on;&#10;    vec3 col = vec3(0.015) + mix(tint, vec3(1.0), 0.2) * (lit * mask * 2.6 + g * 0.4);&#10;    return vec4(col, 1.0);&#10;}&#10;&#10;// ---------- v5.7: film look and style ----------&#10;// @@ fxLensFlare&#10;vec4 fxLensFlare(vec2 m, float t, vec3 tint, float size, float ghosts, int style, float asp)   // a bright light in the middle of the board flaring in the lens: 0 round, 1 anamorphic (a long blue streak)&#10;{&#10;    vec2 d = (m - 0.5) * vec2(asp, 1.0);&#10;    float r = length(d), s = 0.2 + 0.8 * size;&#10;    float core = exp(-r / (0.02 * s)) * 1.5 + exp(-r / (0.12 * s)) * 0.5;&#10;    float an = atan(d.y, d.x);&#10;    float rays = pow(max(0.0, sin(an * 6.0 + t * 0.1)), 24.0) * exp(-r / (0.3 * s)) * 0.5;&#10;    vec3 c = tint * (core + rays);&#10;    if (style == 1) {&#10;        float streak = exp(-abs(d.y) / (0.004 * s)) * exp(-abs(d.x) / (0.9 * s));&#10;        c += vec3(0.35, 0.6, 1.0) * streak * 1.2;&#10;    }&#10;    for (int i = 0; i &lt; 5 + LZ; i++) {   // ghosts: soft coloured discs strung out from the light, across the lens&#10;        float fi = float(i);&#10;        vec2 gc = vec2(-0.75, 0.45) * (0.12 + 0.17 * fi) * (0.6 + 0.6 * s);&#10;        float rad = (0.015 + 0.04 * h11(fi * 3.1)) * s, gd = length(d - gc);&#10;        float disc = smoothstep(rad, rad * 0.6, gd) * 0.5 + smoothstep(rad * 1.05, rad * 0.95, gd) * smoothstep(rad * 0.85, rad * 0.95, gd);&#10;        c += mix(tint, hueCol(0.5 + fi * 0.17), 0.6) * disc * 0.18 * ghosts;&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxLightLeak&#10;vec4 fxLightLeak(vec2 m, float t, vec3 tint, float strength, float drift, int style)   // light leaking into the camera: warm glows from the edges, slowly moving&#10;{&#10;    float e = min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y));&#10;    vec2 p = m * 1.6 + vec2(t * 0.03 * (0.3 + drift), -t * 0.02);&#10;    float n = fbm(p * 1.3) * fbm(p * 0.7 + 4.0);&#10;    float a = smoothstep(0.15, 0.6, n) * (0.4 + 0.6 * smoothstep(0.45, 0.0, e));&#10;    vec3 c = style == 1 ? hueCol(n * 1.5 + t * 0.02 + m.x * 0.3) : mix(vec3(1.0, 0.45, 0.15), vec3(1.0, 0.85, 0.5), n) * mix(vec3(1.0), tint, 0.4);&#10;    return vec4(c * a * strength * 1.6, 1.0);&#10;}&#10;&#10;// @@ fxCRT&#10;vec4 fxCRT(vec2 uv, vec2 m, float t, vec2 ctr, float strength, float curve, float asp)   // an old TV screen: bent glass, lines, red green and blue, a little flicker&#10;{&#10;    vec2 c = vec2(ctr.x, 1.0 - ctr.y), d = uv - c;&#10;    float bend = curve * 0.35 * dot(d * vec2(asp, 1.0), d * vec2(asp, 1.0));&#10;    vec2 u = c + d * (1.0 + bend);&#10;    vec3 col = vec3(picAt(u + vec2(0.0012 * strength, 0.0)).r, picAt(u).g, picAt(u - vec2(0.0012 * strength, 0.0)).b);&#10;    float y = u.y * 270.0, line = 0.65 + 0.35 * sin(y * 6.2832);&#10;    float px = floor(u.x * 640.0 * asp), sub = mod(px, 3.0);&#10;    vec3 mask = mix(vec3(1.0), vec3(sub == 0.0 ? 1.3 : 0.75, sub == 1.0 ? 1.3 : 0.75, sub == 2.0 ? 1.3 : 0.75), 0.6);&#10;    vec3 crt = col * mix(vec3(1.0), line * mask, strength) * (0.96 + 0.04 * sin(t * 50.0)) * 1.15;&#10;    float vig = smoothstep(0.0, 0.08, min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y)));&#10;    return vec4(crt * mix(1.0, vig, curve), 1.0);&#10;}&#10;&#10;// @@ fxPixelate&#10;vec4 fxPixelate(vec2 uv, float block, float levels, int style, float asp)   // the picture in blocks (0), halftone dots (1) or round tiles (2), with fewer colours&#10;{&#10;    float n = mix(160.0, 18.0, block);   // blocks across the height&#10;    vec2 g = uv * vec2(n * asp, n), id = floor(g), f = fract(g) - 0.5;&#10;    vec3 c = picAt((id + 0.5) / vec2(n * asp, n));&#10;    float lv = floor(mix(32.0, 3.0, levels));&#10;    c = floor(c * lv + 0.5) / lv;&#10;    if (style == 1) {   // halftone: a dot of its colour as big as the cell is bright, on black (a dark picture stays dark)&#10;        float k = lum(c), r = sqrt(k) * 0.68;&#10;        float dotm = smoothstep(r, r - 0.08, length(f));&#10;        return vec4(c / max(k, 0.25) * 0.8 * dotm, 1.0);&#10;    }&#10;    if (style == 2) {&#10;        float dotm = smoothstep(0.48, 0.42, length(f));&#10;        return vec4(c * dotm, 1.0);&#10;    }&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxKaleido&#10;vec4 fxKaleido(vec2 uv, vec2 m, float t, vec2 ctr, float segs, float turn, int style, float asp)   // the picture mirrored: a kaleidoscope round the middle (0), left onto right (1), top onto bottom (2)&#10;{&#10;    vec2 c = vec2(ctr.x, 1.0 - ctr.y), d = (uv - c) * vec2(asp, 1.0);&#10;    if (style == 1) d.x = -abs(d.x);&#10;    else if (style == 2) d.y = abs(d.y);&#10;    else {&#10;        float n = floor(3.0 + 9.0 * segs), w = 3.14159 / n;&#10;        float an = atan(d.y, d.x) + t * turn * 0.2, r = length(d);&#10;        an = mod(an, 2.0 * w);&#10;        an = abs(an - w);&#10;        d = vec2(cos(an), sin(an)) * r;&#10;    }&#10;    return vec4(picAt(c + d / vec2(asp, 1.0)), 1.0);&#10;}&#10;&#10;// ---------- v5.9 ----------&#10;// @@ fxCopy&#10;vec4 fxCopy(vec2 uv, vec2 ctr, vec2 src, float size, float turn, int style, float asp)   // a piece of the picture from somewhere else (src), shown in the board: 0 as it is, 1 mirrored, 2 upside down&#10;{&#10;    vec2 c = vec2(ctr.x, 1.0 - ctr.y), s = vec2(src.x, 1.0 - src.y);&#10;    vec2 d = (uv - c) * vec2(asp, 1.0) / exp2((size - 0.5) * 2.0);   // 0.5: as big as it is; up to twice, down to half&#10;    float a = (turn - 0.5) * 6.2832;&#10;    d = mat2(cos(a), -sin(a), sin(a), cos(a)) * d;&#10;    if (style == 1) d.x = -d.x;&#10;    if (style == 2) d.y = -d.y;&#10;    return vec4(picAt(s + d / vec2(asp, 1.0)), 1.0);&#10;}&#10;&#10;// @@ fxBlinds&#10;vec4 fxBlinds(vec2 uv, vec2 m, float t, vec3 tint, float slats, float soft, int style)   // v8.5: light through venetian blinds, striped across a wall (in the board's perspective), stirring a little&#10;{&#10;    float x = style == 1 ? m.x : style == 2 ? m.y + (m.x - 0.5) * 0.6 : m.y;   // across, up and down, or slanting&#10;    float n = 6.0 + 22.0 * slats;&#10;    float sway = 0.012 * sin(t * 0.6) + 0.006 * sin(t * 1.7 + 1.0);   // the blinds move in a draught&#10;    float f = fract((x + sway) * n);&#10;    float w = 0.05 + 0.3 * soft, open = 0.55;&#10;    float lit = smoothstep(0.0, w, f) * (1.0 - smoothstep(open - w, open, f));&#10;    lit *= 0.9 + 0.1 * vnoise(vec2(t * 0.4, x * 3.0));&#10;    float e = edgeFade(m, 0.06 + 0.12 * soft);&#10;    vec3 c = picAt(uv);&#10;    return vec4(c * mix(vec3(1.0), 0.42 + lit * 1.5 * mix(vec3(1.0), tint, 0.6), e), 1.0);&#10;}&#10;&#10;// @@ fxTrain&#10;vec4 fxTrain(vec2 uv, vec2 m, float t, vec3 tint, float often, float bright, int style)   // v8.5: now and then a train passes: its lit windows sweep across the wall&#10;{&#10;    float per = 16.0 - 12.0 * often, k = floor(t / per), u = t - k * per;&#10;    float dur = 3.0 + 2.0 * h11(k * 3.1);&#10;    float on = smoothstep(0.0, 0.4, u) * (1.0 - smoothstep(dur - 0.5, dur, u));&#10;    float x = style == 1 ? 1.0 - m.x : m.x;&#10;    float ph = x * 5.0 - u * 9.0 + h11(k) * 10.0;   // the windows, rushing past&#10;    float car = fract(ph / 6.0);   // a dark gap between the carriages&#10;    float win = smoothstep(0.08, 0.2, fract(ph)) * (1.0 - smoothstep(0.62, 0.76, fract(ph)));&#10;    win *= smoothstep(0.02, 0.06, car) * (1.0 - smoothstep(0.92, 0.96, car));&#10;    win *= 0.6 + 0.4 * h11(floor(ph) + k * 7.0);   // some windows brighter than others&#10;    float band = smoothstep(0.15, 0.35, m.y) * (1.0 - smoothstep(0.6, 0.85, m.y));   // the windows' height on the wall&#10;    float flick = 0.85 + 0.15 * sin(t * 47.0) * sin(t * 13.0);&#10;    float L = (win * band * 2.0 + 0.18) * on * flick * bright * edgeFade(m, 0.08);&#10;    return vec4(picAt(uv) * (1.0 + L * 1.8 * mix(vec3(1.0), tint, 0.7)), 1.0);&#10;}&#10;&#10;// @@ fxMoonlight&#10;vec4 fxMoonlight(vec2 uv, vec2 m, float t, vec3 tint, float dark, float size)   // v8.5: moonlight that comes and goes as clouds drift past the moon&#10;{&#10;    vec2 p = vec2(t * 0.11, t * 0.02);   // the clouds before the moon, the same for the whole picture&#10;    float cl = smoothstep(0.35, 0.7, fbm(p * (1.0 + 2.0 * (1.0 - size)) + uv * 0.25));&#10;    float light = 1.0 - cl;&#10;    vec3 c = picAt(uv);&#10;    vec3 moon = mix(vec3(0.78, 0.88, 1.12), tint, 0.4);&#10;    vec3 g = c * mix(vec3(1.0 - dark * 0.7), moon * (1.0 + 0.3 * dark), light);&#10;    return vec4(mix(c, g, edgeFade(m, 0.1)), 1.0);&#10;}&#10;&#10;// @@ fxDropRings&#10;vec4 fxDropRings(vec2 uv, vec2 m, float t, vec3 tint, float drops, float size, int style)   // v8.5: raindrops landing on a puddle or a street: rings that spread and fade&#10;{&#10;    float n = 4.0 + 10.0 * drops;&#10;    vec2 g = m * vec2(n, n * 1.4);&#10;    vec2 id0 = floor(g), grad = vec2(0.0);&#10;    float h = 0.0;&#10;    for (int j = -1; j &lt;= 1; j++)&#10;        for (int i = -1; i &lt;= 1; i++) {&#10;            vec2 id = id0 + vec2(float(i), float(j));&#10;            float r1 = h21(id), r2 = h21(id + 17.3);&#10;            vec2 c = id + 0.15 + 0.7 * vec2(r1, r2);&#10;            float per = 1.6 + 2.4 * r1, k = floor(t / per + r2), u = fract(t / per + r2) * 1.6;   // a drop now and then, not always in the same place&#10;            if (u &gt; 1.0 || h21(id + k * 3.7) &gt; 0.25 + 0.5 * drops) continue;&#10;            c = id + 0.15 + 0.7 * vec2(h21(id + k), h21(id + k + 9.1));&#10;            float rad = u * (0.5 + 1.0 * size);&#10;            vec2 d = g - c;&#10;            float l = length(d);&#10;            float ring = exp(-pow((l - rad) * 9.0, 2.0)) * (1.0 - u) * (1.0 - u) * sin((l - rad) * 30.0);&#10;            h += ring;&#10;            grad += ring * d / max(l, 1e-3);&#10;        }&#10;    float e = edgeFade(m, 0.05);&#10;    vec3 c = style == 0 ? picAt(uv + grad * 0.009 * e) + max(h, 0.0) * 0.3 * tint * e : picAt(uv) + max(h, 0.0) * 0.9 * tint * e;&#10;    return vec4(c, 1.0);&#10;}&#10;&#10;// @@ fxSnowstorm&#10;vec4 fxSnowstorm(vec2 p, vec2 m, float t, vec3 tint, float amount, float wind)   // v8.5: snow driven by gusts of wind, flakes near and far, a white haze in the strongest gusts (p: fc / R.y)&#10;{&#10;    float gust = 0.6 + 0.4 * sin(t * 0.33) + 0.25 * sin(t * 1.1 + 2.0);&#10;    float wnd = wind * gust * 1.6;&#10;    float a = 0.0;&#10;    for (int L = 0; L &lt; 4 + LZ; L++) {&#10;        float fl = float(L), sc = 11.0 + fl * 13.0;   // the near layer first: big, fast&#10;        float fall = 0.45 - fl * 0.07;&#10;        vec2 q = p * sc + vec2(-t * wnd * (1.0 - fl * 0.15), t * fall) * sc;&#10;        q.x += sin(q.y * 0.5 + t) * 0.3;&#10;        vec2 id = floor(q), f = fract(q) - 0.5;&#10;        if (h21(id + fl * 7.1) &gt; 0.15 + 0.75 * amount) continue;&#10;        vec2 o = (vec2(h21(id + 3.1), h21(id + 5.7)) - 0.5) * 0.6 + 0.12 * vec2(sin(t * 2.0 + h21(id) * 6.0), cos(t * 1.7 + h21(id) * 5.0));&#10;        vec2 d = f - o;&#10;        d.x /= 1.0 + wnd * (1.2 - fl * 0.3);   // smeared along the wind&#10;        float r = (0.05 + 0.05 * h21(id + 9.0)) * (fl &lt; 0.5 ? 1.4 : 1.0);&#10;        a += smoothstep(r, r * (fl &lt; 0.5 ? 0.1 : 0.4), length(d)) * (1.0 - fl * 0.18);&#10;    }&#10;    float haze = smoothstep(0.4, 0.9, fbm(p * 2.0 + vec2(-t * wnd * 0.6, t * 0.1))) * 0.35 * amount * gust;&#10;    float e = edgeFade(m, 0.1);&#10;    return vec4(mix(vec3(1.0), tint, 0.15), clamp(a + haze, 0.0, 1.0) * e);&#10;}&#10;&#10;// @@ fxMist&#10;vec4 fxMist(vec2 m, float t, vec3 tint, float thick, float height)   // v8.5: low mist rolling slowly over water, thickest just above it&#10;{&#10;    float y = 1.0 - m.y;   // 0 at the board's bottom&#10;    float band = 1.0 - smoothstep(0.0, 0.2 + 0.75 * height, y);&#10;    float n1 = fbm(vec2(m.x * 1.6 - t * 0.1, y * 9.0 + 0.4 * sin(m.x * 3.0 + t * 0.2)));   // long, flat banks&#10;    float n2 = fbm(vec2(m.x * 4.0 + t * 0.06, y * 18.0) + 5.0);   // wisps going the other way&#10;    float dens = band * (0.35 + 0.65 * smoothstep(0.2, 0.9, n1 * 0.7 + n2 * 0.4)) * (0.25 + 0.8 * thick);&#10;    dens *= smoothstep(0.0, 0.12, m.x) * (1.0 - smoothstep(0.88, 1.0, m.x));&#10;    return vec4(mix(vec3(0.82, 0.86, 0.9), tint, 0.15), clamp(dens, 0.0, 0.9));&#10;}&#10;&#10;// @@ fxGrade&#10;vec4 fxGrade(vec2 uv, vec2 m, float amt, float con, int style)   // v8.5: a film look over the picture&#10;{&#10;    vec3 c = picAt(uv), g = c;&#10;    float l = lum(c);&#10;    if (style == 0) {   // teal &amp; orange: teal shadows, warm skin and lights&#10;        g = c + mix(vec3(-0.06, 0.03, 0.09), vec3(0.11, 0.03, -0.09), smoothstep(0.15, 0.75, l));&#10;        g = mix(vec3(lum(g)), g, 1.15);&#10;    } else if (style == 1)   // bleach bypass: silvery, little colour, hard&#10;        g = mix(c, vec3(l), 0.6) * 1.05;&#10;    else if (style == 2)   // cold blue&#10;        g = mix(vec3(l), c, 0.75) * vec3(0.84, 0.97, 1.16) + vec3(0.0, 0.01, 0.03);&#10;    else if (style == 3)   // warm sunset&#10;        g = c * vec3(1.16, 0.98, 0.76) + vec3(0.03, 0.01, 0.0);&#10;    else if (style == 4)   // black &amp; white&#10;        g = vec3(l);&#10;    else   // faded film: lifted blacks, softer colour&#10;        g = mix(vec3(0.09, 0.08, 0.11), vec3(0.95, 0.92, 0.85), mix(vec3(l), c, 0.8));&#10;    g = (g - 0.5) * (0.7 + 0.9 * con + (style == 1 ? 0.25 : 0.0)) + 0.5;&#10;    return vec4(mix(c, clamp(g, 0.0, 1.0), amt * edgeFade(m, 0.06)), 1.0);&#10;}&#10;&#10;// @@ fxFocus&#10;vec4 fxFocus(vec2 uv, vec2 m, float t, float blur, float hold, int style, float ar)   // v8.5: the focus shifts: this part goes soft and sharp again (two boards, one of each kind: a focus pull)&#10;{&#10;    float x = abs(fract(t * 0.08) * 2.0 - 1.0);   // 0 .. 1 .. 0&#10;    float h = 0.1 + 0.35 * hold;&#10;    float b = smoothstep(h, 1.0 - h, x);&#10;    if (style == 1) b = 1.0 - b;&#10;    if (style == 2) b = 1.0;&#10;    float r = b * blur * 0.014 * edgeFade(m, 0.1);&#10;    if (r &lt; 0.0004) return vec4(picAt(uv), 1.0);&#10;    vec3 s = vec3(0.0);&#10;    float ws = 0.0;&#10;    for (int i = 0; i &lt; 24 + LZ; i++) {   // a disc of samples: soft, the bright spots grow round&#10;        float fi = float(i), a = fi * 2.39996, rr = sqrt((fi + 0.5) / 24.0) * r;&#10;        vec3 c = picAt(uv + vec2(cos(a) / ar, sin(a)) * rr);&#10;        float w = 1.0 + 2.0 * lum(c) * lum(c);&#10;        s += c * w;&#10;        ws += w;&#10;    }&#10;    return vec4(s / ws, 1.0);&#10;}&#10;&#10;// @@ fxParallax&#10;vec4 fxParallax(vec2 uv, vec2 m, float t, float amt, float depth, int style, vec2 ctr)   // v8.5: 2.5D: the picture in the board moves as a layer of its own, so it seems to stand out from the rest&#10;{&#10;    float e = edgeFade(m, 0.06 + 0.2 * (1.0 - depth));   // the edge goes along with the picture round it&#10;    float s = sin(t * 0.35), c = cos(t * 0.35);&#10;    float k = amt * (0.3 + 0.7 * depth) * e;&#10;    vec2 off = vec2(0.0);&#10;    float z = 1.0;&#10;    if (style == 0) off = vec2(s * 0.022, 0.0) * k;   // side to side&#10;    else if (style == 1) z = 1.0 + 0.05 * k * (0.5 + 0.5 * s);   // pushing in and out&#10;    else off = vec2(s * 0.018, c * 0.01) * k;   // round&#10;    return vec4(picAt(ctr + (uv - ctr) / z - off), 1.0);&#10;}&#10;`;&#10;// the shared code, and the on-demand effects after it, each going into the shader only when an element uses it&#10;const BASE = SHARED.split('// ==== on demand')[0];&#10;const ONDEMAND = SHARED.split('// ==== on demand')[1].split('\n// @@ ').slice(1).map(b =&gt; ({ name: b.split('\n')[0].trim(), code: '\n' + b.slice(b.indexOf('\n') + 1) }));&#10;&#10;// v8.9: the editor's size. The canvas is laid out in W x H units, stretched over the Scene's 1920 x 1080: fewer units make&#10;// everything in the editor bigger (125% is 1536 x 864, 150% 1280 x 720). The picture keeps its own pixels (PXW x PXH).&#10;const UISIZES = [1, 1.25, 1.5];&#10;if (state.uiSize === undefined) state.uiSize = 2;&#10;let W = 1920 / UISIZES[state.uiSize], H = 1080 / UISIZES[state.uiSize];   // the units the editor works in (stretched over the Scene)&#10;const ACC = '#8a3fff';&#10;const NAMESEL = '#c9a6ff';   // a selected name: the purple, lighter so it reads on any picture   // 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;            'Cloud shadows', 'Dappled light', 'Day / night', 'Swell', 'Handheld', 'Colour fringe', 'Bloom',   // v1.5: the picture changes&#10;            'Light trails', 'TV glow', 'Fog', 'Rainbow', 'Shore waves', 'Caustics', 'Beacon', 'Frost', 'Window drops', 'Headlight sweep',&#10;            'Shooting stars', 'Star trails', 'Nebula', 'Northern lights', 'Planet bands', 'Film grain', 'Vignette', 'Old film',   // v1.5&#10;            'Firelight', 'Flame flicker', 'Embers', 'Birds', 'Cloud drift', 'Sun glow',   // v3.5&#10;            'MilkDrop window',   // v4.5: a hole in the picture, where the MilkDrop player's Scene under it shows&#10;            'Shader code',       // v5.0: your own shader (Shadertoy's mainImage), pasted or from a file&#10;            'Spectrum', 'Oscilloscope', 'Lasers', 'Moving heads', 'Mirror ball', 'Strobe', 'Beat zoom', 'Stage wash', 'Beat rings', 'Level meter',   // v5.3: music and stage&#10;            'Lens flare', 'Light leak', 'CRT screen', 'Pixelate', 'Kaleidoscope',   // v5.7: film look and style&#10;            'Picture copy',    // v5.9: a piece of the picture from elsewhere&#10;            '(gone)',          // v8.3's Raven, taken out&#10;            'Blinds', 'Passing train', 'Moonlight', 'Raindrop rings', 'Snowstorm', 'Mist over water', 'Colour grade', 'Focus pull', '2.5D parallax'];   // v8.5&#10;const FXFN = ['fxPlasma', null, 'fxGlitch', 'fxBars', 'fxRetro', 'fxPlasma', 'fxWindow', 'fxNeon', 'fxCustom', null, null,&#10;              'fxClouds', 'fxSmoke'].concat(Array(48).fill(null));&#10;const FXADD = [false, true, 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,&#10;               false, false, false, false, false, false, false, true, true, false, true, false, true, true, false, false, true,&#10;               true, true, true, true, false, false, false, false,&#10;               false, false, true, false, false, true, false, false,&#10;               true, true, true, true, true, true, false, true, true, true,&#10;               true, true, false, false, false, false];   // added light&#10;// the effects in groups, as the panel offers them&#10;const CATS = [['Signs', [0, 1, 2, 3, 4, 6, 7, 13, 36, 8]], ['Light', [14, 15, 22, 41, 44, 35, 53, 58, 78, 79, 80]],&#10;              ['Weather', [9, 11, 12, 24, 37, 25, 26, 42, 43, 38, 82, 83, 81]], ['Water', [10, 27, 39, 40, 81, 83]], ['Nature', [21, 23, 55, 54]],&#10;              ['Sky &amp; space', [45, 46, 47, 48, 49, 56, 57]], ['Moving picture', [76, 16, 17, 18, 19, 20, 28, 29, 31, 54, 57, 86]],&#10;              ['Film look', [30, 32, 33, 34, 50, 51, 52, 71, 72, 73, 74, 75, 84, 85, 86]], ['Music &amp; stage', [61, 62, 63, 64, 65, 66, 67, 68, 69, 70]], ['MilkDrop', [59]], ['Your own', [60]]];&#10;const MOVES = fx =&gt; (fx &gt;= 16 &amp;&amp; fx &lt;= 20) || (fx &gt;= 28 &amp;&amp; fx &lt;= 34) || fx === 52 || fx === 53 || fx === 54 || fx === 57 || fx === 67 || fx &gt;= 73 &amp;&amp; fx &lt;= 76 || [78, 79, 80, 81, 84, 85, 86].includes(fx);   // the picture itself, changed: needs a background&#10;const NOBRIGHT = fx =&gt; MOVES(fx) || fx === 59 || fx === 26 || fx === 42 || fx === 50 || fx === 51;   // these show the picture as it is: no Brightness&#10;const NOCOLOUR = fx =&gt; (MOVES(fx) &amp;&amp; ![19, 29, 30, 34, 53, 78, 79, 80, 81].includes(fx)) || fx === 50 || fx === 59 || fx === 60;   // and these have no colour of their own&#10;// what the two sliders of each v1.1 effect are called, with where they start&#10;const FXK = { 1: ['Glow', 'Flicker', 0.5, 0.1], 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;              28: ['Darkness', 'Cloud size', 0.5, 0.5], 29: ['Strength', 'Patch size', 0.5, 0.5], 30: ['Night', 'Blue', 0.6, 0.5],&#10;              31: ['Rise', 'Tilt', 0.5, 0.3], 32: ['Shake', 'Zoom', 0.4, 0.3], 33: ['Strength', 'Wobble', 0.4, 0.3], 34: ['Glow', 'Size', 0.5, 0.5],&#10;              35: ['Traffic', 'Trail length', 0.6, 0.5], 36: ['Flicker', 'Colours', 0.5, 0.5], 37: ['Thickness', 'Height', 0.6, 0.5],&#10;              38: ['Strength', 'Width', 0.6, 0.4], 39: ['Reach', 'Foam', 0.6, 0.5], 40: ['Strength', 'Size', 0.6, 0.5],&#10;              41: ['Beam width', 'Reach', 0.3, 0.6], 42: ['Grow', 'Blur', 0.5, 0.5], 43: ['Drops', 'Size', 0.4, 0.4],&#10;              44: ['Width', 'How often', 0.5, 0.5], 45: ['How often', 'Trail length', 0.5, 0.5], 46: ['Stars', 'Arc length', 0.5, 0.4],&#10;              47: ['Strength', 'Detail', 0.6, 0.5], 48: ['Strength', 'Height', 0.7, 0.5], 49: ['Opacity', 'Bands', 0.6, 0.5],&#10;              50: ['Amount', 'Grain size', 0.4, 0.3], 51: ['Amount', 'Breathe', 0.6, 0.3], 52: ['Amount', 'Scratches', 0.7, 0.4],&#10;              53: ['Flicker', 'Reach', 0.6, 0.5], 54: ['Strength', 'Size', 0.6, 0.5], 55: ['Amount', 'Height', 0.5, 0.6],&#10;              56: ['How many', 'Size', 0.4, 0.4], 57: ['Direction', 'Distance', 0.75, 0.4], 58: ['Size', 'Pulse', 0.5, 0.5],&#10;              61: ['Bars', 'Height', 0.5, 0.6], 62: ['Height', 'Glow', 0.5, 0.5], 63: ['Beams', 'Sweep', 0.4, 0.5], 64: ['Lights', 'Swing', 0.4, 0.5],&#10;              65: ['Spots', 'Spot size', 0.5, 0.3], 66: ['Speed', 'Flash length', 0.3, 0.3], 67: ['Strength', null, 0.5, 0.5], 68: ['Strength', 'Colour change', 0.6, 0.3],&#10;              69: ['Size', 'Thickness', 0.6, 0.3], 70: ['Segments', 'Glow', 0.4, 0.5],&#10;              71: ['Size', 'Ghosts', 0.5, 0.5], 72: ['Strength', 'Drift', 0.5, 0.4], 73: ['Strength', 'Curve', 0.7, 0.5], 74: ['Block size', 'Fewer colours', 0.4, 0.3],&#10;              75: ['Segments', 'Turning', 0.4, 0.2], 76: ['Size', 'Turn', 0.5, 0.5],&#10;              78: ['Slats', 'Softness', 0.5, 0.3], 79: ['How often', 'Brightness', 0.5, 0.6], 80: ['Darkness', 'Cloud size', 0.6, 0.5],&#10;              81: ['Drops', 'Ring size', 0.5, 0.5], 82: ['Amount', 'Wind', 0.6, 0.6], 83: ['Thickness', 'Height', 0.6, 0.4],&#10;              84: ['Strength', 'Contrast', 0.7, 0.4], 85: ['Blur', 'Hold', 0.6, 0.5], 86: ['Amount', 'Depth', 0.4, 0.5] };&#10;const FXSTYLES = { 1: ['Neon', 'Neon outline', 'Hologram', 'LED dots', 'Lit panel', 'Halo letters', 'LED screen'], 17: ['Grass', 'Leaves', 'Flag'], 19: ['Water', 'Wet street'], 21: ['Snow', 'Dust in sunlight', 'Fireflies', 'Leaves', 'Blossom', 'Hail', 'Sand', 'Stars', 'Bubbles'],&#10;                   23: ['Flames', 'Rocket'], 25: ['Strike', 'In the clouds'], 27: ['Glints', 'Moon path'], 35: ['Cars', 'One colour'],&#10;                   37: ['Ground fog', 'Mist bank'], 41: ['Lighthouse', 'Searchlight'], 60: ['Solid', 'Black is see-through', 'Added light'],&#10;                   61: ['Bars', 'LED blocks', 'Mirrored', 'Line'], 62: ['Line', 'Circle'], 63: ['Fan', 'Crossing', 'Colours'], 64: ['One colour', 'Colours'],&#10;                   65: ['One colour', 'Colours'], 66: ['On the beat', 'Steady', 'Random'], 67: ['On the kick', 'With the level'], 68: ['From below', 'From above'],&#10;                   70: ['Up', 'Across'], 71: ['Round', 'Anamorphic'], 72: ['Warm', 'Rainbow'], 74: ['Pixels', 'Halftone dots', 'Round tiles'],&#10;                   75: ['Kaleidoscope', 'Mirror left-right', 'Mirror top-bottom'], 76: ['As it is', 'Mirrored', 'Upside down'],&#10;                   78: ['Across', 'Up and down', 'Slanting'], 79: ['Left to right', 'Right to left'], 81: ['In the picture', 'Light rings'],&#10;                   84: ['Teal &amp; orange', 'Bleach bypass', 'Cold blue', 'Warm sunset', 'Black &amp; white', 'Faded film'], 85: ['Sharp first', 'Soft first', 'Stay soft'],&#10;                   86: ['Side to side', 'Push in', 'Round'] };&#10;const ADDSTYLES = { 1: [0, 1, 2, 5], 21: [1, 2, 7], 60: [2] };   // the kinds of these that add light (the rest cover)&#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', 'Traffic light', 'Aircraft', 'Lens flare'];   // a board's light: the first 7&#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.demo !== undefined) {   // v8.7: the demos of v8.6 are gone; saved with one on, your own work comes back&#10;    const keep = state.demoKeep;&#10;    if (state.demo &amp;&amp; keep) { state.items = keep.items; state.bg = keep.bg; state.sel = keep.sel; state.edges = keep.edges; }&#10;    delete state.demo; delete state.demoKeep;&#10;}&#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;if (state.bsize === undefined) { state.brush = 0; state.bsize = 0.3; state.bsoft = 0.5; }   // v6.0: the mask brush: 0 off, 1 paint, 2 erase&#10;const brushR = () =&gt; 0.004 + 0.16 * state.bsize * state.bsize;   // the brush's radius, in picture heights&#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;// v6.7: an element can follow another's timeline (it.tlFrom) or sound (it.auFrom), by a cable drawn in Edit: then that one's is used, down a chain&#10;function srcOf(it, kind) {&#10;    let cur = it;&#10;    for (let n = 0; n &lt; 32 &amp;&amp; cur[kind]; n++) {&#10;        const next = state.items.find(t =&gt; t.id === cur[kind]);&#10;        if (!next || next === it) break;&#10;        cur = next;&#10;    }&#10;    return cur;&#10;}&#10;// v7.8: one that follows a timeline also takes its rhythm (speed and seed: when it blinks, pulses, flickers), so they run in step&#10;const RHY = it =&gt; srcOf(it, 'tlFrom');&#10;const TL = it =&gt; srcOf(it, 'tlFrom').tl, AUD = it =&gt; srcOf(it, 'auFrom').au;&#10;const tlOn = (it, key) =&gt; { const tl = TL(it); return !!(tl &amp;&amp; tl.tracks &amp;&amp; tl.tracks[key] &amp;&amp; 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 tl = TL(it), k = tl.tracks[key].keys, u = 'fract(T / ' + f(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;// ---------- the sound: a setting can follow the sound on the Scene's In A, or the DAW's beat ----------&#10;// it.au = { key: { src (0 off, 1.. AUSRC), amt (-1..1: how far it moves the setting, up or down) } }&#10;const AUSRC = ['Off', 'Level', 'Bass', 'Mid', 'High', 'Beat', 'Bar'];&#10;// v6.8: Level, Bass, Mid, High from Envelope Followers in the patch (P55-P58), measured as the meters in the Audio panel; the highs are quieter, so lifted 12 dB&#10;const AUGLSL = [null, 'auLift(auDb(P55), P31)', 'auLift(auDb(P56), P31)', 'auLift(auDb(P57 * 1.4), P31)',&#10;                'auLift(auDb(P58 * 4.0), P31)', '(P29 &gt; 0.5 ? exp(-fract(P28) * 6.0) : 0.0)', '(P29 &gt; 0.5 ? P30 : 0.0)'];&#10;const auOn = (it, key) =&gt; { const au = AUD(it); return !!(au &amp;&amp; au[key] &amp;&amp; au[key].src &gt; 0); };&#10;const anOn = (it, key) =&gt; tlOn(it, key) || auOn(it, key);   // moved by the timeline or the sound&#10;const AN = (it, key, still) =&gt; {   // animated, following the sound, or as it is&#10;    const e = tlOn(it, key) ? tlExpr(it, key) : still;&#10;    const au = AUD(it);&#10;    return auOn(it, key) ? 'clamp(' + e + ' + ' + f(au[key].amt) + ' * AU' + au[key].src + ', 0.0, 1.0)' : e;&#10;};&#10;if (state.auOpen === undefined) state.auOpen = false;&#10;if (state.ausens === undefined) state.ausens = 0.5;&#10;const AUH = 330;   // the Audio panel's height, under the picture&#10;function tlAt(it, key, still, t) {   // the same in the Script, at t seconds: for the pictures, which the Script draws&#10;    if (!tlOn(it, key))&#10;        return still;&#10;    const tl = TL(it), k = tl.tracks[key].keys, u = ((t / tl.len) % 1 + 1) % 1;&#10;    for (let i = 1; i &lt; k.length; i++)&#10;        if (u &lt;= k[i][0])&#10;            return k[i - 1][1] + (k[i][1] - k[i - 1][1]) * Math.max(0, Math.min(1, (u - k[i - 1][0]) / Math.max(1e-4, k[i][0] - k[i - 1][0])));&#10;    return k[k.length - 1][1];&#10;}&#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 === 'mask')&#10;        return L;&#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;        if (it.fx !== 13) L.push(['fade', 'Edge fade', it.fade || 0, pc]);&#10;        if (it.fx === 60 &amp;&amp; it.glsl)   // your own shader's P1-P8, as its code uses them&#10;            glslPNames(it.glsl).forEach(([n, name]) =&gt; L.push(['p' + n, name, glslP(it)[n - 1], v =&gt; v.toFixed(2)]));&#10;    } else if (it.type === 'image') {&#10;        L.push(['x', 'Across', it.x, pc], ['y', 'Down', it.y, pc], ['scale', 'Size', it.scale, v =&gt; Math.round(v * 200) + '%'],&#10;               ['rot', 'Turn', it.rot, v =&gt; Math.round((v - 0.5) * 360) + ' deg']);&#10;        return L;&#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' || !NOCOLOUR(it.fx))&#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 : state.auOpen ? AUH + 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.pts)&#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;for (const it of state.items) if (it.fx === 77) { it.fx = 0; it.style = 0; }   // so is the Raven of v8.3&#10;state.items = state.items.filter(it =&gt; !it.strip);   // so are the filmstrips of v2.0 to v2.5&#10;delete state.strips; delete state.strip2;&#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 (less where a MilkDrop window lets the player show)\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;    '        float a = mix(1.0, o.a, MDW);\n' +&#10;    '        o = vec4(mix(g, o.rgb, o.a / a), a);\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;// v8.2: a board with fixed corners: quadUV's inverse worked out here once (as the shader would, from the same rounded&#10;// corners), the side of the vanishing line folded into its sign; columns for GLSL's mat3&#10;function quadMat(Q) {&#10;    const [a, b, c, d] = Q.map(p =&gt; p.map(v =&gt; +f(v)));&#10;    const sx = a[0] - b[0] + c[0] - d[0], sy = a[1] - b[1] + c[1] - d[1];&#10;    const dx1 = b[0] - c[0], dx2 = d[0] - c[0], dy1 = b[1] - c[1], dy2 = d[1] - c[1];&#10;    const den = dx1 * dy2 - dx2 * dy1;&#10;    if (Math.abs(den) &lt; 1e-9) return 'mat3(0.0)';&#10;    const g = (sx * dy2 - dx2 * sy) / den, h = (dx1 * sy - sx * dy1) / den;&#10;    const A = b[0] - a[0] + g * b[0], B = d[0] - a[0] + h * d[0], C = a[0];&#10;    const D = b[1] - a[1] + g * b[1], E = d[1] - a[1] + h * d[1], F = a[1];&#10;    const i = [E - F * h, C * h - B, B * F - C * E, F * g - D, A - C * g, C * D - A * F, D * h - E * g, B * g - A * h, A * E - B * D];&#10;    const mx = (a[0] + b[0] + c[0] + d[0]) / 4, my = (a[1] + b[1] + c[1] + d[1]) / 4, wm = i[6] * mx + i[7] * my + i[8];&#10;    if (wm === 0) return 'mat3(0.0)';&#10;    const sg = wm &gt; 0 ? 1 : -1, n = Math.max(...i.map(Math.abs)) || 1;   // scaled to about 1: the division cancels it, and floats keep their digits&#10;    const e = k =&gt; (sg * i[k] / n).toExponential(7);&#10;    return 'mat3(' + [e(0), e(3), e(6), e(1), e(4), e(7), e(2), e(5), e(8)].join(', ') + ')';&#10;}&#10;// the box round a board's shape (or, for a light box that shines past its edges, all of it): a pixel outside skips it&#10;const BOXM = 4 / 1080;   // a few pixels more, for the soft edge&#10;function boardBox(it) {&#10;    if (it.type !== 'board' || it.fx === 13)&#10;        return [-1000, -1000, 1000, 1000];&#10;    const xs = it.pts.map(p =&gt; p[0]), ys = it.pts.map(p =&gt; p[1]);&#10;    return [Math.min(...xs) - BOXM, Math.min(...ys) - BOXM, Math.max(...xs) + BOXM, Math.max(...ys) + BOXM];&#10;}&#10;&#10;const SYMP = { 9: 'eA.z', 10: 'eA.w', 11: 'eA.y', 12: 'eB.x', 13: 'eB.y', 23: 'eB.z' };   // P numbers -&gt; the loop's arrays&#10;const SYML = { 1: 'eQ0.x', 2: 'eQ0.y', 3: 'eB.x', 4: 'eA.z', 5: 'eA.w', 6: 'eA.y' };   // the same for a light&#10;// a board or a light that can go in a shared loop: 4 points, nothing on the timeline, not selected, no mask over it&#10;const loopable = (it, masks) =&gt; (it.type === 'light' || it.type === 'board' &amp;&amp; it.pts.length === 4 &amp;&amp; it.fx !== 1 &amp;&amp; it.fx !== 60) &amp;&amp; it.id !== liveSel &amp;&amp; RHY(it).id !== liveSel &amp;&amp;&#10;    !(TL(it) &amp;&amp; TL(it).tracks &amp;&amp; Object.keys(TL(it).tracks).some(k =&gt; tlOn(it, k))) &amp;&amp; !(AUD(it) &amp;&amp; Object.keys(AUD(it)).some(k =&gt; auOn(it, k))) &amp;&amp; !masks.some(m =&gt; m.all !== false || (m.only || []).includes(it.id));&#10;// several boards in a row as one loop: each kind of effect is in the shader once, however many boards use it, so a&#10;// scene with many boards compiles much faster. Their numbers are in arrays; the kind (the code it needs) picks the branch.&#10;function loopCode(run) {&#10;    const n = run.length, kinds = [], ek = [];&#10;    for (const it of run) {&#10;        const code = itemCode(it, false, true);&#10;        let k = kinds.indexOf(code);&#10;        if (k &lt; 0) { k = kinds.length; kinds.push(code); }&#10;        ek.push(k);&#10;    }&#10;    const arr = (type, list) =&gt; 'const ' + type + ' E' + '_' + '[' + list.length + '] = ' + type + '[' + list.length + '](' + list.join(', ') + ');';&#10;    const nm = (decl, name) =&gt; decl.replace(' E_[', ' ' + name + '[');&#10;    const q = run.flatMap(it =&gt; it.type === 'light' ? [v2(it.x, it.y), 'vec2(0.0)', 'vec2(0.0)', 'vec2(0.0)'] : boardQuad(it).map(p =&gt; v2(p[0], p[1])));&#10;    const k1 = it =&gt; it.rsize === undefined ? 0.6 : it.rsize, k2 = it =&gt; it.rstr === undefined ? 0.6 : it.rstr;&#10;    return '    {   // ' + n + ' elements in one loop\n' +&#10;        '        ' + nm(arr('vec2', q), 'EQ') + '\n' +&#10;        '        ' + nm(arr('vec3', run.map(it =&gt; rgb(hexOf(it)))), 'ET') + '\n' +&#10;        '        ' + nm(arr('vec4', run.map(it =&gt; 'vec4(' + [RHY(it).seed, it.transp || 0, RHY(it).speed, it.type === 'light' ? it.power : it.bright].map(f).join(', ') + ')')), 'EA') + '\n' +&#10;        '        ' + nm(arr('vec4', run.map(it =&gt; 'vec4(' + (it.type === 'light' ? [it.size, 0, 0, 0] : [k1(it), k2(it), it.fade || 0, 0]).map(f).join(', ') + ')')), 'EB') + '\n' +&#10;        '        ' + nm(arr('int', ek.map(String)), 'EK') + '\n' +&#10;        '        ' + nm(arr('mat3', run.map(it =&gt; it.type === 'board' ? quadMat(boardQuad(it)) : 'mat3(0.0)')), 'EM') + '\n' +&#10;        '        ' + nm(arr('vec4', run.map(it =&gt; 'vec4(' + boardBox(it).map(f).join(', ') + ')')), 'EBB') + '\n' +&#10;        '        for (int ei = 0; ei &lt; ' + n + ' + LZ; ei++) {\n' +&#10;        '            vec2 eQ0 = EQ[ei * 4], eQ1 = EQ[ei * 4 + 1], eQ2 = EQ[ei * 4 + 2], eQ3 = EQ[ei * 4 + 3];\n' +&#10;        '            vec3 eT = ET[ei];\n            vec4 eA = EA[ei], eB = EB[ei];\n' +&#10;        '            int ek = EK[ei];\n            mat3 eM = EM[ei];\n            vec4 eBB = EBB[ei];\n' +&#10;        kinds.map((c, k) =&gt; '            ' + (k ? 'else ' : '') + (k &lt; kinds.length - 1 ? 'if (ek == ' + k + ') ' : '') + '{\n' + c + '            }\n').join('') +&#10;        '        }\n    }\n';&#10;}&#10;&#10;// Two sets of P for the selected element, used in turn (P1..P23, or P32..P54): choosing another element needs a new&#10;// shader, and until it is built the old one keeps reading the old set, so the old one is never drawn with the new&#10;// element's numbers.&#10;let bank = 0;&#10;const PN = k =&gt; 'P' + (bank ? k + 31 : k);&#10;// v5.5: a text board's own words (typed in the box at the top), up to 3 lines; boards from before have one of the old fixed texts&#10;const textLines = it =&gt; String(it.label !== undefined ? it.label : TEXTS[Math.min(it.text || 0, TEXTS.length - 1)]).split('\n')&#10;    .map(l =&gt; l.trim().slice(0, 40)).filter(l =&gt; l).slice(0, 3);&#10;let labelList = [], textFns = [];   // the Scene's Labels, and each text board's own functions, made with the shader&#10;function labIdx(str) {&#10;    let i = labelList.indexOf(str);&#10;    if (i &lt; 0 &amp;&amp; labelList.length &lt; 16) { i = labelList.length; labelList.push(str); }&#10;    return Math.max(0, i);&#10;}&#10;function textCode(it, tint, k1, k2) {&#10;    const q = boardQuad(it), len = (a, b) =&gt; Math.hypot((q[b][0] - q[a][0]) * W, (q[b][1] - q[a][1]) * H);&#10;    const asp = Math.max(0.05, (len(0, 1) + len(3, 2)) / Math.max(1, len(0, 3) + len(1, 2)));&#10;    const V = [1000, 1000 / asp], motion = it.tmove === undefined ? 1 : it.tmove;&#10;    let lines = textLines(it), S, calls, scroll = 1;&#10;    if (!lines.length) lines = [' '];&#10;    if (motion === 1) {   // one line running by, from the right edge out over the left&#10;        const line = lines.join('   ');&#10;        S = V[1] * 0.6;&#10;        scroll = V[0] + textW(line, S) + S;&#10;        calls = ['labelText(p, ' + labIdx(line) + ', vec2(' + f(V[0]) + ', ' + f(V[1] / 2 - S * 0.36) + '), ' + f(S) + ', 0.0)'];&#10;    } else {              // the lines in the middle, as big as fits&#10;        const n = lines.length, wide = Math.max(...lines.map(l =&gt; textW(l, 1)));&#10;        S = Math.min(V[1] * 0.78 / (1.2 * n - 0.2), V[0] * 0.86 / Math.max(0.5, wide));&#10;        const top = V[1] / 2 + S * (1.2 * n - 0.2) / 2;&#10;        calls = lines.map((l, k) =&gt; 'labelText(p, ' + labIdx(l) + ', vec2(' + f(V[0] / 2) + ', ' + f(top - S * (0.82 + 1.2 * k)) + '), ' + f(S) + ', 0.5)');&#10;    }&#10;    const tpl = ONDEMAND.find(b =&gt; b.name === 'fxTextN').code;&#10;    textFns.push('float txt' + it.id + '(vec2 p) { return ' + calls.reduce((a, b) =&gt; 'max(' + a + ', ' + b + ')') + '; }\n' +&#10;                 tpl.split('txtBlur').join('txtBlur' + it.id).split('TXT(').join('txt' + it.id + '(').split('fxTextN').join('fxText' + it.id));&#10;    return 'fxText' + it.id + '(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + (it.style || 0) + ', ' + motion + ', ' + v2(V[0], V[1]) + ', ' + f(S) + ', ' + f(scroll) + ')';&#10;}&#10;function itemCode(it, live, sym) {   // sym: a board in a shared loop, its numbers read from the loop's arrays (eQ0..3, eT, eA, eB)&#10;    if (it.type === 'image' || it.type === 'mask')   // the Script draws it / a mask is worked in by buildCode&#10;        return '';&#10;    // live: the selected element reads P1.. so dragging it needs no new shader&#10;    const SY = it.type === 'light' ? SYML : SYMP, P = (k, v) =&gt; sym &amp;&amp; SY[k] ? SY[k] : live ? PN(k) : f(v);&#10;    const c3 = hexRGB(hexOf(it));&#10;    const tint = anOn(it, 'r') || anOn(it, 'g') || anOn(it, 'b') ?&#10;        'vec3(' + ['r', 'g', 'b'].map((k, i) =&gt; AN(it, k, live ? PN(18 + i) : f(c3[i]))).join(', ') + ')' :&#10;        sym ? 'eT' : live ? 'vec3(' + PN(18) + ', ' + PN(19) + ', ' + PN(20) + ')' : rgb(hexOf(it));&#10;    const rs = RHY(it), seed = sym ? 'eA.x' : f(rs.seed);&#10;    const SP = k =&gt; rs === it || sym ? P(k, it.speed) : rs.id === liveSel ? PN(rs.type === 'light' ? 4 : 9) : f(rs.speed);   // the one followed selected: its live speed   // its speed, or (following) that of the one it follows&#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 quad = boardQuad(it);&#10;        const pt = (i) =&gt; sym ? 'eQ' + i : live ? 'vec2(' + PN(2 * i + 1) + ', ' + PN(2 * i + 2) + ')' : v2(quad[i][0], quad[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;            fx = textCode(it, tint, k1, k2);&#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(tex0(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 ctr = '(' + pt(0) + ' + ' + pt(1) + ' + ' + pt(2) + ' + ' + pt(3) + ') * 0.25';   // the middle of the board&#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 + ', ' + st + ')'),&#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 + ', ' + st + ')',&#10;                   24: 'fxSteam(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   25: 'fxLightning(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + (state.bg ? 'tex0(uv).rgb' : 'vec3(0.0)') + ', ' + st + ')',&#10;                   26: 'fxGlass(fc / R.y, uv, t, ' + tint + ', ' + k1 + ', ' + k2 + ', R.y / R.x)',&#10;                   27: 'fxSparkle(fc, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', S, ' + (state.bg ? 'lum(tex0(uv).rgb)' : '1.0') + ', ' + st + ')',&#10;                   28: bg('fxCloudShadow(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   29: bg('fxDappled(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')'),&#10;                   30: bg('fxDayNight(uv, ' + k1 + ', ' + k2 + ', ' + tint + ')'),&#10;                   31: bg('fxSwell(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   32: bg('fxHandheld(uv, t, ' + k1 + ', ' + k2 + ')'),&#10;                   33: bg('fxFringe(uv, t, ' + k1 + ', ' + k2 + ')'),&#10;                   34: bg('fxBloom(uv, t, ' + tint + ', ' + k1 + ', ' + k2 + ')'),&#10;                   35: 'fxLightTrails(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   36: 'fxTV(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   37: 'fxFog(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   38: 'fxRainbow(m, t, ' + k1 + ', ' + k2 + ')',&#10;                   39: 'fxShore(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   40: 'fxCaustics(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   41: 'fxBeacon(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   42: 'fxFrost(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   43: 'fxDrips(fc / R.y, uv, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   44: 'fxSweep(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   45: 'fxShooting(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   46: 'fxStarTrails(q, (' + pt(0) + ' + ' + pt(1) + ' + ' + pt(2) + ' + ' + pt(3) + ') * 0.25, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   47: 'fxNebula(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   48: 'fxAurora(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   49: 'fxPlanetBands(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   50: 'fxGrain(fc, t, ' + k1 + ', ' + k2 + ')',&#10;                   51: 'fxVignette(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   52: bg('fxOldFilm(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   53: bg('fxFirelight(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')'),&#10;                   54: bg('fxFlame(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   55: 'fxEmbers(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   56: 'fxBirds(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   57: bg('fxDrift(uv, m, t, ' + k1 + ', ' + k2 + ')'),&#10;                   58: 'fxSunGlow(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   59: 'vec4(0.0, 0.0, 0.0, 1.0)',&#10;                   60: glslOf(it) ? glslCall(it) : 'vec4(0.0)',&#10;                   61: 'fxSpectrum(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   62: 'fxScope(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   63: 'fxLaser(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   64: 'fxHeads(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   65: 'fxDisco(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   66: 'fxStrobe(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   67: bg('fxBump(uv, m, (' + pt(0) + ' + ' + pt(1) + ' + ' + pt(2) + ' + ' + pt(3) + ') * 0.25, ' + k1 + ', ' + st + ', ' + (full ? '0.0' : '1.0') + ')'),&#10;                   68: 'fxWash(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   69: 'fxRings(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   70: 'fxMeter(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   71: 'fxLensFlare(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ', R.x / R.y)',&#10;                   72: 'fxLightLeak(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')',&#10;                   73: bg('fxCRT(uv, m, t, ' + ctr + ', ' + k1 + ', ' + k2 + ', R.x / R.y)'),&#10;                   74: bg('fxPixelate(uv, ' + k1 + ', ' + k2 + ', ' + st + ', R.x / R.y)'),&#10;                   75: bg('fxKaleido(uv, m, t, ' + ctr + ', ' + k1 + ', ' + k2 + ', ' + st + ', R.x / R.y)'),&#10;                   76: bg('fxCopy(uv, ' + ctr + ', ' + (it.kx === undefined ? ctr : v2(it.kx, it.ky)) + ', ' + k1 + ', ' + k2 + ', ' + st + ', R.x / R.y)'),&#10;                   78: bg('fxBlinds(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')'),&#10;                   79: bg('fxTrain(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')'),&#10;                   80: bg('fxMoonlight(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')'),&#10;                   81: bg('fxDropRings(uv, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ', ' + st + ')'),&#10;                   82: 'fxSnowstorm(fc / R.y, m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   83: 'fxMist(m, t, ' + tint + ', ' + k1 + ', ' + k2 + ')',&#10;                   84: bg('fxGrade(uv, m, ' + k1 + ', ' + k2 + ', ' + st + ')'),&#10;                   85: bg('fxFocus(uv, m, t, ' + k1 + ', ' + k2 + ', ' + st + ', R.x / R.y)'),&#10;                   86: bg('fxParallax(uv, m, t, ' + k1 + ', ' + k2 + ', ' + st + ', vec2(0.0, 1.0) + vec2(1.0, -1.0) * ' + ctr + ')') }[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, tex0(vec2(uv.x + d.x, uv.y - d.y)).rgb, cov * ' + vis + ');\n' +&#10;            '            }\n' : '';&#10;        // how it follows the picture: Surface (with the moving picture: stronger where it is bright), Bright parts, Dark parts&#10;        const react = !pic || [10, 14, 15].includes(it.fx) ? '' :&#10;            MOVES(it.fx) &amp;&amp; pic === 1 ? '            s.a *= clamp(0.2 + 1.2 * lum(tex0(uv).rgb), 0.0, 1.0);\n' :&#10;            '            picReact(s, ' + pic + ', tex0(uv).rgb);\n';&#10;        const glowOut = it.fx === 13;   // a light box shines past its edges&#10;        // Edge fade (P23 while selected): softly gone towards the edges, over so much of the way to the middle&#10;        let fadeCode = '';&#10;        if (!glowOut &amp;&amp; (live || anOn(it, 'fade') || (it.fade || 0) &gt; 0.001)) {&#10;            const q4 = boardQuad(it), hs = Math.min(...[0, 1, 2, 3].map(i =&gt; Math.hypot((q4[(i + 1) % 4][0] - q4[i][0]) * W, (q4[(i + 1) % 4][1] - q4[i][1]) * H))) / H / 2;&#10;            const e = it.pts.length === 4 ? '2.0 * min(min(m.x, 1.0 - m.x), min(m.y, 1.0 - m.y))' : '-sd / ' + f(Math.max(1e-4, hs));&#10;            const fd = AN(it, 'fade', P(23, it.fade || 0));&#10;            fadeCode = '            { float fd = ' + fd + '; if (fd &gt; 0.001) s.a *= smoothstep(0.0, fd, ' + e + '); }   // Edge fade\n';&#10;        }&#10;        const mixl = it.fx === 59 ? 'C *= 1.0 - s.a * cov; A *= 1.0 - s.a * cov; MDW = max(MDW, s.a * cov);   // see-through: the MilkDrop Scene under it shows' :&#10;                     glowOut ? 'glowAdd(C, A, s.rgb * s.a);' :&#10;                     FXADD[it.fx] &amp;&amp; (!ADDSTYLES[it.fx] || ADDSTYLES[it.fx].includes(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;        // v8.2: a fixed board: its matrix worked out by the Script, and pixels outside its box skip it all&#10;        const bb = boardBox(it), open = sym ? '    if (q.x &gt; eBB.x &amp;&amp; q.y &gt; eBB.y &amp;&amp; q.x &lt; eBB.z &amp;&amp; q.y &lt; eBB.w) {   // ' :&#10;                   live || glowOut ? '    {   // ' : '    if (q.x &gt; ' + f(bb[0]) + ' &amp;&amp; q.y &gt; ' + f(bb[1]) + ' &amp;&amp; q.x &lt; ' + f(bb[2]) + ' &amp;&amp; q.y &lt; ' + f(bb[3]) + ') {   // ';&#10;        const muv = sym ? 'quadUVm(q, eM)' : live ? 'quadUV(q, ' + pt(0) + ', ' + pt(1) + ', ' + pt(2) + ', ' + pt(3) + ')' : 'quadUVm(q, ' + quadMat(quad) + ')';&#10;        return open + FX[it.fx] + '\n' +&#10;               '        vec2 m = ' + muv + ';\n' +&#10;               (it.pts.length === 4 ? '        float cov = m.x &gt; -5.0 ? quadCov(q, ' + pt(0) + ', ' + pt(1) + ', ' + pt(2) + ', ' + pt(3) + ', R) : 0.0;\n' :&#10;                '        float sd = m.x &gt; -5.0 ? shape' + it.id + '(qa) : 1.0;   // its own shape, worked out once\n' +&#10;                '        float cov = clamp(0.5 - sd * R.y, 0.0, 1.0);\n') +&#10;               '        if (' + (glowOut ? 'm.x &gt; -5.0' : 'cov &gt; 0.0') + ') {\n' +&#10;               '            float t = T * ' + spd(SP(9)) + ' + ' + 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' + fadeCode +&#10;               '            ' + mixl + '\n' +&#10;               '        }\n' +&#10;               '    }\n';&#10;    }&#10;    const sz = AN(it, 'size', P(3, it.size)), lx = AN(it, 'x', P(1, it.x)), ly = AN(it, 'y', P(2, it.y)), pw = AN(it, 'power', P(5, it.power));&#10;    const lt = 'T * ' + spd(SP(4));&#10;    const lc = it.mode === 7 ? 'trafficCol(' + lt + ' + ' + seed + ' * 8.0)' : tint;   // a traffic light picks its own colour&#10;    return '    glowAdd(C, A, lamp(fc, vec2(' + lx + ', 1.0 - ' + ly + ') * R, (6.0 + 250.0 * ' + sz + ' * ' + sz + ') * S, ' +&#10;           '3.0 * ' + pw + ' * ' + vis + ' * lampAmp(' + it.mode + ', ' + lt + ', ' + seed + '), ' + lc + ', ' + (it.mode === 2 ? '1.0' : '0.0') + '));   // ' + MODES[it.mode] + '\n' +&#10;           (it.mode === 9 ? '    glowAdd(C, A, fxFlare(q, vec2(' + lx + ', ' + ly + '), T, ' + tint + ', ' + pw + ' * ' + vis + '));\n' : '');&#10;}&#10;&#10;function buildCode() {&#10;    labelList = []; textFns = [];&#10;    let s = '// Made by the Cinemnode Script: change the Script, not this.\n' + BASE + '@NEEDED@\n' + CUSTOM + '\n' +&#10;            'float AU1, AU2, AU3, AU4, AU5, AU6;   // the sound and the beat (Audio panel), worked out at the top of sceneImage\n' +&#10;            'float MDW = 0.0;   // how much a MilkDrop window opened this pixel (no chequer there in Edit: the player shows)\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 PIC = tex0(uv).rgb;   // the background, read once for every effect that looks at it\n    vec3 C = PIC;\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;            '    vec2 qa = q * vec2(R.x / R.y, 1.0);   // q with square pixels, for the masks\n';&#10;    let body = '';&#10;    const masks = state.items.filter(m =&gt; m.type === 'mask' &amp;&amp; !m.hidden &amp;&amp; m.pts.length &gt; 2);&#10;    let run = [];&#10;    const flush = () =&gt; { if (run.length &gt; 1) body += loopCode(run); else if (run.length) body += itemCode(run[0], false); run = []; };&#10;    // Only the selected one (Scene, While editing): in Edit the others are left out, so the shader is small, quick to&#10;    // build and quick to draw; with nothing selected, or in Perform, all of them&#10;    const solo = state.edit &amp;&amp; state.solo &amp;&amp; state.items.some(t =&gt; t.id === liveSel &amp;&amp; !['image', 'mask'].includes(t.type));&#10;    const shown = it =&gt; !it.hidden &amp;&amp; (!solo || it.id === liveSel || it.type === 'mask');&#10;    for (const it of state.items)&#10;        if (shown(it) &amp;&amp; loopable(it, masks))&#10;            run.push(it);&#10;        else if (shown(it)) {&#10;            flush();&#10;            const code = itemCode(it, it.id === liveSel);&#10;            const on = code ? masks.filter(m =&gt; m.all !== false || (m.only || []).includes(it.id)) : [];&#10;            body += !on.length ? code :   // what the element added is taken back again where its masks are: worked out only where it drew, each mask once a pixel&#10;                '    {\n    vec3 C0 = C; float A0 = A;\n' + code +&#10;                '    if (C != C0 || A != A0) {\n' + on.map(m =&gt; '        if (mk' + m.id + ' &lt; 0.0) mk' + m.id + ' = mask' + m.id + '(qa);\n').join('') +&#10;                '        float mk = ' + on.map(m =&gt; 'mk' + m.id).reduce((a, b) =&gt; 'max(' + a + ', ' + b + ')') + ';\n' +&#10;                '        C = mix(C, C0, mk); A = mix(A, A0, mk);\n    }\n    }\n';&#10;        }&#10;    flush();&#10;    const shapes = state.items.filter(t =&gt; t.type === 'board' &amp;&amp; shown(t) &amp;&amp; t.pts.length !== 4);&#10;    const own = [...new Set(state.items.filter(t =&gt; t.type === 'board' &amp;&amp; t.fx === 60 &amp;&amp; shown(t) &amp;&amp; glslOf(t)).map(t =&gt; glslOf(t)))];   // each shader once&#10;    if (textFns.length)&#10;        s = s.replace('void sceneImage(', textFns.join('\n') + '\nvoid sceneImage(');&#10;    if (own.length)&#10;        s = s.replace('void sceneImage(', own.map(src =&gt; glslAdapt(src).code).join('\n') + '\nvoid sceneImage(');&#10;    if (masks.length || shapes.length)&#10;        s = s.replace('void sceneImage(', masks.map(maskCode).join('') + shapes.map(t =&gt; polyFn('shape' + t.id, t.pts) + '    return s * sqrt(d);   // &lt; 0 inside, in heights\n}\n').join('') + 'void sceneImage(');&#10;    for (let k = 1; k &lt; AUSRC.length; k++)   // the sound, worked out once a pixel, only what is used&#10;        if (new RegExp('\\bAU' + k + '\\b').test(body + masks.map(maskCode).join('')))&#10;            s += '    AU' + k + ' = ' + AUGLSL[k] + ';   // ' + AUSRC[k] + '\n';&#10;    s += masks.map(m =&gt; '    float mk' + m.id + ' = -1.0;   // mask ' + m.id + ', not worked out yet\n').join('') + body.split('tex0(uv).rgb').join(state.bg ? 'PIC' : 'tex0(uv).rgb');&#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;    const needed = ONDEMAND.filter(b =&gt; body.includes(b.name + '(')).map(b =&gt; b.code).join('');   // only the effects in use&#10;    // v6.1: changing scenes (P24 0..1): the picture fades to black, or to the bare background, and back&#10;    s += state.sfade === 2 &amp;&amp; state.bg ? '    C = mix(C, PIC, P24); A = mix(A, 1.0, P24);   // scene change: to the background\n' :&#10;                                         '    C = mix(C, vec3(0.0), P24); A = mix(A, 1.0, P24);   // scene change: to black\n';&#10;    return pruneGLSL(s.replace('@NEEDED@', needed) + '    o = A &gt; 0.0001 ? vec4(min(C / A, vec3(1.0)), A) : vec4(0.0);\n}\n\n' + VIEW_MAIN);&#10;}&#10;// v8.2: only the functions the shader reaches (from mainImage down) stay in it: the shared code holds some forty effects,&#10;// and a shorter shader is built (compiled) sooner, each time it changes&#10;const FNHEAD = /^(?:void|float|int|bool|vec[234]|ivec[234]|mat[234])\s+(\w+)\s*\(/;&#10;function pruneGLSL(code) {&#10;    const lines = code.split('\n'), parts = [];   // { name, text } for each function, { text } for what is between them&#10;    for (let i = 0; i &lt; lines.length;) {&#10;        const h = FNHEAD.exec(lines[i]);&#10;        if (!h || /;\s*$/.test(lines[i])) { parts.push({ text: lines[i++] }); continue; }&#10;        const from = i;&#10;        let depth = 0, open = false;&#10;        for (; i &lt; lines.length; i++) {&#10;            const l = lines[i].replace(/\/\/.*$/, '');&#10;            for (const ch of l) { if (ch === '{') { depth++; open = true; } else if (ch === '}') depth--; }&#10;            if (open &amp;&amp; depth &lt;= 0) { i++; break; }&#10;        }&#10;        parts.push({ name: h[1], text: lines.slice(from, i).join('\n') });&#10;    }&#10;    const calls = t =&gt; new Set((t.replace(/\/\/.*$/gm, '').match(/\b\w+(?=\s*\()/g) || []));&#10;    const want = new Set(['mainImage']), todo = ['mainImage'];&#10;    parts.forEach(p =&gt; { if (!p.name) for (const c of calls(p.text)) if (!want.has(c)) { want.add(c); todo.push(c); } });   // what lies between them (defines) counts too&#10;    while (todo.length) {&#10;        const n = todo.pop();&#10;        for (const p of parts)&#10;            if (p.name === n) for (const c of calls(p.text)) if (!want.has(c)) { want.add(c); todo.push(c); }&#10;    }&#10;    return parts.filter(p =&gt; !p.name || want.has(p.name)).map(p =&gt; p.text).join('\n');&#10;}&#10;&#10;// a mask in GLSL: how much it holds back at p (q with square pixels), 0 to 1, from how far p is inside its shape&#10;function polyFn(name, P) {   // how far p is from a shape's edge (its body: s * sqrt(d), negative inside)&#10;    const k = W / H, n = P.length;&#10;    const pts = P.map(p =&gt; 'vec2(' + f(p[0] * k) + ', ' + f(p[1]) + ')').join(', ');&#10;    return 'float ' + name + '(vec2 p)\n{\n' +&#10;        '    vec2 v[' + n + '] = vec2[' + n + '](' + pts + ');\n' +&#10;        '    float d = dot(p - v[0], p - v[0]), s = 1.0;\n' +&#10;        '    for (int i = 0, j = ' + (n - 1) + '; i &lt; ' + n + '; j = i, i++) {\n' +&#10;        '        vec2 e = v[j] - v[i], w = p - v[i];\n' +&#10;        '        vec2 b = w - e * clamp(dot(w, e) / dot(e, e), 0.0, 1.0);\n' +&#10;        '        d = min(d, dot(b, b));\n' +&#10;        '        bvec3 c = bvec3(p.y &gt;= v[i].y, p.y &lt; v[j].y, e.x * w.y &gt; e.y * w.x);\n' +&#10;        '        if (all(c) || all(not(c))) s = -s;\n    }\n';&#10;}&#10;function maskCode(m) {&#10;    const k = W / H, n = m.pts.length;&#10;    const pts = m.pts.map(p =&gt; 'vec2(' + f(p[0] * k) + ', ' + f(p[1]) + ')').join(', ');&#10;    const fe = f(0.0005 + 0.08 * (m.feather === undefined ? 0.2 : m.feather));&#10;    return 'float mask' + m.id + '(vec2 p)\n{\n' +&#10;        (m.bonly ? '    float in_ = 0.0;   // brush only: the shape is just its handle\n' : polyIn(n, pts, fe)) + brushCode(m) +&#10;        '    return ' + (m.invert ? '(1.0 - in_)' : 'in_') + ' * (1.0 - ' + AN(m, 'transp', f(m.transp || 0)) + ');\n}\n';&#10;}&#10;function polyIn(n, pts, fe) {   // 1 inside the mask's shape, soft at its edge&#10;    return '    vec2 v[' + n + '] = vec2[' + n + '](' + pts + ');\n' +&#10;        '    float d = dot(p - v[0], p - v[0]), s = 1.0;\n' +&#10;        '    for (int i = 0, j = ' + (n - 1) + '; i &lt; ' + n + '; j = i, i++) {\n' +&#10;        '        vec2 e = v[j] - v[i], w = p - v[i];\n' +&#10;        '        vec2 b = w - e * clamp(dot(w, e) / dot(e, e), 0.0, 1.0);\n' +&#10;        '        d = min(d, dot(b, b));\n' +&#10;        '        bvec3 c = bvec3(p.y &gt;= v[i].y, p.y &lt; v[j].y, e.x * w.y &gt; e.y * w.x);\n' +&#10;        '        if (all(c) || all(not(c))) s = -s;\n    }\n' +&#10;        '    float in_ = 1.0 - smoothstep(-' + fe + ', ' + fe + ', s * sqrt(d));   // 1 inside\n';&#10;}&#10;// v6.0: the brush. Each stroke, in the order painted, adds to the mask (Paint) or takes from it (Erase), soft at its edge&#10;function brushCode(m) {&#10;    const k = W / H;&#10;    return (m.strokes || []).map(st =&gt; {&#10;        const P = st.p.map(q =&gt; [q[0] * k, q[1]]), r = st.r, r0 = r * (1 - 0.95 * st.s);&#10;        const x0 = Math.min(...P.map(q =&gt; q[0])) - r, x1 = Math.max(...P.map(q =&gt; q[0])) + r, y0 = Math.min(...P.map(q =&gt; q[1])) - r, y1 = Math.max(...P.map(q =&gt; q[1])) + r;&#10;        const n = P.length, a = 'smoothstep(' + f(r) + ', ' + f(r0) + ', d)';&#10;        return '    if (p.x &gt; ' + f(x0) + ' &amp;&amp; p.x &lt; ' + f(x1) + ' &amp;&amp; p.y &gt; ' + f(y0) + ' &amp;&amp; p.y &lt; ' + f(y1) + ') {   // a stroke: ' + (st.e ? 'erase' : 'paint') + '\n' +&#10;               '        vec2 b[' + n + '] = vec2[' + n + '](' + P.map(q =&gt; 'vec2(' + f(q[0]) + ', ' + f(q[1]) + ')').join(', ') + ');\n' +&#10;               '        float d = length(p - b[0]);\n' +&#10;               '        for (int i = 1; i &lt; ' + n + '; i++) { vec2 e = b[i] - b[i - 1], w = p - b[i - 1]; d = min(d, length(w - e * clamp(dot(w, e) / max(dot(e, e), 1e-9), 0.0, 1.0))); }\n' +&#10;               '        in_ = ' + (st.e ? 'min(in_, 1.0 - ' + a + ')' : 'max(in_, ' + a + ')') + ';\n    }\n';&#10;    }).join('');&#10;}&#10;// a stroke as painted, made lighter: points closer than a fifth of the brush to the line through them go&#10;function simplify(P, tol) {&#10;    if (P.length &lt; 3) return P;&#10;    const [a, b] = [P[0], P[P.length - 1]];&#10;    let far = 0, at = 0;&#10;    for (let i = 1; i &lt; P.length - 1; i++) {&#10;        const ex = b[0] - a[0], ey = b[1] - a[1], wx = P[i][0] - a[0], wy = P[i][1] - a[1], L = ex * ex + ey * ey;&#10;        const t = L ? Math.max(0, Math.min(1, (wx * ex + wy * ey) / L)) : 0, d = Math.hypot(wx - ex * t, wy - ey * t);&#10;        if (d &gt; far) { far = d; at = i; }&#10;    }&#10;    if (far &lt;= tol) return [a, b];&#10;    return simplify(P.slice(0, at + 1), tol).slice(0, -1).concat(simplify(P.slice(at), tol));&#10;}&#10;&#10;let sentCode = '';&#10;// v8.1: the shader is built for liveSel (the element it reads from P). Selecting only redraws the editor; the new shader&#10;// follows a moment later (codePend ticks), so clicking through the layers builds it once; the first drag or slider builds it at once&#10;let liveSel = 0, codePend = 0;&#10;let sentSel = 0;   // the element the shader on its way reads from P&#10;function sendCode() {&#10;    codePend = 0;&#10;    liveSel = state.sel;&#10;    if (state.sel !== sentSel) { sentSel = state.sel; bank ^= 1; }   // the other set of P: see PN&#10;    const code = buildCode(), key = code + '\n' + labelList.join('\n');   // new words alone are new Labels, the same code&#10;    if (key !== sentCode) {&#10;        sentCode = key;&#10;        out(1, { labels: labelList.length ? labelList.slice() : [' '], 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, P31: state.ausens } });&#10;}&#10;let tlDirty = false;   // the timeline changed while dragging: a new shader once you let go&#10;c.on('dragend', () =&gt; { if (brushEnd) brushEnd(); dropRow(); sendAids(null); if (tlDirty) { tlDirty = false; sendCode(); } });&#10;&#10;function sendP() {&#10;    if (state.sel !== liveSel) { sendCode(); return; }   // the shader still reads another element's P: build it for this one first (it sends the P)&#10;    const it = selected();&#10;    if (!it || it.type === 'image' || it.type === 'mask')&#10;        return;&#10;    const v = it.type === 'board' ? boardQuad(it).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;                                    [it.x, it.y, it.size, it.speed, it.power, it.transp || 0];&#10;    const p = {};&#10;    v.forEach((x, i) =&gt; p[PN(i + 1)] = x);&#10;    if (it.type === 'board')&#10;        p[PN(23)] = it.fade || 0;&#10;    hexRGB(hexOf(it)).forEach((x, i) =&gt; p[PN(18 + i)] = x);&#10;    out(1, { p: p });&#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 addMask(x, y) {&#10;    const r = 0.12, pts = [];&#10;    for (let i = 0; i &lt; 6; i++) { const a = i / 6 * 2 * Math.PI - Math.PI / 2; pts.push([x + r * Math.cos(a) * H / W, y + r * Math.sin(a)]); }&#10;    const it = { id: state.next++, type: 'mask', pts: pts, feather: 0.2, invert: 0, all: true, only: [], transp: 0, seed: Math.random() };&#10;    state.items.push(it);&#10;    select(it.id);&#10;}&#10;&#10;// ---------- the sound player: an Audio Player in the patch, run from Properties (Scene), heard and fed to the Scene's In A ----------&#10;// Out 3 its file, Out 4 Play, Out 5 Stop, Out 6 Loop, Out 7 Volume (dB)&#10;if (state.snd === undefined) state.snd = { file: '', loop: true, vol: 40 / 46, playing: false };   // v7.0: 0 dB to start&#10;&#10;// ---------- MilkDrop: the MilkDrop Player has its own Scene, under this one; a &quot;MilkDrop window&quot; board shows it ----------&#10;// Out 8 -&gt; the player's In 5 (commands as JSON text), its Out 4 (what it made of a preset) -&gt; In 4 here&#10;if (state.md === undefined) state.md = { file: '', tex: '', which: 0, standin: 0, status: null };&#10;if (!state.md.set) state.md.set = { sensitivity: 0.5, speed: 0.5, brightness: 0.5 };   // v4.8: the player's settings, 0.5 as in MilkDrop&#10;if (!state.md.list) { state.md.list = state.md.file ? [state.md.file] : []; state.md.levels = {}; state.md.lscroll = 0; }   // v4.8: the playlist&#10;let wantMd = '';   // the next file from the File node is a preset ('file') or one in the textures folder ('tex')&#10;function mdSend(cmd) { out(8, JSON.stringify(cmd)); }&#10;function mdPlay(path) {   // play a preset of the playlist (or a new one, which joins the list)&#10;    const md = state.md;&#10;    if (!md.list.includes(path)) md.list.push(path);&#10;    md.file = path; md.which = 0; md.status = null;&#10;    mdSend({ file: path });&#10;    rebuild();&#10;}&#10;function mdStep(d) {&#10;    const md = state.md, n = md.list.length;&#10;    if (!n) return;&#10;    const i = md.list.indexOf(md.file);&#10;    mdPlay(md.list[((i &lt; 0 ? 0 : i + d) % n + n) % n]);&#10;}&#10;const MDSTANDIN = ['Picture', 'Pattern', 'Grey'];&#10;const AUDIOEXT = /\.(wav|wave|mp3|aif|aiff|flac|ogg)$/i;&#10;const sndDb = v =&gt; v &lt; 0.01 ? -60 : Math.round((-40 + 46 * v) * 10) / 10;   // the slider (0..1) as decibels, 0 dB a little past the middle&#10;function sendSound(file) {&#10;    if (file &amp;&amp; state.snd.file) out(3, state.snd.file);&#10;    out(6, state.snd.loop ? 1 : 0);&#10;    out(7, sndDb(state.snd.vol));&#10;}&#10;function setSound(path) {&#10;    state.snd.file = path; state.snd.playing = false;&#10;    out(5);&#10;    sendSound(true);&#10;    rebuild();&#10;}&#10;// ---------- Help: the help page, in the editor, a tab for each part and Prev / Next through it ----------&#10;const HELP = [{&quot;t&quot;: &quot;What Cinemnode is&quot;, &quot;lines&quot;: [&quot;Cinemnode turns a photo into a cinemagraph: you lay moving effects, lights, pictures and masks over your own image. It is an MNodes project of 1920 x 1080 with these nodes:&quot;, &quot;# Node  |  What it does&quot;, &quot;| Cinemnode (Scene)  |  Draws the photo and all effects; see-through where there is nothing&quot;, &quot;| Cinemnode Editor (Script)  |  The editor itself: toolbar, panels, handles, timeline&quot;, &quot;| Background File (File)  |  Picks files: the background, and pictures for Image layers&quot;, &quot;| Colour Code (Text Input)  |  Type a colour code here (#RRGGBB, #RRGGBBAA or 255, 128, 0) for the selected element&quot;, &quot;| Audio In, Audio Out  |  The plugin's sound: into the Scene's In A for the Audio panel, and out again unchanged&quot;, &quot;| Transport  |  The DAW's beat and bar, for Beat and Bar in the Audio panel&quot;, &quot;| Sound Player (Audio Player)  |  Plays the sound file chosen in Properties (Scene)&quot;, &quot;| Sound bands, Level, Bass, Mid, High (Envelope Followers) and their values (Audio To Data)  |  Measure the sound for the Audio panel and hand it to the Scene&quot;, &quot;| Listen volume  |  The sound player's Volume: only what you hear, the measuring gets the full level&quot;, &quot;| MilkDrop (Scene) and MilkDrop Player (Script)  |  Plays MilkDrop presets, under the Cinemnode Scene; a MilkDrop window board shows it&quot;, &quot;| Preset file (Shader Code)  |  Reads preset and shader files for the MilkDrop Player and Shader code boards&quot;, &quot;| Shader code (Text Input)  |  The box at the top for pasted shader code, a text board's words and a scene's name; shown only while you use it&quot;, &quot;| Left key, Right key (Keyboard Key)  |  The arrow keys: the scene before or after&quot;, &quot;Edit and Perform. In Edit mode you see the editor, and the picture fits between the toolbar, the dock and the timeline. Done (at the bottom of the toolbar) goes to Perform: only the picture with its effects, full screen. Double-click the Scene to go back to Edit mode, or send a message to In 1 of the Script (a Widget Toggle, for instance).&quot;]}, {&quot;t&quot;: &quot;The editor&quot;, &quot;lines&quot;: [&quot;The editor is laid out like Photoshop: tools on the left, a dock on the right, and the timeline or the Audio panel across the bottom when you open it (the dock then stops above it).&quot;, &quot;Toolbar (two columns, top to bottom)&quot;, &quot;# Button  |  What it does&quot;, &quot;| Board  |  New board: an area with an effect&quot;, &quot;| Image  |  New picture layer (picks a file)&quot;, &quot;| Mask  |  New mask: a shape where effects do not show&quot;, &quot;| Light  |  New light (double-clicking an empty spot works too)&quot;, &quot;| Copy  |  Copy of the selected element&quot;, &quot;| Delete  |  Removes the selected element&quot;, &quot;| Undo / Redo  |  Back and forth through the last 80 changes&quot;, &quot;| Picture  |  Choose the background photo&quot;, &quot;| Edges  |  Shows the edges in the photo (set up in Properties)&quot;, &quot;| Fit  |  Whole picture in view; shows the zoom level when zoomed in&quot;, &quot;| Timeline  |  Opens or closes the timeline&quot;, &quot;| Audio  |  Opens or closes the Audio panel&quot;, &quot;| Snap  |  Snapping to other elements and the sides, on or off&quot;, &quot;| Clear  |  Removes everything that is not locked (click twice)&quot;, &quot;| Panels  |  Hides or shows the dock&quot;, &quot;| Help  |  Opens this help in the editor: a tab for each part, Prev and Next (or the mouse wheel) to page through, click outside or the cross to close&quot;, &quot;| Done  |  Goes to Perform&quot;, &quot;Dock. On the right are Properties (the settings of the selected element, or the background when nothing is selected) and Layers (all elements, the top one in front). In Layers, click a name to select it; the eye hides, the lock locks, the bin deletes it, and the arrows move a layer forward or back. You can also drag a row up or down to give it another place. Each part folds in by its header; the &lt; / &gt; tab on the edge folds the whole dock away. Layers stays at the bottom of the dock and shows up to 8 rows (fewer, down to 3, when Properties needs the room): scroll it with the wheel or its scrollbar (click above or below the thumb for a page); the selected element scrolls into view by itself. The mouse wheel on Properties scrolls Properties when it is too long; then a strip above Layers says there are more settings below.&quot;, &quot;Background. With nothing selected, Properties has BACKGROUND: Choose... picks the photo (as Picture in the toolbar does), No background takes it away, so the Scene is see-through. Effects that move the picture itself need a background.&quot;, &quot;Edges. Edges in the toolbar shows the edges found in the photo, as a guide for placing boards: green for straight ones, pink for round ones. Properties then has EDGES: All, Straight or Round, Sensitivity and Edge width.&quot;, &quot;While editing. With many elements the picture can get slow while you edit. In Properties of the Scene (nothing selected), set While editing to Only the selected one: in Edit the picture then shows just the element you selected (masks stay), so the shader is small and quick. With nothing selected, and in Perform, it always shows all of them.&quot;, &quot;Zoom and pan. The mouse wheel on an empty spot zooms in and out around the mouse. When zoomed in, drag an empty spot to move the picture. Fit resets it.&quot;, &quot;Editor size. With nothing selected, Properties starts with EDITOR SIZE: 100%, 125% or 150% makes all text, tools and panels of the editor bigger (150% at first). The picture keeps its own size; only the editor around it grows, so there is less room for the picture: Panels (or the tab on the dock) hides the dock when you want the picture bigger.&quot;, &quot;## Scenes&quot;, &quot;A project can hold several scenes: each has its own background and elements. Only the scene you see is in the shader, so the others cost nothing.&quot;, &quot;- With nothing selected, Properties starts with SCENES: click a scene to go to it. + New makes an empty one (same background), Duplicate a copy of this one, Rename opens the box at the top for its name, Delete removes it (click twice).&quot;, &quot;- change: Cut (at once), Via black or Via background (the effects fade to the bare background, then the new scene fades in; best when both scenes share the background), over 0.5, 1, 2 or 4 seconds. The scenes never run at the same time, so a change costs nothing extra.&quot;, &quot;- From the patch: a number on In 7 of the Cinemnode Editor Script (1 for the first scene, 2 for the second...) changes scene, so MIDI, a DAW automation or a sequencer can switch scenes while you perform.&quot;, &quot;- The left and right arrow keys go to the scene before or after (round from the last to the first), with the change you chose. MNodes has to have the keyboard focus; nothing happens while you type in a text box.&quot;, &quot;- Undo works within one scene: changing scene starts it again.&quot;]}, {&quot;t&quot;: &quot;Elements&quot;, &quot;lines&quot;: [&quot;There are four kinds of element. They stack in the order of Layers, except pictures: those always lie on top.&quot;, &quot;## Board&quot;, &quot;An area with an effect, fitted into the photo.&quot;, &quot;- Shape: 4 points give an area in perspective; drag each corner into place (Ctrl + drag scales the whole board). Double-click the edge for an extra point, right-click a point to remove it (3 at least). With more or fewer than 4 points, the effect is spread over a straight box around the points and your shape is cut out of it.&quot;, &quot;- Properties: group and effect, a kind where there is one (Snow or Fireflies for Particles, for instance), colour, Speed, Brightness, the effect's own two sliders, Edge fade and Transparency.&quot;, &quot;- Picture: Off, Surface, Bright parts or Dark parts: the effect follows the photo, for instance only on its bright parts. For effects that move the photo itself, Surface means: stronger where the photo is bright.&quot;, &quot;- Edge fade: 0 is a hard edge; higher fades the effect out towards the inside, at 100% all the way to the middle. It scales with the board. Not on Light box.&quot;, &quot;- Full screen makes the board cover the whole picture. corners: Shape (dragging a corner moves only that corner) or Scale (dragging a corner scales the whole board, as Ctrl + drag does).&quot;, &quot;- Light mode: Light box, Colour glow and Edge glow can blink, twinkle, flicker like a broken tube, pulse, strobe or flicker like a candle, as a light does.&quot;, &quot;## Light&quot;, &quot;A light: a glow at a point. Pick a mode (On, Blink, Twinkle, Broken tube, Pulse, Strobe, Candle, Traffic light, Aircraft, Lens flare), colour, Size, Speed and Strength. The ring around the light shows its reach.&quot;, &quot;## Image&quot;, &quot;A picture as a layer, always on top of the effects. PNG with transparency works.&quot;, &quot;- Drag to move, mouse wheel = bigger or smaller, Shift + wheel = turn.&quot;, &quot;- The corners change the box (Ctrl keeps its proportions).&quot;, &quot;- Fit shows the whole picture in the box, Fill fills the box and cuts off the rest.&quot;, &quot;## Mask&quot;, &quot;A shape where the effects do not show. It starts as a hexagon.&quot;, &quot;- Double-click the edge for another point, right-click a point to remove it.&quot;, &quot;- inside / outside: hide the effects inside the shape, or outside it.&quot;, &quot;- Soft edge for a soft border, Transparency to let the effect partly through.&quot;, &quot;- All effects or Only the ones I pick: then click the boards and lights the mask should block.&quot;, &quot;- Masks work on effects and lights, not on pictures.&quot;, &quot;- Brush: choose Paint or Erase and paint on the picture. Paint adds to the mask, Erase takes from it (also from the shape). Brush size and Brush softness set the brush; Undo stroke takes the last one back, Clear brush all of them. The strokes stay fixed on the picture.&quot;, &quot;- Brush only: the shape no longer masks anything, it is only the handle to select the mask; just the strokes count.&quot;]}, {&quot;t&quot;: &quot;Effects&quot;, &quot;lines&quot;: [&quot;A board first picks a group, then an effect. Effects in Moving picture and some in Film look move the photo itself, so they need a background photo.&quot;, &quot;# Group  |  Effect  |  What it does  |  Own sliders&quot;, &quot;| Signs  |  Plasma  |  Colourful moving pattern  |  -&quot;, &quot;| Signs  |  Text  |  Your own words (Type text: a box opens at the top, up to 3 lines). Kinds: Neon, Neon outline, Hologram, LED dots, Lit panel, Halo letters, LED screen. Motion: Still, Scroll or Switching on. The letters use the Scene's font: set Font File (TTF or OTF) on the Cinemnode Scene node in the Inspector for another look, for example a narrow futuristic font for a Blade Runner sign  |  Glow, Flicker&quot;, &quot;| Signs  |  Glitch  |  Glitching digital screen  |  -&quot;, &quot;| Signs  |  Colour bars  |  Test card with colour bars  |  -&quot;, &quot;| Signs  |  Retro  |  Retro pattern  |  -&quot;, &quot;| Signs  |  Window light  |  Lit window  |  -&quot;, &quot;| Signs  |  Neon edge  |  Neon tube along the edge  |  -&quot;, &quot;| Signs  |  Light box  |  Lit area with a glow around it, with a light mode  |  Glow size&quot;, &quot;| Signs  |  TV glow  |  Flickering light of a TV  |  Flicker, Colours&quot;, &quot;| Signs  |  Custom  |  Your own effect  |  -&quot;, &quot;| Light  |  Colour glow  |  One colour of the photo lights up (pick the spot with the picker)  |  Tolerance, Softness&quot;, &quot;| Light  |  Edge glow  |  The photo's edges light up: Glow, Running or Sparkle  |  Sensitivity, Glow width&quot;, &quot;| Light  |  Light rays  |  Rays of light  |  Light from, Rays&quot;, &quot;| Light  |  Beacon  |  Turning beam: Lighthouse or Searchlight  |  Beam width, Reach&quot;, &quot;| Light  |  Headlight sweep  |  Headlights sweeping over a wall  |  Width, How often&quot;, &quot;| Light  |  Light trails  |  Light trails of traffic: Cars or One colour  |  Traffic, Trail length&quot;, &quot;| Light  |  Firelight  |  A fire's warm light flickering over the room (strongest at the bottom of the board)  |  Flicker, Reach&quot;, &quot;| Light  |  Sun glow  |  A soft glow round the sun in the middle of the board, slowly breathing  |  Size, Pulse&quot;, &quot;| Light  |  Blinds  |  Light through venetian blinds, striped across a wall in the board's perspective, stirring a little (Across, Up and down, Slanting). Needs a background  |  Slats, Softness&quot;, &quot;| Light  |  Passing train  |  Now and then a train passes: its lit windows rush across the wall, with gaps between the carriages (Left to right, Right to left). Needs a background  |  How often, Brightness&quot;, &quot;| Light  |  Moonlight  |  Moonlight that comes and goes as clouds drift past the moon: the picture darkens and lights up again, cool blue (the Colour tints it). Needs a background  |  Darkness, Cloud size&quot;, &quot;| Weather  |  Rain  |  Falling rain  |  (Amount = how much)&quot;, &quot;| Weather  |  Clouds  |  Drifting clouds  |  -&quot;, &quot;| Weather  |  Smoke  |  Smoke plume from the bottom middle  |  -&quot;, &quot;| Weather  |  Steam  |  Rising steam  |  Amount, Width&quot;, &quot;| Weather  |  Fog  |  Fog: Ground fog or Mist bank  |  Thickness, Height&quot;, &quot;| Weather  |  Lightning  |  Lightning: Strike or In the clouds  |  Flash, Bolt&quot;, &quot;| Weather  |  Rain on glass  |  Rain on a window pane: fine beads, and drops that slide down in fits and starts, wiping a clear way through the mist  |  Drops, Mist&quot;, &quot;| Weather  |  Frost  |  Ice growing over a window  |  Grow, Blur&quot;, &quot;| Weather  |  Window drops  |  Drops that land on the window, wander down and vanish  |  Drops, Size&quot;, &quot;| Weather  |  Rainbow  |  Rainbow  |  Strength, Width&quot;, &quot;| Weather  |  Raindrop rings  |  Raindrops landing on a puddle or a street: rings that spread and fade, in the board's perspective (lay the board flat on the ground). In the picture bends it, Light rings only shines. Needs a background  |  Drops, Ring size&quot;, &quot;| Weather  |  Snowstorm  |  Snow driven by gusts of wind, flakes near and far, a white haze in the strongest gusts  |  Amount, Wind&quot;, &quot;| Weather  |  Mist over water  |  Low mist rolling slowly over water, thickest at the bottom of the board  |  Thickness, Height&quot;, &quot;| Water  |  Ripple  |  Rings in water: On top or In the picture  |  Circle size, Strength&quot;, &quot;| Water  |  Water sparkle  |  Glints: Glints or Moon path  |  Amount, Size&quot;, &quot;| Water  |  Shore waves  |  Waves rolling onto a beach, with foam  |  Reach, Foam&quot;, &quot;| Water  |  Caustics  |  Net of light as on a pool floor  |  Strength, Size&quot;, &quot;| Nature  |  Particles  |  Snow, Dust in sunlight, Fireflies, Leaves, Blossom, Hail, Sand, Stars or Bubbles. Snow, dust, fireflies, leaves, blossom and bubbles have depth: near ones are bigger, faster and out of focus. Leaves are autumn coloured (the colour you pick tints them), petals pink to white  |  Amount, Size&quot;, &quot;| Nature  |  Fire  |  Fire: Flames or Rocket  |  Height, Detail&quot;, &quot;| Nature  |  Embers  |  Glowing sparks rising from the bottom of the board and dying out  |  Amount, Height&quot;, &quot;| Nature / Moving picture  |  Flame flicker  |  The flame in the picture itself licks and wavers (a candle, a fireplace)  |  Strength, Size&quot;, &quot;| Sky &amp; space  |  Shooting stars  |  Shooting stars  |  How often, Trail length&quot;, &quot;| Sky &amp; space  |  Star trails  |  Star trails around a point  |  Stars, Arc length&quot;, &quot;| Sky &amp; space  |  Nebula  |  Nebula  |  Strength, Detail&quot;, &quot;| Sky &amp; space  |  Northern lights  |  Aurora  |  Strength, Height&quot;, &quot;| Sky &amp; space  |  Planet bands  |  Bands of a planet  |  Opacity, Bands&quot;, &quot;| Sky &amp; space  |  Birds  |  Small birds crossing the board now and then, flapping  |  How many, Size&quot;, &quot;| Sky &amp; space / Moving picture  |  Cloud drift  |  The picture in the board drifts slowly sideways, seamlessly (put it over the sky only)  |  Direction, Distance&quot;, &quot;| Moving picture  |  Flow  |  The photo flows in one direction (water, clouds)  |  Direction, Length&quot;, &quot;| Moving picture  |  Sway  |  Swaying: Grass, Leaves or Flag  |  Wind, Wave size&quot;, &quot;| Moving picture  |  Heat haze  |  Heat shimmer  |  Strength, Size&quot;, &quot;| Moving picture  |  Reflection  |  Reflection: Water or Wet street  |  Ripples, Clearness&quot;, &quot;| Moving picture  |  Breathe  |  Slow zoom in and out  |  Amount&quot;, &quot;| Moving picture  |  Cloud shadows  |  Cloud shadows passing over  |  Darkness, Cloud size&quot;, &quot;| Moving picture  |  Dappled light  |  Moving light through leaves  |  Strength, Patch size&quot;, &quot;| Moving picture  |  Swell  |  Swell of the sea  |  Rise, Tilt&quot;, &quot;| Moving picture  |  Picture copy  |  A piece of the background from somewhere else, shown in the board: Pick where from, then click the middle of the piece on the picture. As it is, Mirrored or Upside down. Edge fade gives it soft edges and Transparency lets the picture under it through (needs a background)  |  Size, Turn&quot;, &quot;| Moving picture  |  2.5D parallax  |  The picture in the board moves as a layer of its own (Side to side, Push in, Round), so it seems to stand out from the rest. Trace the near thing (a person, a tree) with the board's points; a full-screen board with a small Amount is the far layer. Edge fade softens its edge. Needs a background  |  Amount, Depth&quot;, &quot;| Film look  |  Day / night  |  Grades the picture towards night  |  Night, Blue&quot;, &quot;| Film look  |  Handheld  |  Handheld camera  |  Shake, Zoom&quot;, &quot;| Film look  |  Colour fringe  |  Colour fringes  |  Strength, Wobble&quot;, &quot;| Film look  |  Bloom  |  Bright parts glow  |  Glow, Size&quot;, &quot;| Film look  |  Film grain  |  Film grain  |  Amount, Grain size&quot;, &quot;| Film look  |  Vignette  |  Dark corners  |  Amount, Breathe&quot;, &quot;| Film look  |  Old film  |  Old film with scratches  |  Amount, Scratches&quot;, &quot;| Film look  |  Lens flare  |  A bright light in the middle of the board flaring in the lens, with ghosts: Round or Anamorphic (a long blue streak)  |  Size, Ghosts&quot;, &quot;| Film look  |  Light leak  |  Light leaking into the camera: glows from the edges, slowly moving: Warm or Rainbow  |  Strength, Drift&quot;, &quot;| Film look  |  CRT screen  |  The picture on an old TV: bent glass, lines, red green and blue, a little flicker (needs a background)  |  Strength, Curve&quot;, &quot;| Film look  |  Pixelate  |  The picture in blocks with fewer colours: Pixels, Halftone dots or Round tiles (needs a background)  |  Block size, Fewer colours&quot;, &quot;| Film look  |  Kaleidoscope  |  The picture mirrored round the middle of the board, or left onto right, or top onto bottom (needs a background)  |  Segments, Turning&quot;, &quot;| Film look  |  Colour grade  |  A film look over the picture: Teal &amp; orange, Bleach bypass, Cold blue, Warm sunset, Black &amp; white, Faded film. A full-screen board grades all of it  |  Strength, Contrast&quot;, &quot;| Film look  |  Focus pull  |  The focus shifts: this part goes soft and sharp again. Two boards, one Sharp first and one Soft first, make a focus pull from one to the other. Needs a background  |  Blur, Hold&quot;, &quot;| Music &amp; stage  |  Spectrum  |  The sound's spectrum, low notes on the left: Bars, LED blocks, Mirrored or Line  |  Bars, Height&quot;, &quot;| Music &amp; stage  |  Oscilloscope  |  The waveform as a glowing line: Line or Circle  |  Height, Glow&quot;, &quot;| Music &amp; stage  |  Lasers  |  Laser beams through haze, sweeping, brighter on the kick: Fan, Crossing or Colours  |  Beams, Sweep&quot;, &quot;| Music &amp; stage  |  Moving heads  |  Stage spots along the top of the board, their beams swinging: One colour or Colours  |  Lights, Swing&quot;, &quot;| Music &amp; stage  |  Mirror ball  |  Spots of a mirror ball going round over the walls: One colour or Colours  |  Spots, Spot size&quot;, &quot;| Music &amp; stage  |  Strobe  |  Flashes: On the beat (1 to 8 a beat, or on the kick when the DAW is stopped), Steady or Random  |  Speed, Flash length&quot;, &quot;| Music &amp; stage  |  Beat zoom  |  The picture in the board bumps towards you: On the kick or With the level  |  Strength&quot;, &quot;| Music &amp; stage  |  Stage wash  |  Coloured stage light washing up or down the board, breathing with the music: From below or From above  |  Strength, Colour change&quot;, &quot;| Music &amp; stage  |  Beat rings  |  Rings going out from the middle, one each beat  |  Size, Thickness&quot;, &quot;| Music &amp; stage  |  Level meter  |  A meter of LEDs showing how loud it is: Up or Across  |  Segments, Glow&quot;, &quot;&quot;, &quot;MilkDrop window. The group MilkDrop has one effect, MilkDrop window. It makes the board see-through, so the MilkDrop Player's own Scene under Cinemnode shows in the board's shape. Edge fade, Transparency and masks work as on any board, and elements above it in Layers stay in front. In Properties:&quot;, &quot;- Add preset... picks a .milk or .milk2 file and adds it to the playlist. The player checks it and says how well it can play: supported, plays adjusted, only in part, or only in MilkDrop3, with the reasons below.&quot;, &quot;- Playlist: click a preset to play it, the arrows change the order, the bin takes it out; &lt; Prev and Next &gt; step through the list. The dot shows how well it played: green supported, yellow adjusted, orange in part, red only in MilkDrop3.&quot;, &quot;- Sensitivity (how strongly it reacts to the sound), Speed and Brightness; the middle is as MilkDrop plays it, and they apply to every preset.&quot;, &quot;- Textures folder...: pick any picture in MilkDrop's textures folder once, so presets find their pictures.&quot;, &quot;- Preset 1 / Preset 2 for a double (.milk2) preset, and, only when a preset asks for pictures the folder does not have, missing pictures (Picture, Pattern or Grey) with their names.&quot;, &quot;In Edit, the window shows the player where the zoomed view would show a chequer. The player's picture does not zoom with the view; in Perform both line up.&quot;, &quot;&quot;, &quot;Shader code. The group Your own has the effect Shader code: a shader of your own, written as on Shadertoy, with void mainImage(out vec4 fragColor, in vec2 fragCoord). It runs in the board's shape: iResolution is the board's size in pixels, iTime its time (Speed sets how fast), iChannel0 the sound on In A, iChannel1 to 3 the background picture; iMouse stays still. Its own names are given a tag, so they never clash with Cinemnode's or another shader's.&quot;, &quot;ISF shaders (.fs files, as VDMX and Resolume use them) work too: load or paste one. Its settings become the board's sliders (up to 8: a number, switch or list takes one, a point two, a colour three), starting where the shader wants them. An image input is the background picture, an audio input the sound on In A. Shaders with passes or pictures of their own are not run; the panel says so.&quot;, &quot;- Load file... reads a .glsl or .frag file, or an ISF .fs file. Saving that file again brings the new code in by itself, for live editing.&quot;, &quot;- Or paste it: press Paste code in Properties and a wide box opens at the top of the picture. Paste the code into it and press Use code; the box closes by itself (Close box closes it without using it).&quot;, &quot;- P1 to P8: Cinemnode's own P are the board's corners, so a shader's P1-P8 become sliders of the board. Only the ones the code uses get one, named from its comments where it says so (for example // P2 cell size), otherwise just P2. A new value goes in when you stop moving the slider. These P's also show up in the Timeline and the Audio panel, so they can be animated or follow the sound.&quot;, &quot;- Kind: Solid, Black is see-through (dark parts let the picture show), or Added light.&quot;, &quot;- One pass only (no Buffer A to D). If the code has a mistake, the Scene keeps its last good shader and shows the error.&quot;]}, {&quot;t&quot;: &quot;Menu, copying and colours&quot;, &quot;lines&quot;: [&quot;Right-click menu. Right-click an element for its menu:&quot;, &quot;# Option  |  On  |  What it does&quot;, &quot;| Make square  |  Board (4 points)  |  A straight square, as big and as turned as it was&quot;, &quot;| Make circle / Make hexagon  |  Board or mask  |  A round shape (12 points, a little rough) or a hexagon, as big and as turned as it was; drag its points after&quot;, &quot;| Mirror X / Mirror Y  |  Board or mask  |  The shape mirrored left-right or up-down round its middle; the effect in it stays the right way round&quot;, &quot;| Make rectangle  |  Board (4 points)  |  Takes the perspective off, keeps width and height&quot;, &quot;| Straighten  |  Board (4 points)  |  Level again&quot;, &quot;| Back to 4 corners  |  Board (other shape)  |  Back to a board with 4 corners&quot;, &quot;| Replace picture, No turn, Fit / Fill  |  Image  |  Other file, no turn, Fit or Fill&quot;, &quot;| Hide the effects inside/outside, Mask all effects  |  Mask  |  Invert, or mask all effects again&quot;, &quot;| Copy size  |  All  |  Remembers size, turn and shape&quot;, &quot;| Paste size  |  All  |  Same width and height; its own turn and shape stay&quot;, &quot;| Paste size and shape  |  Board, Image, Mask  |  Takes the turn and shape as well&quot;, &quot;| Duplicate, Bring to front, Send to back  |  All  |  Copy, to the front, to the back&quot;, &quot;| Hide, Lock, Delete  |  All  |  Hide, lock in place, remove&quot;, &quot;Copy and Paste work between all kinds: a light counts as a square as big as its ring; a mask pasted onto a board (size and shape) gives the board the same points.&quot;, &quot;Undo and Redo in the toolbar remember the last 80 changes. Selecting an element is not a change; a run of wheel turns is one step. Ctrl+Z does not work, because the Script gets no keys.&quot;, &quot;Colours. Pick a colour from the row, or switch between RGB and HSV sliders. Type a code in the Colour Code field: #RGB, #RGBA, #RRGGBB, #RRGGBBAA, or 255, 128, 0 (with a fourth number for alpha). Keep your own colours in the palette; right-click a palette colour to remove it.&quot;]}, {&quot;t&quot;: &quot;Timeline&quot;, &quot;lines&quot;: [&quot;The timeline animates the selected element in a loop, with straight lines between the keys. Open it with Timeline in the toolbar.&quot;, &quot;- A white **play head** runs across the graph: where the loop is now, on the same clock as the picture.&quot;, &quot;- Select an element and pick a property in the list on the left. A round dot means: this property is animated.&quot;, &quot;- Click Animate (or the graph) to start.&quot;, &quot;- Click in the graph for a key, drag a key to move it, right-click a key to remove it. The start and end of the loop move together, so the loop never jumps.&quot;, &quot;- Set with loop how long one round takes (0.5 to 30 seconds).&quot;, &quot;# Element  |  What you can animate&quot;, &quot;| Board  |  Transparency, Brightness, the effect's own two sliders, Edge fade, Red, Green, Blue&quot;, &quot;| Light  |  Transparency, Size, Strength, Across, Down, Red, Green, Blue&quot;, &quot;| Image  |  Transparency, Across, Down, Size, Turn&quot;, &quot;| Mask  |  Transparency&quot;, &quot;An animated property is locked in Properties (with a link to the timeline), and dragging or the mouse wheel does not change it either. The animation plays in Perform too.&quot;, &quot;## Cables: follow another element&quot;, &quot;In Edit every board, light and picture has small round jacks: **orange for the sound** and **blue for the timeline**, an in on the left and an out on the right.&quot;, &quot;- Drag from the out of A to the in of B: B now follows A (its sound settings, or its timeline keys and loop). A blue cable also puts B in step with A: B takes A's speed and rhythm, so a Blink or Pulse goes on and off together (B's Speed slider is then locked). Change A and B changes with it. A chain A, B, C works; a cable that would go round in a circle is refused.&quot;, &quot;- Right-click a cable, or the in of B, to cut it. The Timeline or Audio panel of B says what it follows, with **Go to** and **Cut the cable**.&quot;, &quot;- It costs nothing extra: B works out the same as A.&quot;, &quot;- To hide the jacks and cables: with nothing selected, Properties has **CABLES - Show / Hide**. Hidden, they still work.&quot;]}, {&quot;t&quot;: &quot;Audio&quot;, &quot;lines&quot;: [&quot;The Audio button opens a panel under the picture, in the same place as the timeline. Each setting of the selected board, light or mask (the same ones the timeline offers) can follow a part of the sound:&quot;, &quot;- Level: how loud the sound is overall&quot;, &quot;- Bass, Mid, High: a part of the spectrum&quot;, &quot;- Beat: a pulse on every beat of the DAW, fading until the next one&quot;, &quot;- Bar: a ramp from 0 to 1 over each bar of the DAW&quot;, &quot;The slider next to it says how far the sound moves the setting: to the right it goes up, to the left down, from where its own slider in Properties puts it. Sensitivity (on the right) sets how loud the sound must be before it moves anything. The meters show what comes in now.&quot;, &quot;The sound comes from the plugin's audio input (Audio In, wired to the Scene's In A, and passed on unchanged to Audio Out). Beat and Bar come from the Transport node (following the DAW), and only move while the DAW plays. Pictures (images) cannot follow the sound yet. The reaction plays in Perform too.&quot;, &quot;Sound player. With nothing selected, Properties has a SOUND part under BACKGROUND: Choose sound... loads a WAV, MP3, AIFF, FLAC or OGG file, with Play, Stop, Loop and Volume. The file plays through the plugin's output (so you hear it) and goes into the Scene's In A together with the plugin's input, so the Audio panel follows it.&quot;, &quot;- Level, Bass, Mid and High are measured in the patch by Envelope Followers (the nodes Sound bands, Level, Bass, Mid, High), the same way the meters in the panel show them. A setting that follows the sound is locked in Properties, with an orange dot: click it to open the Audio panel.&quot;, &quot;- The sound player's Volume is only what you hear (a Listen volume node after the player): the Audio panel and the effects always get the file at its full level, so turning it down does not stop them moving.&quot;]}, {&quot;t&quot;: &quot;Mouse and keys&quot;, &quot;lines&quot;: [&quot;# Where  |  Action  |  Result&quot;, &quot;| Element  |  Drag  |  Move (Alt: no snapping)&quot;, &quot;| Element  |  Mouse wheel  |  Bigger or smaller&quot;, &quot;| Element  |  Shift + mouse wheel  |  Turn&quot;, &quot;| Element  |  Right-click  |  Menu&quot;, &quot;| Corner or point  |  Drag  |  Move it&quot;, &quot;| Board corner  |  Ctrl + drag  |  Scale the whole board&quot;, &quot;| Image corner  |  Ctrl + drag  |  Scale the box, keeping its proportions&quot;, &quot;| Edge of a board or mask  |  Double-click  |  Add a point&quot;, &quot;| Point of a board or mask  |  Right-click  |  Remove the point&quot;, &quot;| Empty spot  |  Double-click  |  New light&quot;, &quot;| Empty spot  |  Mouse wheel  |  Zoom&quot;, &quot;| Empty spot (zoomed in)  |  Drag  |  Move the picture&quot;, &quot;| Empty spot  |  Click  |  Deselect&quot;, &quot;| Scene in Perform  |  Double-click  |  Back to Edit mode&quot;, &quot;| Scenes  |  Left / right arrow  |  The scene before / after&quot;]}, {&quot;t&quot;: &quot;Limits&quot;, &quot;lines&quot;: [&quot;- Pictures always lie on top of all effects; masks do not work on them.&quot;, &quot;- On a board with more or fewer than 4 points, an effect that draws the edge (Neon edge) follows the box, not the cut shape.&quot;, &quot;- Ctrl+Z and other keys do not work in the editor; use Undo and Redo in the toolbar.&quot;, &quot;- Shader code runs one pass: Shadertoy shaders with Buffer A to D, and ISF shaders with passes or pictures of their own, are not run.&quot;, &quot;- MilkDrop window: the player's picture does not zoom with the view in Edit; in Perform both line up.&quot;, &quot;- Filmstrips are gone (tried in 2.0 to 2.5, removed in 2.6).&quot;]}, {&quot;t&quot;: &quot;Credits&quot;, &quot;lines&quot;: [&quot;Cinemnode is made by Darc Sector.&quot;, &quot;&quot;, &quot;The MilkDrop window plays MilkDrop presets with the MilkDrop Player, an independent re-implementation of the preset format: it includes no MilkDrop code. MilkDrop is by Ryan Geiss (Nullsoft); MilkDrop3 is by Maxim Volskiy and contributors (BSD 3-Clause). Cinemnode is not affiliated with or endorsed by the MilkDrop authors.&quot;, &quot;&quot;, &quot;No presets or textures come with Cinemnode. The ones you load belong to their own makers, and their own licences apply.&quot;]}, {&quot;t&quot;: &quot;Versions&quot;, &quot;lines&quot;: [&quot;# Version  |  New&quot;, &quot;| 8.9  |  Editor size 100%, 125% or 150% (150% at first): all text, tools and panels bigger. Tools in two columns; the timeline and Audio panel go across the bottom, under the dock&quot;, &quot;| 8.8  |  Shader code also takes ISF shaders (.fs): their settings become the board's sliders&quot;, &quot;| 8.7  |  The demos of 8.6 taken out again&quot;, &quot;| 8.5  |  Nine new effects: Blinds, Passing train, Moonlight, Raindrop rings, Snowstorm, Mist over water, Colour grade, Focus pull, 2.5D parallax&quot;, &quot;| 8.4  |  The Raven effect taken out again&quot;, &quot;| 8.3  |  New effect Raven (Nature): a perched raven as a silhouette or a shadow on the wall, that moves a little&quot;, &quot;| 8.2  |  Faster shader: only the effects in use go in (builds about 40% quicker), boards skip pixels outside them&quot;, &quot;| 8.1  |  Faster: clicking through elements builds the shader once, a moment later; the MilkDrop list scrolls without redrawing the editor&quot;, &quot;| 8.0  |  Right-click a board or mask: Mirror X and Mirror Y&quot;, &quot;| 7.9  |  Right-click a board or mask: Make circle (12 points) or Make hexagon&quot;, &quot;| 7.8  |  Joined by a timeline cable, elements also blink and pulse in step (same speed and rhythm)&quot;, &quot;| 7.7  |  Layers makes room for Properties (down to 3 rows); a strip says when there are more settings below&quot;, &quot;| 7.6  |  Layers stays at the bottom of the dock, with its own scrollbar; the wheel scrolls it quickly&quot;, &quot;| 7.5  |  Properties: thin lines between the blocks&quot;, &quot;| 7.4  |  A play head on the timeline&quot;, &quot;| 7.3  |  CABLES in Properties (nothing selected): show or hide the jacks and cables&quot;, &quot;| 7.2  |  The cables between elements follow zooming and panning&quot;, &quot;| 7.1  |  The sound levels reach the Scene as values (Audio To Data) instead of CV&quot;, &quot;| 7.0  |  The sound player's Volume starts at 0 dB&quot;, &quot;| 6.9  |  Turning the sound player down no longer stops the Audio panel: the volume is only for listening, the analysis gets the full level&quot;, &quot;| 6.8  |  The Audio panel works: Level, Bass, Mid and High now measured in the patch (Envelope Followers into P55-P58), and a setting that follows the sound is locked in Properties&quot;, &quot;| 6.7  |  Cables between elements: orange jacks follow another's sound, blue jacks its timeline&quot;, &quot;| 6.6  |  The right arrow key works too (the Script has 8 inputs at most: both keys now come in on In 7 and In 8)&quot;, &quot;| 6.5  |  Export and Import taken out again (the scenes stay saved with the project, Ctrl+S)&quot;, &quot;| 6.3  |  The arrow keys for scenes, made surer: two Keyboard Key nodes (Left key, Right key) instead of one Keyboard&quot;, &quot;| 6.2  |  The left and right arrow keys change scene&quot;, &quot;| 6.1  |  Scenes: several in one project, changed with Cut, Via black or Via background, from Properties or a number on In 7 of the Script&quot;, &quot;| 6.0  |  Masks: paint them with a brush (Paint, Erase, size, softness, Undo stroke), or Brush only&quot;, &quot;| 5.9  |  Picture copy (Moving picture): a piece of the background from elsewhere in a board, with Edge fade and Transparency, Size and Turn&quot;, &quot;| 5.8  |  Sliders: room for longer names; a name too long is cut short with ... (the whole name shows when you rest the mouse on the slider)&quot;, &quot;| 5.7  |  Film look: Lens flare, Light leak, CRT screen, Pixelate (pixels, halftone, round tiles) and Kaleidoscope (or mirror)&quot;, &quot;| 5.6  |  Particles made realistic: Snow, Dust in sunlight, Fireflies, Leaves and Blossom in five depths with real shapes and motion, and new Bubbles&quot;, &quot;| 5.5  |  Text: type your own words (up to 3 lines), in 7 kinds (Neon, Neon outline, Hologram, LED dots, Lit panel, Halo letters, LED screen) with Still, Scroll or Switching on&quot;, &quot;| 5.4  |  Shader code: the paste box opens with Paste code, as a wide strip at the top, and closes once the code is used&quot;, &quot;| 5.3  |  Rain on glass made realistic (fine beads, sliding drops that wipe the mist). New group Music &amp; stage: Spectrum, Oscilloscope, Lasers, Moving heads, Mirror ball, Strobe, Beat zoom, Stage wash, Beat rings, Level meter&quot;, &quot;| 5.2  |  Shader code: its P1-P8 can be animated on the Timeline and follow the sound in the Audio panel&quot;, &quot;| 5.1  |  Shader code: a paste box on the panel (Use code), and the P1-P8 a shader uses become sliders on the board, named from its comments&quot;, &quot;| 5.0  |  Shader code: your own Shadertoy-style shader on a board, from a file (live while you save) or pasted&quot;, &quot;| 4.9  |  Credits page in the help&quot;, &quot;| 4.8  |  MilkDrop: a playlist (add, play, order, Prev / Next) and Sensitivity, Speed and Brightness (MilkDrop Player v0.5)&quot;, &quot;| 4.7  |  All buttons fit their text: chips grow with it, fixed buttons make the text a little smaller where needed&quot;, &quot;| 4.6  |  MilkDrop Player v0.4: random pictures come from your textures folder, the two most used pictures get the real ones; missing pictures choice only when something is missing&quot;, &quot;| 4.5  |  MilkDrop window: a board that shows the MilkDrop Player (v0.3, its own Scene under Cinemnode), with Load preset and a check of how well each preset plays&quot;, &quot;| 4.4  |  Layer list: a dragged row really stays under the mouse and passes over the others&quot;, &quot;| 4.3  |  A dragged row in the layer list stays right under the mouse&quot;, &quot;| 4.2  |  Dragging a row in the layer list: the others make room, and it lands where you let go&quot;, &quot;| 4.1  |  Delete and drag to a new place in the layer list; While editing: Only the selected one (Scene)&quot;, &quot;| 4.0  |  Choosing another element no longer briefly shows the one chosen before, also with many elements&quot;, &quot;| 3.9  |  Help in the editor: round dots for points, the Darc Sector logo, tables in neat columns&quot;, &quot;| 3.8  |  Layout fixes: corners label, timeline tabs, Image hint and Audio notes no longer overlap or run off&quot;, &quot;| 3.7  |  Help in the editor: this page, with tabs and Prev / Next&quot;, &quot;| 3.6  |  Sound player in Properties (Scene): a file to play, heard and followed by the Audio panel&quot;, &quot;| 3.5  |  Audio panel: settings follow the sound (Level, Bass, Mid, High) or the DAW's Beat and Bar. Six new effects: Firelight, Sun glow, Embers, Flame flicker, Birds, Cloud drift&quot;, &quot;| 3.4  |  All editor text 25% bigger&quot;, &quot;| 3.3  |  Faster updates with many elements: boards and lights share one loop, so each kind of effect is in the shader once; masks are worked out only where something is drawn&quot;, &quot;| 3.2  |  Bigger, brighter editor text: hints, toolbar, section labels and sliders (values now sit right of the slider)&quot;, &quot;| 3.1  |  Bigger, brighter names on the picture and in the layer list&quot;, &quot;| 3.0  |  Edge fade per board&quot;, &quot;| 2.9  |  Dragging the picture no longer stutters with locked layers&quot;, &quot;| 2.8  |  Boards with more or fewer than 4 points&quot;, &quot;| 2.7  |  Copy and Paste size between all kinds of element&quot;, &quot;| 2.6  |  Filmstrips removed; a mask set to outside stays clickable&quot;, &quot;| 1.9  |  Masks&quot;, &quot;| 1.8  |  Picture layers&quot;, &quot;| 1.7  |  Right-click menu, Make square, Copy and Paste size, Undo and Redo&quot;, &quot;| 1.6  |  Window drops, new Shore waves, Picture options for all effects&quot;, &quot;| 1.5  |  Many new effects, in groups&quot;, &quot;| 1.4  |  Animated properties locked, &lt; and &gt; for the dock&quot;, &quot;| 1.3  |  Animate everything of an element, RGB too&quot;, &quot;| 1.2  |  Timeline for transparency in a loop&quot;, &quot;| 1.1  |  Twelve cinemagraph effects&quot;, &quot;| 1.0  |  Scene Kit becomes Cinemnode, in Darc Sector colours&quot;]}];&#10;const LOGO = 'C:/Users/Danny/Downloads/Cinemnode logo.png';   // the Darc Sector logo, at the top of the help   // [{ t: title, lines: [...] }]: '## ' a heading, '- ' a point, '# ' a table's header, '| ' a row (cells split by '  |  ')&#10;let help = null;   // { tab, screen } while it is open&#10;let HW, HH, HX, HY, HBODY;&#10;function helpSize() { HW = Math.min(1320, W - 40); HH = Math.min(900, H - 40); HX = (W - HW) / 2; HY = (H - HH) / 2; HBODY = HH - 232; }&#10;helpSize();&#10;function wrap(text, size, width) {   // lines of at most width, by a guess of the letters' width&#10;    const cw = size * 0.53, max = Math.max(8, Math.floor(width / cw)), out = [];&#10;    let line = '';&#10;    for (const w of String(text).split(' ')) {&#10;        if (line &amp;&amp; (line + ' ' + w).length &gt; max) { out.push(line); line = w; }&#10;        else line = line ? line + ' ' + w : w;&#10;    }&#10;    if (line) out.push(line);&#10;    return out.length ? out : [''];&#10;}&#10;function helpScreens(tab) {   // the tab's lines laid out, cut into screens that fit the body: [[{x, y, text, size, fill}...], ...]&#10;    const screens = [[]], BW = HW - 80;&#10;    let y = 0;&#10;    const put = (rows, h, gap) =&gt; {   // rows: items with their own y from 0; h their height&#10;        if (y + h &gt; HBODY &amp;&amp; y &gt; 0) { screens.push([]); y = 0; }&#10;        rows.forEach(o =&gt; screens[screens.length - 1].push(Object.assign({}, o, { y: y + o.y })));&#10;        y += h + gap;&#10;    };&#10;    for (const l of HELP[tab].lines) {&#10;        if (l.startsWith('## ')) put([{ x: 0, y: 0, text: l.slice(3), size: 22, fill: ACC }], 30, 6);&#10;        else if (l.startsWith('- ')) { const w = wrap(l.slice(2), 18, BW - 28); put(w.map((t, i) =&gt; ({ x: 28, y: i * 26, text: t, size: 18, fill: '#e4def5' })).concat([{ x: 8, y: 0, dot: true }]), w.length * 26, 4); }&#10;        else if (l.startsWith('# ')) { const c = l.slice(2).split('  |  '); put(c.map((t, i) =&gt; ({ x: HCOL(c.length, i), y: 0, text: t, size: 15, fill: '#9a94b8' })), 24, 2); }&#10;        else if (l.startsWith('| ')) {&#10;            const c = l.slice(2).split('  |  ');&#10;            if (c.length &gt; 3) {   // the effects: group, name | what it does | its sliders&#10;                const w = wrap(c[2] + (c[3] ? '  (' + c[3] + ')' : ''), 17, BW - 390);&#10;                put([{ x: 0, y: 0, text: c[0], size: 15, fill: '#9a94b8' }, { x: 190, y: 0, text: c[1], size: 18, fill: '#c9a6ff' }]&#10;                    .concat(w.map((t, i) =&gt; ({ x: 390, y: i * 24, text: t, size: 17, fill: '#e4def5' }))), Math.max(26, w.length * 24), 4);&#10;            } else {   // two or three columns, each wrapped in its own width&#10;                const xs = c.map((t, i) =&gt; HCOL(c.length, i)), rows = [];&#10;                let n = 1;&#10;                c.forEach((t, i) =&gt; {&#10;                    const w = wrap(t, i ? 17 : 18, (i &lt; c.length - 1 ? xs[i + 1] : BW) - xs[i] - 16);&#10;                    n = Math.max(n, w.length);&#10;                    w.forEach((tt, k) =&gt; rows.push({ x: xs[i], y: k * 24, text: tt, size: i ? 17 : 18, fill: i ? '#e4def5' : '#c9a6ff' }));&#10;                });&#10;                put(rows, Math.max(26, n * 24), 4);&#10;            }&#10;        } else { const w = wrap(l, 18, BW); put(w.map((t, i) =&gt; ({ x: 0, y: i * 26, text: t, size: 18, fill: '#e4def5' })), w.length * 26, 12); }&#10;    }&#10;    return screens;&#10;}&#10;const HCOL = (n, i) =&gt; n &gt; 3 ? [0, 190, 390, 900][i] : n === 3 ? [0, 360, 600][i] : [0, 300][i];   // where a table's columns start&#10;function drawHelp() {&#10;    const sheet = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#050610b0', interactive: true });&#10;    sheet.on('click', e =&gt; { e.stop(); help = null; rebuild(); });&#10;    sheet.on('wheel', e =&gt; e.stop());&#10;    const g = layer.group({ x: HX, y: HY });&#10;    const box = g.rect({ w: HW, h: HH, radius: 14, fill: '#14121f', stroke: ACC, strokeWidth: 1.5, interactive: true, shadow: { color: '#000000c0', y: 8, blur: 30 } });&#10;    box.on('click', e =&gt; e.stop());&#10;    box.on('wheel', e =&gt; { e.stop(); step(e.delta &gt; 0 ? 1 : -1); });&#10;    g.text({ x: 32, y: 34, text: 'CINEMNODE HELP', size: 22, baseline: 'middle', fill: ACC, interactive: false });&#10;    g.text({ x: 248, y: 35, text: 'by Darc Sector', size: 16, baseline: 'middle', fill: '#9a94b8', interactive: false });&#10;    g.image({ x: HW - 170, y: 8, w: 104, h: 95, src: LOGO, fit: 'contain', interactive: false });&#10;    const x = g.group({ x: HW - 52, y: 14, cursor: 'pointer', tooltip: 'Close' });&#10;    x.rect({ w: 38, h: 38, radius: 8, fill: '#1a1628' });&#10;    x.line({ x1: 12, y1: 12, x2: 26, y2: 26, width: 2.5, stroke: '#f1ecff', interactive: false });&#10;    x.line({ x1: 26, y1: 12, x2: 12, y2: 26, width: 2.5, stroke: '#f1ecff', interactive: false });&#10;    x.on('click', e =&gt; { e.stop(); help = null; rebuild(); });&#10;    // the tabs, in rows as they fit&#10;    let tx = 32, ty = 62;&#10;    HELP.forEach((p, i) =&gt; {&#10;        const bw = textW(p.t, 18) + 26;&#10;        if (tx + bw &gt; HW - 180) { tx = 32; ty += 36; }   // (the logo sits on the right)&#10;        button(g, tx, ty, bw, p.t, () =&gt; { help.tab = i; help.screen = 0; rebuild(); }, i === help.tab);&#10;        tx += bw + 6;&#10;    });&#10;    const top = ty + 50;&#10;    HBODY = HH - 58 - 14 - top - 30;   // v8.9: the body between the tabs and Prev / Next&#10;    g.line({ x1: 32, y1: top - 10, x2: HW - 32, y2: top - 10, width: 1, stroke: '#2f2850', interactive: false });&#10;    const screens = helpScreens(help.tab);&#10;    help.screen = Math.min(help.screen, screens.length - 1);&#10;    screens[help.screen].forEach(o =&gt; o.dot ? g.circle({ x: 40 + o.x + 6, y: top + 18 + o.y, r: 4, fill: ACC, interactive: false })   // a point: a round dot&#10;                                           : g.text({ x: 40 + o.x, y: top + 18 + o.y, text: o.text, size: o.size, baseline: 'middle', fill: o.fill, interactive: false }));&#10;    // Prev / Next: through the screens of a tab, then on to the next tab&#10;    const step = d =&gt; {&#10;        const n = helpScreens(help.tab).length;&#10;        if (d &gt; 0) { if (help.screen &lt; n - 1) help.screen++; else if (help.tab &lt; HELP.length - 1) { help.tab++; help.screen = 0; } }&#10;        else { if (help.screen &gt; 0) help.screen--; else if (help.tab &gt; 0) { help.tab--; help.screen = helpScreens(help.tab).length - 1; } }&#10;        rebuild();&#10;    };&#10;    const first = help.tab === 0 &amp;&amp; help.screen === 0, last = help.tab === HELP.length - 1 &amp;&amp; help.screen === screens.length - 1;&#10;    const by = HH - 58;&#10;    g.line({ x1: 32, y1: by - 14, x2: HW - 32, y2: by - 14, width: 1, stroke: '#2f2850', interactive: false });&#10;    button(g, 32, by, 130, '&lt; Prev', () =&gt; { if (!first) step(-1); }, false);&#10;    button(g, HW - 162, by, 130, 'Next &gt;', () =&gt; { if (!last) step(1); }, !last);&#10;    g.text({ x: HW / 2, y: by + 15, text: HELP[help.tab].t + (screens.length &gt; 1 ? '  -  ' + (help.screen + 1) + ' of ' + screens.length : '') + '      (' + (help.tab + 1) + ' / ' + HELP.length + ')',&#10;             size: 16, align: 'center', baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;}&#10;&#10;let wantSound = false;   // the next file from the File node is a sound for the player&#10;let wantImage = false;   // the next file from the File node is a picture layer, not the background&#10;function addImage(path) {&#10;    const it = { id: state.next++, type: 'image', src: path, x: 0.5, y: 0.5, w: 0.3, h: 0.3 * W / H, scale: 0.5, rot: 0.5, transp: 0, fit: 0, 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.pts)&#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('press', () =&gt; { wheeling = false; });&#10;c.on('release', () =&gt; { dropRow(); checkpoint(); if (tlDirty) { tlDirty = false; sendCode(); } if (pending) { pending = false; rebuild(); } });&#10;&#10;function select(id) {&#10;    if (id !== state.sel) state.brush = 0;   // the brush is for the mask it was picked up on&#10;    sure = false;&#10;    hexTyping = null;&#10;    state.sel = id;&#10;    if (state.sel !== liveSel) codePend = 8;   // the new shader a moment later (onTick)&#10;    rebuild();&#10;}&#10;&#10;function centre(it) {&#10;    if (!it.pts)&#10;        return [it.x, it.y];&#10;    return [it.pts.reduce((a, p) =&gt; a + p[0], 0) / it.pts.length, it.pts.reduce((a, p) =&gt; a + p[1], 0) / it.pts.length];&#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;// ---------- undo and redo ----------&#10;// every change is one step back: the elements as they were, kept as text (choosing another one is no change); a run&#10;// of wheel turns on one element is one step&#10;let past = [], future = [], now = null, wheeling = false;&#10;const snapshot = () =&gt; JSON.stringify(state.items);&#10;function checkpoint() {&#10;    const s = snapshot();&#10;    if (now !== null &amp;&amp; s !== now) {&#10;        past.push(now);&#10;        if (past.length &gt; 80)&#10;            past.shift();&#10;        future = [];&#10;    }&#10;    now = s;&#10;}&#10;function wheelStep() {&#10;    if (!wheeling) { checkpoint(); wheeling = true; }&#10;}&#10;function restore(s) {&#10;    state.items = JSON.parse(s);&#10;    if (!state.items.some(t =&gt; t.id === state.sel))&#10;        state.sel = 0;&#10;    now = s;&#10;    menu = null; sure = false; hexTyping = null; wheeling = false;&#10;    sendCode();&#10;    rebuild();&#10;}&#10;function undo() { checkpoint(); if (past.length) { future.push(now); restore(past.pop()); } }&#10;function redo() { checkpoint(); if (future.length) { past.push(now); restore(future.pop()); } }&#10;&#10;// ---------- a board's shape ----------&#10;// a board as its middle, its turn (radians, along its top and bottom edges) and its width and height, in pixels&#10;function frameOf(it) {&#10;    const P = it.pts.map(p =&gt; [p[0] * W, p[1] * H]);&#10;    const d = (a, b) =&gt; Math.hypot(b[0] - a[0], b[1] - a[1]);&#10;    const [cx, cy] = centre(it);&#10;    const a = Math.atan2(P[1][1] - P[0][1] + P[2][1] - P[3][1], P[1][0] - P[0][0] + P[2][0] - P[3][0]);&#10;    return { cx: cx * W, cy: cy * H, a: a, w: (d(P[0], P[1]) + d(P[3], P[2])) / 2, h: (d(P[0], P[3]) + d(P[1], P[2])) / 2 };&#10;}&#10;// the four corners the effect is spread over: a 4-point board's own; with more or fewer points, the straight box round&#10;// them, turned by it.qa (radians: the board's turn when it got its fifth point)&#10;function boardQuad(it) {&#10;    if (it.pts.length === 4)&#10;        return it.pts;&#10;    const a = it.qa || 0, ca = Math.cos(a), sa = Math.sin(a), [cx, cy] = centre(it);&#10;    const L = it.pts.map(p =&gt; { const x = (p[0] - cx) * W, y = (p[1] - cy) * H; return [x * ca + y * sa, -x * sa + y * ca]; });&#10;    const x0 = Math.min(...L.map(l =&gt; l[0])), x1 = Math.max(...L.map(l =&gt; l[0])), y0 = Math.min(...L.map(l =&gt; l[1])), y1 = Math.max(...L.map(l =&gt; l[1]));&#10;    return [[x0, y0], [x1, y0], [x1, y1], [x0, y1]].map(([x, y]) =&gt; [cx + (x * ca - y * sa) / W, cy + (x * sa + y * ca) / H]);&#10;}&#10;function addMaskPoint(it, u, v) {   // a new point on the edge nearest to (u, v), in pixels&#10;    let best = 0, bd = 1e9;&#10;    const n = it.pts.length;&#10;    for (let i = 0; i &lt; n; i++) {&#10;        const a = it.pts[i], b = it.pts[(i + 1) % n];&#10;        const ex = (b[0] - a[0]) * W, ey = (b[1] - a[1]) * H, wx = (u - a[0]) * W, wy = (v - a[1]) * H;&#10;        const t = Math.max(0, Math.min(1, (wx * ex + wy * ey) / Math.max(1e-6, ex * ex + ey * ey)));&#10;        const d = Math.hypot(wx - ex * t, wy - ey * t);&#10;        if (d &lt; bd) { bd = d; best = i; }&#10;    }&#10;    if (it.type === 'board' &amp;&amp; it.pts.length === 4)&#10;        it.qa = frameOf(it).a;   // the box the effect is spread over keeps the board's turn&#10;    it.pts.splice(best + 1, 0, [u, v]);&#10;    sendCode();&#10;    rebuild();&#10;}&#10;function setFrame(it, f) {   // the board as a straight rectangle, w by h, turned by a round its middle&#10;    const ca = Math.cos(f.a), sa = Math.sin(f.a);&#10;    it.pts = [[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([u, v]) =&gt; {&#10;        const x = u * f.w / 2, y = v * f.h / 2;&#10;        return [clampN((f.cx + x * ca - y * sa) / W), clampN((f.cy + x * sa + y * ca) / H)];&#10;    });&#10;}&#10;function squareUp(it, square) {   // no perspective: a rectangle as wide and high as it was (a square as big), as turned as it was&#10;    const f = frameOf(it);&#10;    if (square)&#10;        f.w = f.h = Math.sqrt(f.w * f.h);&#10;    setFrame(it, f);&#10;}&#10;function makeShape(it, n) {   // v7.9: a circle (12 points, a little rough) or a hexagon (6), as big as the shape was and as turned&#10;    if (it.locked) return;&#10;    const a = it.pts.length === 4 ? frameOf(it).a : (it.qa || 0), [cx, cy] = centre(it), ca = Math.cos(a), sa = Math.sin(a);&#10;    const L = it.pts.map(p =&gt; { const x = (p[0] - cx) * W, y = (p[1] - cy) * H; return [x * ca + y * sa, -x * sa + y * ca]; });&#10;    const w = Math.max(...L.map(l =&gt; l[0])) - Math.min(...L.map(l =&gt; l[0])), h = Math.max(...L.map(l =&gt; l[1])) - Math.min(...L.map(l =&gt; l[1]));&#10;    const r = Math.max(4, Math.sqrt(w * h) / 2), x0 = cx * W, y0 = cy * H;&#10;    it.qa = a;&#10;    it.pts = [];&#10;    for (let k = 0; k &lt; n; k++) {&#10;        const t = a + (n === 6 ? 0 : Math.PI / n) + 2 * Math.PI * k / n;&#10;        it.pts.push([(x0 + r * Math.cos(t)) / W, (y0 + r * Math.sin(t)) / H]);&#10;    }&#10;}&#10;function mirrorShape(it, ax) {   // v8.0: the shape mirrored left-right (ax 0) or up-down (1) round its middle; the effect in it stays the right way round&#10;    if (it.locked) return;&#10;    const c = centre(it)[ax], n = it.pts.length;&#10;    const P = it.pts.map(p =&gt; { const q = p.slice(); q[ax] = 2 * c - q[ax]; return q; });&#10;    it.pts = n === 4 ? (ax === 0 ? [P[1], P[0], P[3], P[2]] : [P[3], P[2], P[1], P[0]]) : P.reverse();&#10;    if (n !== 4 &amp;&amp; it.qa) it.qa = -it.qa;   // its box turns the other way too&#10;}&#10;function straighten(it) {   // a level rectangle&#10;    const f = frameOf(it);&#10;    f.a = 0;&#10;    setFrame(it, f);&#10;}&#10;// a copied size, from any element, for any element: { w, h (pixels), a (its turn, radians), rel (its corners or points&#10;// from its middle, in pixels) }&#10;let clip = null;&#10;const lightR = it =&gt; 6 + 250 * it.size * it.size;   // a light's reach, in pixels (as its ring shows)&#10;function shapeOf(it) {&#10;    if (it.type === 'board' &amp;&amp; it.pts.length === 4) {&#10;        const f = frameOf(it);&#10;        return { w: f.w, h: f.h, a: f.a, rel: it.pts.map(p =&gt; [p[0] * W - f.cx, p[1] * H - f.cy]) };&#10;    }&#10;    if (it.pts) {   // a mask's points (or a board's, not 4), and the box round them&#10;        const [cx, cy] = centre(it), rel = it.pts.map(p =&gt; [p[0] * W - cx * W, p[1] * H - cy * H]);&#10;        const xs = rel.map(r =&gt; r[0]), ys = rel.map(r =&gt; r[1]);&#10;        return { w: Math.max(...xs) - Math.min(...xs), h: Math.max(...ys) - Math.min(...ys), a: 0, rel: rel };&#10;    }&#10;    const [w, h] = it.type === 'image' ? imgBox(it, it.scale) : [2 * lightR(it), 2 * lightR(it)];&#10;    const a = it.type === 'image' ? (it.rot - 0.5) * 2 * Math.PI : 0, ca = Math.cos(a), sa = Math.sin(a);&#10;    return { w: w, h: h, a: a, rel: [[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([u, v]) =&gt; { const x = u * w / 2, y = v * h / 2; return [x * ca - y * sa, x * sa + y * ca]; }) };&#10;}&#10;function copySize(it) { clip = shapeOf(it); }&#10;const turnOf = a =&gt; (((a / (2 * Math.PI) + 0.5) % 1) + 1) % 1;   // radians -&gt; an image's rot (0.5: not turned)&#10;function pasteSize(it) {   // as wide and high as the copied one, along its own sides, keeping its own turn and shape&#10;    if (it.type === 'light') { it.size = Math.sqrt(Math.max(0, (Math.max(clip.w, clip.h) / 2 - 6) / 250)); return; }&#10;    if (it.type === 'image') { it.w = Math.max(0.005, clip.w / (W * 2 * it.scale)); it.h = Math.max(0.005, clip.h / (H * 2 * it.scale)); return; }&#10;    const own = shapeOf(it), [cx, cy] = centre(it), kx = clip.w / Math.max(1, own.w), ky = clip.h / Math.max(1, own.h);&#10;    const ca = Math.cos(own.a), sa = Math.sin(own.a);&#10;    it.pts = it.pts.map(p =&gt; {&#10;        const dx = (p[0] - cx) * W, dy = (p[1] - cy) * H;&#10;        const u = (dx * ca + dy * sa) * kx, v = (-dx * sa + dy * ca) * ky;&#10;        return [clampN((cx * W + u * ca - v * sa) / W), clampN((cy * H + u * sa + v * ca) / H)];&#10;    });&#10;}&#10;function pasteShape(it) {   // the copied one's size, turn and shape, round this one's middle&#10;    const [cx, cy] = centre(it);&#10;    if (it.type === 'image') {&#10;        it.w = Math.max(0.005, clip.w / (W * 2 * it.scale)); it.h = Math.max(0.005, clip.h / (H * 2 * it.scale));&#10;        if (!tlOn(it, 'rot')) it.rot = turnOf(clip.a);&#10;    } else if (it.type !== 'light') {&#10;        it.pts = clip.rel.map(r =&gt; [clampN(cx + r[0] / W), clampN(cy + r[1] / H)]);&#10;        it.qa = clip.a;&#10;    }&#10;}&#10;&#10;// ---------- the right-click menu ----------&#10;let menu = null;   // { id, x, y } while it is open&#10;function openMenu(it, e) {&#10;    e.stop();&#10;    sure = false;&#10;    hexTyping = null;&#10;    if (state.sel !== it.id) { state.sel = it.id; sendCode(); }&#10;    menu = { id: it.id, x: e.x, y: e.y };&#10;    rebuild();&#10;}&#10;function drawMenu() {&#10;    const it = state.items.find(t =&gt; t.id === menu.id);&#10;    if (!it) { menu = null; return; }&#10;    const close = e =&gt; { e.stop(); menu = null; rebuild(); };&#10;    const shut = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#00000000', interactive: true });&#10;    shut.on('click', close);&#10;    shut.on('rightclick', close);&#10;    shut.on('wheel', close);&#10;    const board = it.type === 'board';&#10;    const sizeLocked = it.type === 'light' &amp;&amp; tlOn(it, 'size');&#10;    const sizes = [['Copy size', () =&gt; copySize(it)], ['Paste size', clip &amp;&amp; !sizeLocked ? () =&gt; pasteSize(it) : null]];&#10;    if (it.type !== 'light')&#10;        sizes.push(['Paste size and shape', clip ? () =&gt; pasteShape(it) : null]);&#10;    const L = [];&#10;    if (board)&#10;        L.push(...(it.pts.length === 4 ? [['Make square', () =&gt; squareUp(it, true)], ['Make rectangle', () =&gt; squareUp(it, false)], ['Make circle', () =&gt; makeShape(it, 12)], ['Make hexagon', () =&gt; makeShape(it, 6)], ['Mirror X', () =&gt; mirrorShape(it, 0)], ['Mirror Y', () =&gt; mirrorShape(it, 1)], ['Straighten', () =&gt; straighten(it)]] :&#10;                   [['Make circle', () =&gt; makeShape(it, 12)], ['Make hexagon', () =&gt; makeShape(it, 6)], ['Mirror X', () =&gt; mirrorShape(it, 0)], ['Mirror Y', () =&gt; mirrorShape(it, 1)], ['Back to 4 corners', () =&gt; { const q = boardQuad(it); it.pts = q.map(p =&gt; p.slice()); }]]), null);&#10;    if (it.type === 'mask')&#10;        L.push([it.invert ? 'Hide the effects inside' : 'Hide the effects outside', () =&gt; { it.invert = it.invert ? 0 : 1; }],&#10;               ['Mask all effects', it.all === false ? () =&gt; { it.all = true; } : null], null, ['Make circle', () =&gt; makeShape(it, 12)], ['Make hexagon', () =&gt; makeShape(it, 6)], ['Mirror X', () =&gt; mirrorShape(it, 0)], ['Mirror Y', () =&gt; mirrorShape(it, 1)], null, ...sizes, null,&#10;               ['Duplicate', duplicate], ['Hide', () =&gt; { it.hidden = true; }], ['Lock', () =&gt; { it.locked = true; }], ['Delete', () =&gt; remove(it.id)]);&#10;    else {&#10;    if (it.type === 'image')&#10;        L.push(['Replace picture...', () =&gt; { wantImage = 'replace'; out(2); }], ['No turn', tlOn(it, 'rot') ? null : () =&gt; { it.rot = 0.5; }],&#10;               ['Fit / Fill', () =&gt; { it.fit = it.fit ? 0 : 1; }], null);&#10;    L.push(...sizes);&#10;    L.push(null, ['Duplicate', duplicate],&#10;           ['Bring to front', () =&gt; { state.items = state.items.filter(t =&gt; t !== it).concat([it]); }],&#10;           ['Send to back', () =&gt; { state.items = [it].concat(state.items.filter(t =&gt; t !== it)); }],&#10;           null, ['Hide', () =&gt; { it.hidden = true; }], ['Lock', () =&gt; { it.locked = true; }], ['Delete', () =&gt; remove(it.id)]);&#10;    }&#10;    const MW = 250, RH = 34, SH = 11;&#10;    const MH = 40 + L.reduce((a, r) =&gt; a + (r ? RH : SH), 0) + 8;&#10;    const g = layer.group({ x: Math.min(menu.x + 4, W - MW - 8), y: Math.max(8, Math.min(menu.y + 4, H - MH - 8)) });&#10;    g.rect({ w: MW, h: MH, radius: 8, fill: '#14121ff8', stroke: '#2f2850', strokeWidth: 1, interactive: true, shadow: { color: '#000000a0', y: 6, blur: 18 } });&#10;    g.text({ x: 16, y: 22, text: itemName(it), size: 16, baseline: 'middle', fill: ACC, interactive: false });&#10;    let y = 40;&#10;    for (const r of L) {&#10;        if (!r) { g.line({ x1: 12, y1: y + SH / 2, x2: MW - 12, y2: y + SH / 2, width: 1, stroke: '#2f2850', interactive: false }); y += SH; continue; }&#10;        const [name, fn] = r;&#10;        const row = g.group({ x: 4, y: y, cursor: fn ? 'pointer' : 'default' });&#10;        const bg = row.rect({ w: MW - 8, h: RH - 2, radius: 5, fill: '#00000000', interactive: true });&#10;        row.text({ x: 12, y: (RH - 2) / 2, text: name, size: 19, baseline: 'middle', interactive: false,&#10;                   fill: !fn ? '#5c5774' : name === 'Delete' ? '#ff6b7a' : '#f1ecff' });&#10;        if (fn) {&#10;            row.on('enter', () =&gt; bg.set({ fill: '#8a3fff40' }));&#10;            row.on('leave', () =&gt; bg.set({ fill: '#00000000' }));&#10;            row.on('click', e =&gt; { e.stop(); menu = null; fn(); sendCode(); rebuild(); });&#10;        } else&#10;            row.on('click', e =&gt; e.stop());&#10;        y += RH;&#10;    }&#10;}&#10;&#10;// ---------- pictures ----------&#10;// a picture is a box (w across, h down: shares of the Scene, times 2 x scale) round x, y, turned by rot (0.5: not turned);&#10;// the file sits in it whole (Fit) or fills it and is cut (Fill)&#10;const imgBox = (it, sc) =&gt; [it.w * W * 2 * sc, it.h * H * 2 * sc];&#10;function imageCorners(it) {   // the box's corners on the canvas&#10;    const [bw, bh] = imgBox(it, it.scale), a = (it.rot - 0.5) * 2 * Math.PI, ca = Math.cos(a), sa = Math.sin(a);&#10;    return [[-1, -1], [1, -1], [1, 1], [-1, 1]].map(([u, v]) =&gt; { const x = u * bw / 2, y = v * bh / 2;&#10;        return [X(it.x) + (x * ca - y * sa) * view.s, Y(it.y) + (x * sa + y * ca) * view.s]; });&#10;}&#10;let images = {}, imgLayer = null;   // the drawn pictures, by id&#10;function imageProps(it, t) {   // where and how a picture is drawn, at t seconds (its timeline) or as it is (t null)&#10;    const v = (k, still) =&gt; t === null ? still : tlAt(it, k, still, t);&#10;    const sc = v('scale', it.scale), [bw, bh] = imgBox(it, sc);&#10;    const cx = X(v('x', it.x)), cy = Y(v('y', it.y));&#10;    return { x: cx - bw * view.s / 2, y: cy - bh * view.s / 2, w: bw * view.s, h: bh * view.s, rotation: (v('rot', it.rot) - 0.5) * 360,&#10;             opacity: 1 - v('transp', it.transp || 0) };&#10;}&#10;function drawImages() {&#10;    images = {};&#10;    const g = imgLayer = layer.group(state.edit ? { clip: [view.x, view.y, W * view.s, H * view.s] } : {});&#10;    for (const it of state.items)&#10;        if (it.type === 'image' &amp;&amp; !it.hidden &amp;&amp; it.src)&#10;            images[it.id] = g.image(Object.assign({ src: it.src, fit: it.fit ? 'cover' : 'contain', interactive: false }, imageProps(it, time())));&#10;}&#10;function onTick(dt) {   // the pictures' timelines, and a change of scene&#10;    sceneTick(dt || 1 / 30);&#10;    if (glslPend &amp;&amp; --glslPend === 0)&#10;        sendCode();&#10;    if (codePend &amp;&amp; --codePend === 0)&#10;        sendCode();&#10;    for (const it of state.items)&#10;        if (images[it.id] &amp;&amp; TL(it) &amp;&amp; Object.values(TL(it).tracks).some(k =&gt; k.on))&#10;            images[it.id].set(imageProps(it, time()));&#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;// v6.0: the strokes of the selected mask, and while the brush is on, a sheet over the picture to paint on&#10;function drawBrush() {&#10;    const m = selected();&#10;    if (!m || m.type !== 'mask') return;&#10;    const kpx = H * view.s;   // picture heights -&gt; canvas&#10;    const strokeLines = (st, g) =&gt; {&#10;        const col = st.e ? '#3cf0ff' : '#ff4f8b', w = Math.max(1, 2 * st.r * kpx);&#10;        st.p.forEach((q, i) =&gt; {&#10;            g.circle({ x: X(q[0]), y: Y(q[1]), r: w / 2, fill: col, opacity: 0.22, interactive: false });&#10;            if (i) g.line({ x1: X(st.p[i - 1][0]), y1: Y(st.p[i - 1][1]), x2: X(q[0]), y2: Y(q[1]), width: w, stroke: col, opacity: 0.22, interactive: false });&#10;        });&#10;    };&#10;    (m.strokes || []).forEach(st =&gt; strokeLines(st, layer));&#10;    if (!state.brush) return;&#10;    const sheet = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#00000000', interactive: true, cursor: 'crosshair',&#10;                               tooltip: state.brush === 1 ? 'Paint the mask (the effects do not show where you paint)' : 'Erase from the mask' });&#10;    let cur = null, last = null;&#10;    const r = brushR();&#10;    sheet.on('press', e =&gt; { e.stop(); cur = { e: state.brush === 2 ? 1 : 0, r: r, s: state.bsoft, p: [[U(e.x), V(e.y)]] }; last = [e.x, e.y];&#10;        layer.circle({ x: e.x, y: e.y, r: r * kpx, fill: cur.e ? '#3cf0ff' : '#ff4f8b', opacity: 0.3, interactive: false }); });&#10;    sheet.on('drag', e =&gt; { e.stop(); if (!cur) return;&#10;        if (Math.hypot(e.x - last[0], e.y - last[1]) &lt; Math.max(2, r * kpx * 0.25)) return;&#10;        layer.line({ x1: last[0], y1: last[1], x2: e.x, y2: e.y, width: 2 * r * kpx, stroke: cur.e ? '#3cf0ff' : '#ff4f8b', opacity: 0.3, interactive: false });&#10;        cur.p.push([U(e.x), V(e.y)]); last = [e.x, e.y]; });&#10;    const done = () =&gt; { if (!cur) return;&#10;        cur.p = simplify(cur.p, cur.r * 0.15).slice(0, 120).map(q =&gt; [Math.round(q[0] * 1e4) / 1e4, Math.round(q[1] * 1e4) / 1e4]);&#10;        m.strokes = (m.strokes || []).concat([cur]); cur = null; sendCode(); rebuild(); };&#10;    sheet.on('release', done);&#10;    sheet.on('dragend', done);&#10;    brushEnd = done;   // also when the mouse is let go off the sheet&#10;}&#10;let brushEnd = null;&#10;function rebuild() {&#10;    checkpoint();&#10;    glslBox();&#10;    if (layer)&#10;        layer.remove();&#10;    layer = c.group({});&#10;    handles = {};&#10;    fitView();&#10;    sendView();&#10;    drawImages();&#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;        drawLinks();&#10;        drawBrush();&#10;        drawToolbar();&#10;        drawDock();&#10;        if (state.tlOpen)&#10;            drawTimeline();&#10;        else if (state.auOpen)&#10;            drawAudio();&#10;        if (menu)&#10;            drawMenu();&#10;        if (help)&#10;            drawHelp();&#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;        handles[it.id] = { outline: it.type !== 'light' ?&#10;            layer.polygon({ x: 0, y: 0, points: it.type === 'image' ? imageCorners(it) : boardPoints(it), fill: '#00000000', stroke: col, strokeWidth: 1, opacity: 0.4, interactive: false }) :&#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 === 'mask') {&#10;        const h = {}, MC = sel ? '#ff4f8b' : '#ff4f8baa';&#10;        h.poly = layer.polygon({ x: 0, y: 0, points: boardPoints(it), fill: it.invert ? (sel ? '#ff4f8b10' : '#ff4f8b08') : sel ? '#ff4f8b30' : '#ff4f8b18', interactive: true,   // a little colour even outside: a clear fill lets the mouse through stroke: MC, strokeWidth: sel ? 2.5 : 1.5,&#10;                                 cursor: 'move', tooltip: 'Mask - drag: move - double-click the edge: a point more - wheel: size - Shift + wheel: turn - right-click: options' });&#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(); wheelStep();&#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('doubleclick', e =&gt; { e.stop(); addMaskPoint(it, U(e.x), V(e.y)); });&#10;        h.poly.on('rightclick', e =&gt; openMenu(it, e));&#10;        h.name = layer.text({ x: X(it.pts[0][0]), y: Y(it.pts[0][1]) - 12, text: it.invert ? 'Mask (outside)' : 'Mask', size: 22, fill: sel ? '#ff7aa8' : '#ffb3cc',&#10;                              baseline: 'bottom', align: 'center', interactive: false, shadow: '#000000' });&#10;        h.dots = it.pts.map((p, i) =&gt; {&#10;            const d = layer.circle({ x: X(p[0]), y: Y(p[1]), r: sel ? 9 : 6, fill: sel ? '#ff4f8b' : '#ffffff60', stroke: '#000000', strokeWidth: 1.5,&#10;                                     cursor: 'crosshair', tooltip: 'Drag this point - right-click: take it away' });&#10;            d.on('press', () =&gt; { pick(it.id); });&#10;            d.on('drag', e =&gt; { const cur = selected(); if (!cur) return;&#10;                const [sx, sy] = snapDelta([[U(e.x), V(e.y)]], cur.id, e.alt);&#10;                cur.pts[i] = [clampN(U(e.x) + sx), clampN(V(e.y) + sy)]; moveHandles(cur); sendAids(cur.pts[i]); });&#10;            d.on('rightclick', e =&gt; { e.stop(); if (it.pts.length &gt; 3) { it.pts.splice(i, 1); sendCode(); rebuild(); } });&#10;            return d;&#10;        });&#10;        handles[it.id] = h;&#10;    } else if (it.type === 'image') {&#10;        const h = {};&#10;        h.poly = layer.polygon({ x: 0, y: 0, points: imageCorners(it), fill: sel ? '#8a3fff14' : '#ffffff05', stroke: col, strokeWidth: sel ? 2.5 : 1.5,&#10;                                 cursor: 'move', tooltip: 'Picture - drag: move - wheel: bigger/smaller - Shift + wheel: turn - right-click: options' });&#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 || 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); });&#10;        h.poly.on('wheel', e =&gt; { if (it.id !== state.sel) select(it.id); const cur = selected(); e.stop();&#10;            if (tlOn(cur, e.shift ? 'rot' : 'scale')) return;&#10;            wheelStep();&#10;            if (e.shift) cur.rot = ((cur.rot + (e.delta &gt; 0 ? 1 : -1) / 180) % 1 + 1) % 1;&#10;            else cur.scale = Math.max(0.01, Math.min(1, cur.scale * (e.delta &gt; 0 ? 1.04 : 1 / 1.04)));&#10;            moveHandles(cur); refreshSliders(); });&#10;        h.poly.on('rightclick', e =&gt; openMenu(it, e));&#10;        const c0 = imageCorners(it)[0];&#10;        h.name = layer.text({ x: c0[0], y: c0[1] - 8, text: fileName(it.src), size: 22, fill: sel ? NAMESEL : '#ffffff', baseline: 'bottom', interactive: false, shadow: '#000000' });&#10;        h.dots = imageCorners(it).map(p =&gt; {   // a corner: the box wider or narrower, higher or lower, round its middle&#10;            const d = layer.circle({ x: p[0], y: p[1], r: sel ? 10 : 6, fill: sel ? ACC : '#ffffff60', stroke: '#000000', strokeWidth: 1.5, cursor: 'crosshair',&#10;                                     tooltip: 'Drag: the box wider or higher (Ctrl: keep its shape)' });&#10;            d.on('press', () =&gt; { pick(it.id); dragFrom = Object.assign(keep(it), { w: it.w, h: it.h }); });&#10;            d.on('drag', e =&gt; { const cur = selected(); if (!cur || !dragFrom) return;&#10;                const a = (cur.rot - 0.5) * 2 * Math.PI, dx = (e.x - X(cur.x)) / view.s, dy = (e.y - Y(cur.y)) / view.s;&#10;                const u = Math.abs(dx * Math.cos(a) + dy * Math.sin(a)), v = Math.abs(-dx * Math.sin(a) + dy * Math.cos(a));&#10;                if (e.ctrl) { const k = Math.max(u / (dragFrom.w * W * cur.scale), v / (dragFrom.h * H * cur.scale));&#10;                    cur.w = Math.max(0.005, dragFrom.w * k); cur.h = Math.max(0.005, dragFrom.h * k); }&#10;                else { cur.w = Math.max(0.005, u / (W * cur.scale)); cur.h = Math.max(0.005, v / (H * cur.scale)); }&#10;                moveHandles(cur); });&#10;            return d;&#10;        });&#10;        handles[it.id] = h;&#10;    } else 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: options' });&#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(); wheelStep();&#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', e =&gt; openMenu(it, e));&#10;        h.poly.on('doubleclick', e =&gt; { e.stop(); addMaskPoint(it, U(e.x), V(e.y)); });&#10;        h.name = layer.text({ x: X(it.pts[0][0]), y: Y(it.pts[0][1]) - 8, text: FX[it.fx], size: 22, fill: sel ? NAMESEL : '#ffffff',&#10;                              baseline: 'bottom', interactive: false, shadow: '#000000' });&#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',&#10;                                     tooltip: 'Drag this point - double-click the edge: a point more - right-click: take it away' });&#10;            d.on('rightclick', e =&gt; { e.stop(); if (it.pts.length &gt; 3) { if (it.pts.length === 4) it.qa = frameOf(it).a; it.pts.splice(i, 1); sendCode(); rebuild(); } });&#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.pts.length === 4 &amp;&amp; !!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: options' });&#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; } wheelStep();&#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', e =&gt; openMenu(it, e));&#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;    drawLinks();&#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 (images[it.id])&#10;        images[it.id].set(imageProps(it, TL(it) &amp;&amp; Object.values(TL(it).tracks).some(k =&gt; k.on) ? time() : null));&#10;    if (h &amp;&amp; h.outline)   // a locked one: only its outline&#10;        h.outline.set(it.type === 'light' ? { x: X(it.x), y: Y(it.y) } : { points: it.type === 'image' ? imageCorners(it) : boardPoints(it) });&#10;    else if (h &amp;&amp; it.type === 'mask') {&#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]) - 12 });&#10;        tlDirty = true;   // its shape is in the shader: a new one once the mouse lets go&#10;    } else if (h &amp;&amp; it.type === 'image') {&#10;        const P = imageCorners(it);&#10;        h.poly.set({ points: P });&#10;        h.dots.forEach((d, i) =&gt; d.set({ x: P[i][0], y: P[i][1] }));&#10;        h.name.set({ x: P[0][0], y: P[0][1] - 8 });&#10;    } else 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;        if (it.pts.length !== 4)&#10;            tlDirty = true;   // its shape is in the shader: a new one once the mouse lets go&#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, and the pictures' window with it&#10;    if (imgLayer &amp;&amp; state.edit)&#10;        imgLayer.set({ clip: [view.x, view.y, W * view.s, H * view.s] });&#10;    state.items.forEach(place);&#10;    drawLinks();   // v7.2: the cables follow the zoom and the pan too&#10;}&#10;&#10;// ---------- v6.7: cables between elements. Orange: the sound, blue: the timeline. Drag from an out (right) to an in (left) ----------&#10;const LINKS = { auFrom: { col: '#f1995b', dy: -9, name: 'sound' }, tlFrom: { col: '#4fa3ff', dy: 9, name: 'timeline' } };&#10;let linkLayer = null, linking = null;&#10;const canLink = (it, kind) =&gt; !it.hidden &amp;&amp; !it.locked &amp;&amp; (kind === 'auFrom' ? it.type !== 'image' : it.type !== 'mask' &amp;&amp; tlProps(it).length &gt; 0);&#10;function jackAt(it, kind, out) {   // where an element's in (left) or out (right) is on the canvas&#10;    const dy = LINKS[kind].dy;&#10;    if (it.type === 'light') return [X(it.x) + (out ? 26 : -26), Y(it.y) + dy];&#10;    const P = it.type === 'image' ? imageCorners(it) : boardPoints(it), xs = P.map(p =&gt; p[0]), ys = P.map(p =&gt; p[1]);&#10;    return [(out ? Math.max(...xs) + 14 : Math.min(...xs) - 14), (Math.min(...ys) + Math.max(...ys)) / 2 + dy];&#10;}&#10;function wouldLoop(from, to, kind) {   // to would follow from: true when from already follows to, down its chain&#10;    let cur = from;&#10;    for (let n = 0; n &lt; 32 &amp;&amp; cur; n++) {&#10;        if (cur.id === to.id) return true;&#10;        cur = cur[kind] ? state.items.find(t =&gt; t.id === cur[kind]) : null;&#10;    }&#10;    return false;&#10;}&#10;function drawLinks() {&#10;    if (linkLayer) linkLayer.remove();&#10;    linkLayer = null;&#10;    if (!state.edit || !layer || state.hideLinks) return;&#10;    linkLayer = layer.group({});&#10;    const g = linkLayer;&#10;    for (const kind of Object.keys(LINKS)) {&#10;        const L = LINKS[kind];&#10;        state.items.forEach(b =&gt; {   // the cables first, under the jacks&#10;            const a = b[kind] &amp;&amp; state.items.find(t =&gt; t.id === b[kind]);&#10;            if (!a || !canLink(a, kind) || !canLink(b, kind)) return;&#10;            const p = jackAt(a, kind, true), q = jackAt(b, kind, false);&#10;            const ln = g.line({ x1: p[0], y1: p[1], x2: q[0], y2: q[1], width: 3, stroke: L.col + 'cc', cap: 'round', interactive: true, cursor: 'pointer',&#10;                                tooltip: itemName(b) + ' follows the ' + L.name + ' of ' + itemName(a) + ' - right-click: cut' });&#10;            ln.on('rightclick', e =&gt; { e.stop(); delete b[kind]; sendCode(); rebuild(); });&#10;        });&#10;        state.items.forEach(it =&gt; {&#10;            if (!canLink(it, kind)) return;&#10;            const [ix, iy] = jackAt(it, kind, false), [ox, oy] = jackAt(it, kind, true), joined = !!it[kind];&#10;            const jin = g.circle({ x: ix, y: iy, r: 6, fill: joined ? L.col : '#14121f', stroke: L.col, strokeWidth: 2, cursor: 'pointer',&#10;                                   tooltip: 'In: follow the ' + L.name + ' of another element (drag a cable here from its out)' + (joined ? ' - right-click: cut' : '') });&#10;            jin.on('rightclick', e =&gt; { e.stop(); if (it[kind]) { delete it[kind]; sendCode(); rebuild(); } });&#10;            const jout = g.circle({ x: ox, y: oy, r: 6, fill: '#14121f', stroke: L.col, strokeWidth: 2, cursor: 'crosshair',&#10;                                    tooltip: 'Out: drag to the in of another element, and it follows the ' + L.name + ' of this one' });&#10;            jout.on('press', e =&gt; { e.stop(); });&#10;            jout.on('dragstart', e =&gt; { e.stop(); linking = { from: it, kind: kind, line: g.line({ x1: ox, y1: oy, x2: e.x, y2: e.y, width: 3, stroke: L.col, cap: 'round', interactive: false }) }; });&#10;            jout.on('drag', e =&gt; { e.stop(); if (!linking) linking = { from: it, kind: kind, line: g.line({ x1: ox, y1: oy, x2: e.x, y2: e.y, width: 3, stroke: L.col, cap: 'round', interactive: false }) }; linking.line.set({ x2: e.x, y2: e.y }); });&#10;            jout.on('dragend', e =&gt; { e.stop(); linkDrop(e.x, e.y); });&#10;        });&#10;    }&#10;}&#10;function linkDrop(x, y) {   // let go: on (or near) the in of another element, that one follows&#10;    const lk = linking;&#10;    linking = null;&#10;    if (!lk) return;&#10;    let best = null, bd = 30;&#10;    state.items.forEach(t =&gt; {&#10;        if (t === lk.from || !canLink(t, lk.kind)) return;&#10;        const [ix, iy] = jackAt(t, lk.kind, false), d = Math.hypot(ix - x, iy - y);&#10;        if (d &lt; bd) { bd = d; best = t; }&#10;    });&#10;    if (best &amp;&amp; !wouldLoop(lk.from, best, lk.kind)) { best[lk.kind] = lk.from.id; sendCode(); }&#10;    rebuild();&#10;}&#10;function followNote(g, it, kind, what) {   // in the Timeline or Audio panel of one that follows: what it follows, and where to change it&#10;    const a = it[kind] &amp;&amp; state.items.find(t =&gt; t.id === it[kind]);&#10;    if (!a) return false;&#10;    const root = srcOf(it, kind);&#10;    g.text({ x: 16, y: 64, text: 'Follows the ' + what + ' of ' + itemName(a) + (root !== a ? ' (and so of ' + itemName(root) + ')' : '') + ': change it there.', size: 18, baseline: 'middle', fill: '#c9c3e0', interactive: false });&#10;    button(g, 16, 90, 220, 'Go to ' + (root.type === 'light' ? 'Light ' : root.type === 'image' ? 'Image ' : 'Board ') + root.id, () =&gt; select(root.id), false);&#10;    button(g, 244, 90, 160, 'Cut the cable', () =&gt; { delete it[kind]; sendCode(); rebuild(); }, false);&#10;    return true;&#10;}&#10;&#10;// ---------- the Layers panel ----------&#10;const fileName = p =&gt; String(p || '').split(/[\\/]/).pop();&#10;const itemName = it =&gt; it.type === 'image' ? 'Image ' + it.id + ' - ' + fileName(it.src) : it.type === 'mask' ? 'Mask ' + it.id + (it.all === false ? ' - some effects' : ' - all effects') :&#10;    (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;function trash(g, x, y, on) {   // a small bin: Delete in a row of the list&#10;    const col = on ? '#b8b2d0' : '#3c3852';&#10;    g.rect({ x: x - 5, y: y - 4, w: 10, h: 12, radius: 1.5, fill: '#00000000', stroke: col, strokeWidth: 1.6, interactive: false });&#10;    g.line({ x1: x - 8, y1: y - 6, x2: x + 8, y2: y - 6, width: 1.6, stroke: col, interactive: false });&#10;    g.line({ x1: x - 2.5, y1: y - 9, x2: x + 2.5, y2: y - 9, width: 1.6, stroke: col, interactive: false });&#10;}&#10;&#10;// a row of the list dragged up or down: let go and the element takes that place (the front at the top)&#10;let rowDrag = null, rowMoved = false;&#10;function slotOf(d) {   // where in the list (front first) the dragged row would go now&#10;    const i = d.rows.findIndex(r =&gt; r.it === d.it) + state.lscroll;&#10;    return { i: i, j: Math.max(0, Math.min(d.n - 1, i + Math.round(d.dy / d.RH))) };&#10;}&#10;function dragRow(dy, total) {&#10;    const d = rowDrag;&#10;    if (!d)&#10;        return;&#10;    d.dy = dy;&#10;    if (Math.abs(total) &gt; 6)&#10;        d.moved = true;&#10;    if (!d.moved)&#10;        return;&#10;    if (!d.front) { d.front = true; d.row.front(); }   // over the rows it passes&#10;    d.row.set({ y: d.y0 + dy });&#10;    const { i, j } = slotOf(d);&#10;    d.rows.forEach((r, v) =&gt; {   // the rows in between shift one place up or down&#10;        if (r.it === d.it)&#10;            return;&#10;        const k = v + state.lscroll, to = i &lt; k &amp;&amp; k &lt;= j ? k - 1 : j &lt;= k &amp;&amp; k &lt; i ? k + 1 : k;&#10;        r.row.set({ y: d.top + (to - state.lscroll) * d.RH });&#10;    });&#10;}&#10;function dropRow() {&#10;    const d = rowDrag;&#10;    rowDrag = null;&#10;    if (!d || !d.moved)&#10;        return;&#10;    rowMoved = true;&#10;    const list = state.items.slice().reverse(), { i, j } = slotOf(d);&#10;    if (list[i] === d.it &amp;&amp; j !== i) {&#10;        list.splice(i, 1);&#10;        list.splice(j, 0, d.it);&#10;        state.items = list.reverse();&#10;        sendCode();&#10;    }&#10;    rebuild();&#10;}&#10;&#10;const LROWS = 8;   // v7.6: Layers shows at most this many rows, with a scrollbar of its own&#10;let lbox = null, lboxAt = null, layersSel = null, lcap = LROWS;   // lcap (v7.7): fewer rows when Properties needs the room   // the rows' own group: the wheel redraws only that, not the whole editor&#10;function layerRows(list) {   // how many rows Layers shows: at most LROWS, and never more than about 40% of the screen&#10;    return Math.max(1, Math.min(list.length, LROWS, lcap, Math.floor((dockH() * 0.4 - 52) / 30)));&#10;}&#10;function layerScroll(d) {   // the wheel or the scrollbar on Layers: redraw just its rows&#10;    const list = state.items.slice().reverse(), n = layerRows(list);&#10;    const s = Math.max(0, Math.min((state.lscroll || 0) + d, list.length - n));&#10;    if (s === state.lscroll || !lboxAt) return;&#10;    state.lscroll = s;&#10;    drawLayers(lboxAt.g, lboxAt.y, lboxAt.LW);&#10;}&#10;function drawLayers(g, y, LW) {   // the list of elements, pinned at the bottom of the dock; returns where it ends&#10;    const RH = 30;&#10;    const list = state.items.slice().reverse();   // the front first&#10;    const n = layerRows(list), bar = list.length &gt; n;&#10;    lboxAt = { g: g, y: y, LW: LW };&#10;    if (lbox) lbox.remove();&#10;    lbox = g.group({ x: 0, y: 0 });&#10;    g = lbox;&#10;    if (state.sel !== layersSel) {   // a new selection (also from a click in the picture): scroll it into view&#10;        layersSel = state.sel;&#10;        const k = list.findIndex(t =&gt; t.id === state.sel);&#10;        if (k &gt;= 0 &amp;&amp; (k &lt; (state.lscroll || 0) || k &gt;= (state.lscroll || 0) + n)) state.lscroll = k - Math.floor(n / 2);&#10;    }&#10;    state.lscroll = Math.max(0, Math.min(state.lscroll || 0, list.length - n));&#10;    if (!list.length) {&#10;        g.text({ x: 16, y: y + 10, text: 'Nothing yet: add a board or a light (toolbar).', size: 18, baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;        return y + 36;&#10;    }&#10;    const RW = bar ? LW - 14 : LW;   // the rows leave room for the scrollbar&#10;    const catcher = g.rect({ x: 0, y: y - 4, w: LW, h: n * RH + 8, fill: '#00000000', interactive: true });   // the wheel between the rows too&#10;    catcher.on('wheel', e =&gt; { e.stop(); layerScroll(e.delta &gt; 0 ? -1 : 1); });&#10;    const rows = [], top = y;&#10;    list.slice(state.lscroll, state.lscroll + n).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: RW - 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(); if (rowMoved) { rowMoved = false; return; } select(it.id); });&#10;        const ry = y;   // where this row is (y goes on down the list)&#10;        rb.on('press', e =&gt; { rowMoved = false; rowDrag = { it: it, row: row, y0: ry, py: e.y, dy: 0, RH: RH, rows: rows, top: top, n: list.length }; });&#10;        rb.on('drag', e =&gt; { e.stop(); if (rowDrag) dragRow(e.y - rowDrag.py, e.totalY); });   // drag the row up or down: the others make room&#10;        rb.on('release', dropRow);&#10;        rb.on('dragend', dropRow);&#10;        rows.push({ it: it, row: row });&#10;        rb.on('wheel', e =&gt; { e.stop(); layerScroll(e.delta &gt; 0 ? -1 : 1); });&#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: 19, baseline: 'middle', fill: it.hidden ? '#7f7a99' : sel ? NAMESEL : '#ffffff', interactive: false });&#10;        const tb = row.rect({ x: RW - 136, y: 0, w: 28, h: RH - 4, fill: '#00000000', cursor: it.locked ? 'default' : 'pointer', tooltip: it.locked ? 'Locked: unlock it to delete' : 'Delete' });&#10;        tb.on('click', e =&gt; { e.stop(); remove(it.id); });&#10;        trash(row, RW - 122, (RH - 4) / 2, !it.locked);&#10;        const lb = row.rect({ x: RW - 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, RW - 86, (RH - 4) / 2, !!it.locked);&#10;        const up = row.triangle({ x1: RW - 60, y1: 18, x2: RW - 48, y2: 18, x3: RW - 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: RW - 40, y1: 8, x2: RW - 28, y2: 8, x3: RW - 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 (bar) {   // the scrollbar: drag the thumb, or click above or below it for a page&#10;        const th = n * RH - 4, tx = LW - 18, ty = top;&#10;        const track = g.rect({ x: tx, y: ty, w: 8, h: th, radius: 4, fill: '#241f3a', cursor: 'pointer', tooltip: 'Scroll the layers' });&#10;        const hh = Math.max(24, th * n / list.length), most = list.length - n;&#10;        const at = ty + (th - hh) * state.lscroll / most;&#10;        track.on('click', e =&gt; { e.stop(); layerScroll(e.y &lt; at ? -n : n); });&#10;        track.on('wheel', e =&gt; { e.stop(); layerScroll(e.delta &gt; 0 ? -1 : 1); });&#10;        const thumb = g.rect({ x: tx, y: at, w: 8, h: hh, radius: 4, fill: '#8a7fd0', cursor: 'grab', tooltip: (state.lscroll + 1) + '-' + (state.lscroll + n) + ' of ' + list.length });&#10;        let from = 0;&#10;        thumb.on('press', e =&gt; { e.stop(); from = state.lscroll; });&#10;        thumb.on('drag', e =&gt; { e.stop(); layerScroll(Math.round(from + e.totalY * most / Math.max(1, th - hh)) - state.lscroll); });&#10;        thumb.on('wheel', e =&gt; { e.stop(); layerScroll(e.delta &gt; 0 ? -1 : 1); });&#10;    }&#10;    return y + 6;&#10;}&#10;&#10;// ---------- the toolbar: down the left side, as in Photoshop ----------&#10;const TW = 116;   // v8.9: two columns of tools&#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 === 'mask') {   // a shape, half of it blocked&#10;        g.polygon(Object.assign({ points: [[10, 20], [17, 9], [31, 9], [37, 20], [31, 31], [17, 31]], fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        g.polygon(Object.assign({ points: [[24, 9], [31, 9], [37, 20], [31, 31], [24, 31]], fill: col }, o));&#10;    } else if (kind === 'image') {   // a small picture with a plus&#10;        g.rect(Object.assign({ x: 10, y: 12, w: 22, h: 18, radius: 2, fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        g.triangle(Object.assign({ x1: 13, y1: 28, x2: 20, y2: 18, x3: 27, y3: 28, fill: col }, o));&#10;        plus();&#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 === 'help') {   // a question mark in a ring&#10;        g.circle(Object.assign({ x: 24, y: 20, r: 12, fill: '#00000000', stroke: col, strokeWidth: 2 }, o));&#10;        g.text(Object.assign({ x: 24, y: 21, text: '?', size: 18, align: 'center', baseline: 'middle', fill: col }, o));&#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 === 'audio') {   // bars of a spectrum&#10;        [[12, 8], [18, 16], [24, 4], [30, 12], [36, 20]].forEach(([x, h]) =&gt; g.rect(Object.assign({ x: x - 2, y: 32 - (28 - h), w: 4, h: 28 - h, radius: 1, 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.startsWith('undo') || kind.startsWith('redo')) {   // a curved arrow, back or forth (grey with nothing to do)&#10;        const c2 = kind.endsWith('0') ? '#5c5774' : col, back = kind.startsWith('undo');&#10;        g.arc(Object.assign({ x: 24, y: 20, r: 9, width: 2, start: back ? 0 : 180, end: back ? 180 : 360, stroke: c2 }, o));&#10;        g.line(Object.assign({ x1: 24, y1: 29, x2: back ? 17 : 31, y2: 29, width: 2, stroke: c2 }, o));&#10;        g.triangle(Object.assign(back ? { x1: 25, y1: 6, x2: 25, y2: 16, x3: 18, y3: 11 } : { x1: 23, y1: 6, x2: 23, y2: 16, x3: 30, y3: 11 }, { fill: c2 }, o));&#10;    } else if (kind === 'done') {&#10;        line(14, 19, 21, 26); line(21, 26, 34, 11);&#10;    }&#10;}&#10;&#10;function tool(g, x, y, kind, label, tip, fn, on, accent) {&#10;    const b = g.group({ x: x, 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 ? '#b98cff' : '#f1ecff';&#10;    icon(b, kind, col);&#10;    b.text({ x: 24, y: 42, text: label, size: 14, 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() {   // v8.9: in two columns, so the tools can be bigger and still fit&#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: 19, align: 'center', baseline: 'middle', fill: ACC, interactive: false });&#10;    let y = 40, col = 0;&#10;    const T = (...a) =&gt; { tool(g, 8 + col * 52, y, ...a); if (col) { col = 0; y += 56; } else col = 1; };&#10;    const sep = () =&gt; { if (col) { col = 0; y += 56; } g.line({ x1: 12, y1: y + 2, x2: TW - 12, y2: y + 2, width: 1, stroke: '#2f2850', interactive: false }); y += 10; };&#10;    T('board', 'Board', 'Add a board (a sign or a screen with an effect)', () =&gt; addBoard(0.5, 0.5));&#10;    T('image', 'Image', 'Add a picture as a layer, over the effects (PNG with see-through parts works)', () =&gt; { wantImage = true; out(2); });&#10;    T('mask', 'Mask', 'Add a mask: the effects do not show inside it', () =&gt; addMask(0.5, 0.5));&#10;    T('light', 'Light', 'Add a light (double-clicking the picture does too)', () =&gt; addLight(0.5, 0.5));&#10;    T('copy', 'Copy', 'Copy the selected element', duplicate);&#10;    T('delete', 'Delete', 'Delete the selected element (or right-click it: Delete)', () =&gt; { if (state.sel) remove(state.sel); });&#10;    T(past.length ? 'undo' : 'undo0', 'Undo', past.length ? 'Undo the last change' : 'Nothing to undo', undo);&#10;    T(future.length ? 'redo' : 'redo0', 'Redo', future.length ? 'Redo what Undo took back' : 'Nothing to redo', redo);&#10;    sep();&#10;    T('picture', 'Picture', 'Choose a background picture', () =&gt; out(2));&#10;    if (state.bg)&#10;        T('edges', 'Edges', 'Show the edges in the picture (set them up in Properties)', () =&gt; { state.edges = !state.edges; sendAids(null); rebuild(); }, state.edges);&#10;    T('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;    T('timeline', 'Timeline', 'Animate the selected element in a loop: its Transparency, colour and the rest', () =&gt; { state.tlOpen = !state.tlOpen; state.auOpen = false; rebuild(); }, state.tlOpen);&#10;    T('audio', 'Audio', 'Let the selected element follow the sound on In A, or the beat of your DAW', () =&gt; { state.auOpen = !state.auOpen; state.tlOpen = false; rebuild(); }, state.auOpen);&#10;    T('snap', 'Snap', 'Snap to the other elements and the sides (Alt while dragging: no snap)', () =&gt; { state.snap = !state.snap; rebuild(); }, state.snap);&#10;    sep();&#10;    T('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, 8, H - 120, 'help', 'Help', 'How Cinemnode works', () =&gt; { help = help ? null : { tab: 0, screen: 0 }; rebuild(); }, !!help);&#10;    tool(g, 60, H - 120, 'panels', 'Panels', state.dock ? 'Hide the panels' : 'Show the panels', () =&gt; { state.dock = !state.dock; rebuild(); }, state.dock);&#10;    const done = g.group({ x: 8, y: H - 62, cursor: 'pointer', tooltip: 'Leave edit mode (double-click the Scene to come back)' });   // Done: as wide as both columns&#10;    done.rect({ w: 100, h: 50, radius: 8, fill: ACC });&#10;    icon(done, 'done', '#ffffff');&#10;    done.text({ x: 70, y: 21, text: 'Done', size: 16, align: 'center', baseline: 'middle', fill: '#ffffff', interactive: false });&#10;    done.on('click', e =&gt; { e.stop(); setEdit(false); });&#10;}&#10;&#10;// ---------- the panel ----------&#10;let sliders = [];&#10;&#10;// how wide a text is in the Scene's own font (wide, with a little room between the letters), measured on Danny's screen:&#10;// near enough to size buttons by, on the safe side&#10;function textW(t, size) {&#10;    let em = 0;&#10;    for (const ch of String(t))&#10;        em += ' '.includes(ch) ? 0.3 : 'il.,:;!|\'()[]'.includes(ch) ? 0.3 : 'fjrt1-'.includes(ch) ? 0.45 :&#10;              'MWmw'.includes(ch) ? 0.9 : /[A-Z0-9#&amp;%]/.test(ch) ? 0.7 : 0.6;&#10;    return em * size;&#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;    const size = Math.max(12, Math.min(18, 18 * (w - 14) / Math.max(1, textW(label, 18))));   // smaller where the label would not fit&#10;    b.text({ x: w / 2, y: 15, text: label, size: size, 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.min(w, Math.max(54, textW(n, 18) + 24));&#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;    if (auOn(it, 'r') || auOn(it, 'g') || auOn(it, 'b'))   // v6.8: or the sound moves it&#10;        return soundRow(g, x, y, 'Colour', it, ['r', 'g', 'b']) + 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: 22, 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: 19, 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: 16, baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;    return y + 42;&#10;}&#10;&#10;function lockedRow(g, x, y, label, note, sound) {   // a setting the timeline animates (or the sound moves): its name, and a link to that panel instead of a slider&#10;    g.text({ x: x, y: y + 11, text: fitLabel(label, 18, LBLW - 12), size: 18, baseline: 'middle', fill: '#c9c3e0', interactive: false });&#10;    const b = g.group({ x: x + LBLW, y: y, cursor: 'pointer', tooltip: sound ? 'Locked: the sound moves it. Click to open the Audio panel.' : 'Locked: the timeline animates it. Click to open the timeline.' });&#10;    b.circle({ x: 5, y: 11, r: 4.5, fill: sound ? '#f1995b' : ACC });&#10;    b.text({ x: 16, y: 11, text: note || 'animated on the timeline', size: 16, baseline: 'middle', fill: sound ? '#f1995b' : ACC });&#10;    b.on('click', e =&gt; { e.stop(); if (sound) { state.auOpen = true; state.tlOpen = false; } else state.tlOpen = true; rebuild(); });&#10;    return y + 30;&#10;}&#10;const soundRow = (g, x, y, label, it, keys) =&gt; lockedRow(g, x, y, label, 'follows the sound (' + [...new Set(keys.filter(k =&gt; auOn(it, k)).map(k =&gt; AUSRC[AUD(it)[k].src]))].join(', ') + ')', true);&#10;function aslider(g, x, y, w, label, it, key, get, setv, fmt) {   // a slider, locked while the timeline animates what it sets, or the sound moves it (v6.8)&#10;    if (!tlOn(it, key) &amp;&amp; auOn(it, key)) return soundRow(g, x, y, label, it, [key]);&#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 if (auOn(it, 'transp'))&#10;        y = soundRow(panel, 16, y, 'Transparency', it, ['transp']);&#10;    else&#10;        y = slider(panel, 16, y, PW - 32, 'Transparency', () =&gt; it.transp || 0, v =&gt; { it.transp = v; if (it.type === 'mask') tlDirty = true; }, 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;    else if (auOn(it, 'x') || auOn(it, 'y'))&#10;        y = soundRow(panel, 16, y, 'Position', it, ['x', 'y']);&#10;    return y;&#10;}&#10;&#10;let playHead = null;&#10;function drawTimeline() {&#10;    const x0 = TW, w = W - TW, y0 = H - TLH;   // v8.9: across under the dock too&#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: 16, 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: 18, baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;        return;&#10;    }&#10;    if (followNote(g, it, 'tlFrom', 'timeline')) return;&#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: 16, 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: 16, baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;    const lw = 120, lx = w - 128, val = g.text({ x: lx - 6, y: 21, text: tl.len.toFixed(1) + ' s', size: 15, 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; if (playHead) playHead.set({ bind: playHead.headBind() }); };&#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(60, textW(p[1], 18) + 24 + (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: 14, 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: 14, 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;    // v7.4: the play head, where the loop is now: the canvas moves it by itself, on the same clock as the shader&#10;    const headBind = () =&gt; ({ x: ['time', gx - 1, gx + gw - 1, 1 / tl.len] });&#10;    playHead = g.rect({ x: gx, y: gy, w: 2, h: gh, fill: '#ffffffb0', interactive: false, bind: headBind() });&#10;    playHead.headBind = headBind;&#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: 18, align: 'center', baseline: 'middle', fill: '#9a94b8', interactive: false });&#10;}&#10;&#10;function drawAudio() {   // the Audio panel: each setting of the selected element can follow a part of the sound, or the beat&#10;    const x0 = TW, w = W - TW, y0 = H - AUH;   // v8.9: across under the dock too&#10;    const g = layer.group({ x: x0, y: y0 });&#10;    g.rect({ w: w, h: AUH, fill: '#14121ff4', stroke: '#2f2850', strokeWidth: 1, interactive: true });&#10;    g.text({ x: 16, y: 20, text: 'AUDIO', size: 16, baseline: 'middle', fill: ACC, interactive: false });&#10;    // on the right: what comes in now (the Scene's own analysis of In A, and the bar from the DAW), and the sensitivity&#10;    const mx = w - 300;&#10;    g.text({ x: mx, y: 20, text: 'In A now', size: 16, baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;    [['Level', 'levelA'], ['Bass', 'bass'], ['Mid', 'mid'], ['High', 'treble'], ['Bar', 'P30']].forEach(([n, src], i) =&gt; {&#10;        const bx = mx + i * 56, by = 44, bh = 150;&#10;        g.rect({ x: bx, y: by, w: 40, h: bh, radius: 4, fill: '#0b0a12', stroke: '#2f2850', strokeWidth: 1, interactive: false });&#10;        g.rect({ x: bx + 2, y: by + bh - 2, w: 36, h: 0, radius: 3, fill: ACC, interactive: false,&#10;                 bind: { h: [src, 0, -(bh - 4), { smooth: 0.08 }] } });&#10;        g.text({ x: bx + 20, y: by + bh + 16, text: n, size: 15, align: 'center', baseline: 'middle', fill: '#c9c3e0', interactive: false });&#10;    });&#10;    g.text({ x: mx, y: 238, text: 'Sensitivity', size: 16, baseline: 'middle', fill: '#c9c3e0', interactive: false });&#10;    const sx = mx, sw = 270, sv = g.text({ x: mx + sw, y: 238, text: Math.round(state.ausens * 100) + '%', size: 15, align: 'right', baseline: 'middle', fill: '#c9c3e0', interactive: false });&#10;    const st = g.rect({ x: sx, y: 254, w: sw, h: 12, radius: 6, fill: '#1a1628', stroke: '#2f2850', strokeWidth: 1, cursor: 'ew-resize',&#10;                        tooltip: 'How loud the sound must be before it moves anything: higher, softer parts count too' });&#10;    const sf = g.rect({ x: sx, y: 254, w: sw * state.ausens, h: 12, radius: 6, fill: ACC, interactive: false });&#10;    const setS = ex =&gt; { state.ausens = Math.max(0, Math.min(1, (ex - x0 - sx) / sw)); sf.set({ w: sw * state.ausens }); sv.set({ text: Math.round(state.ausens * 100) + '%' }); sendAids(null); };&#10;    st.on('press', e =&gt; { e.stop(); setS(e.x); });&#10;    st.on('drag', e =&gt; { e.stop(); setS(e.x); });&#10;    g.text({ x: mx, y: 290, text: 'Beat, Bar: the DAW, while it plays.', size: 14, baseline: 'middle', fill: '#9a94b8', interactive: false });&#10;    g.text({ x: mx, y: 310, text: 'Sound: the plugin input, and the player', size: 14, baseline: 'middle', fill: '#9a94b8', interactive: false });&#10;    const it = selected();&#10;    if (!it || it.type === 'image') {&#10;        g.text({ x: 110, y: 20, text: it ? 'A picture cannot follow the sound (yet): select a board, a light or a mask.' : 'Select a board, a light or a mask to let it follow the sound.',&#10;                 size: 18, baseline: 'middle', fill: '#aaa4c6', interactive: false });&#10;        return;&#10;    }&#10;    g.text({ x: 110, y: 20, text: itemName(it), size: 16, baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;    if (followNote(g, it, 'auFrom', 'sound')) return;&#10;    const props = tlProps(it), RH2 = Math.max(22, Math.min(34, Math.floor((AUH - 50) / props.length))), BH = RH2 - 6, FS = RH2 &lt; 30 ? 13 : 15,   // rows close up when a shader adds its P's&#10;           nw = 150, cw = 66, ax = 16 + nw + AUSRC.length * (cw + 4) + 10, aw = Math.max(80, mx - 30 - ax - 56);&#10;    props.forEach((p, i) =&gt; {&#10;        const key = p[0], y = 44 + i * RH2, cy = y + BH / 2, a = (it.au &amp;&amp; it.au[key]) || { src: 0, amt: 0.5 };&#10;        g.text({ x: 16, y: cy, text: p[1], size: FS + 1, baseline: 'middle', fill: a.src ? '#ffffff' : '#c9c3e0', interactive: false });&#10;        AUSRC.forEach((n, k) =&gt; {&#10;            const b = g.group({ x: 16 + nw + k * (cw + 4), y: y, cursor: 'pointer', tooltip: k ? 'Follow ' + n.toLowerCase() : 'Not following the sound' });&#10;            const on = a.src === k;&#10;            b.rect({ w: cw, h: BH, radius: 6, fill: on ? (k ? ACC : '#2a2440') : '#1a1628', stroke: on ? ACC : '#2f2850', strokeWidth: 1 });&#10;            b.text({ x: cw / 2, y: BH / 2, text: n, size: FS, align: 'center', baseline: 'middle', fill: on ? '#ffffff' : '#c9c3e0', interactive: false });&#10;            b.on('click', e =&gt; { e.stop(); it.au = it.au || {}; it.au[key] = { src: k, amt: a.amt }; if (!k) delete it.au[key]; sendCode(); rebuild(); });&#10;        });&#10;        if (!a.src) return;&#10;        // how far: -100% (down) to +100% (up), from the middle&#10;        const val = g.text({ x: ax + aw + 56, y: cy, text: Math.round(a.amt * 100) + '%', size: 15, align: 'right', baseline: 'middle', fill: '#c9c3e0', interactive: false });&#10;        const tr = g.rect({ x: ax, y: cy - 6, w: aw, h: 12, radius: 6, fill: '#1a1628', stroke: '#2f2850', strokeWidth: 1, cursor: 'ew-resize',&#10;                            tooltip: 'How far the sound moves it: right up, left down' });&#10;        g.line({ x1: ax + aw / 2, y1: cy - 9, x2: ax + aw / 2, y2: cy + 9, width: 1, stroke: '#5c5774', interactive: false });&#10;        const fill = g.rect({ x: ax + aw / 2, y: cy - 6, w: 0, h: 12, radius: 6, fill: ACC, interactive: false });&#10;        const show = () =&gt; { const v = it.au[key].amt; fill.set({ x: ax + aw / 2 + Math.min(0, v) * aw / 2, w: Math.abs(v) * aw / 2 }); val.set({ text: Math.round(v * 100) + '%' }); };&#10;        const set = ex =&gt; { it.au[key].amt = Math.round(Math.max(-1, Math.min(1, ((ex - x0 - ax) / aw) * 2 - 1)) * 100) / 100; show(); tlDirty = true; };&#10;        tr.on('press', e =&gt; { e.stop(); set(e.x); });&#10;        tr.on('drag', e =&gt; { e.stop(); set(e.x); });&#10;        tr.on('release', () =&gt; { if (tlDirty) { tlDirty = false; sendCode(); } });&#10;        show();&#10;    });&#10;}&#10;&#10;const LBLW = 210;   // the width of a slider's name (the track takes the rest)&#10;function fitLabel(t, size, w) {   // a name cut short with ... where it would run under the slider (the font is a little wider than textW thinks)&#10;    t = String(t);&#10;    if (textW(t, size) * 1.15 &lt;= w) return t;&#10;    while (t.length &gt; 1 &amp;&amp; textW(t + '...', size) * 1.15 &gt; w) t = t.slice(0, -1);&#10;    return t.trimEnd() + '...';&#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: fitLabel(label, 18, LBLW - 12), size: 18, baseline: 'middle', fill: '#e4def5', interactive: false });&#10;    const val = fmt ? g.text({ x: x + w, y: y + 11, text: fmt(get()), size: 16, align: 'right', baseline: 'middle', fill: '#c9c3e0', interactive: false }) : null;&#10;    const show = () =&gt; { if (val) val.set({ text: fmt(get()) }); };&#10;    const tx = x + LBLW, tw = w - LBLW - (fmt ? 56 : 0);   // the value sits right of the track, so a long name never runs into it&#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', tooltip: String(label) });   // the whole name, when it was cut short&#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;const dockH = () =&gt; H - (state.tlOpen ? TLH : state.auOpen ? AUH : 0);   // v8.9: the dock stops above the timeline or the Audio panel&#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: 16, baseline: 'middle', fill: ACC, interactive: false });&#10;    if (sub)&#10;        h.text({ x: 34 + name.length * 11.5 + 14, y: 16, text: sub, size: 16, baseline: 'middle', fill: '#aaa4c6', 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: dockH() / 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: 25, 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 DH = dockH();&#10;    const bg = panel.rect({ w: DW, h: DH, fill: '#14121ff4', stroke: '#2f2850', strokeWidth: 1, interactive: true });&#10;    dockTab(panel, -22, true);&#10;    const g = panel.group({ clip: [0, 0, DW, DH] }).group({ x: 0, y: -(state.dscroll || 0) });   // what is in it, scrolled by the wheel when it is too long (v8.9: cut off at the dock's foot)&#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;    // v7.6: Layers stays at the bottom of the dock, always in view; Properties scrolls above it&#10;    // v7.7: Layers gives way to Properties: it takes only the room left under Properties, down to 3 rows; below that Properties scrolls&#10;    lcap = Math.max(3, Math.floor((DH - y - 20 - 50) / 30));&#10;    const nl = state.items.length, lh = state.openL ? (nl ? layerRows(state.items) * 30 + 6 : 36) + 44 : 40;&#10;    const lg = panel.group({ x: 0, y: DH - lh });&#10;    const lbg = lg.rect({ w: DW, h: lh, fill: '#14121f', stroke: '#2f2850', strokeWidth: 1, interactive: true });&#10;    lbg.on('wheel', e =&gt; e.stop());&#10;    let ly = section(lg, 0, 'LAYERS', 'top = front' + (nl &gt; layerRows(state.items) &amp;&amp; state.openL ? ' - ' + nl + ' in all' : ''), state.openL, () =&gt; state.openL = !state.openL);&#10;    lbox = null; lboxAt = null;&#10;    if (state.openL)&#10;        drawLayers(lg, ly, DW);&#10;    let most = Math.max(0, y + 20 - (DH - lh)), moreT = null;&#10;    if (most &gt; 0) {   // Properties goes on under Layers: say so (a strip of its own, so nothing hides under it)&#10;        most += 22;&#10;        const more = lg.group({ x: 0, y: -22 });&#10;        more.rect({ w: DW, h: 22, fill: '#14121f', interactive: false });&#10;        moreT = more.text({ x: DW / 2, y: 11, text: '', size: 13, align: 'center', baseline: 'middle', fill: '#7f7a99', interactive: false });&#10;    }&#10;    const label = () =&gt; { if (moreT) moreT.set({ text: (state.dscroll || 0) &lt; most ? 'more settings below - scroll' : 'end of the settings' }); };&#10;    if ((state.dscroll || 0) &gt; most) { state.dscroll = most; g.set({ y: -most }); }&#10;    label();&#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 }); label(); }&#10;    });&#10;}&#10;&#10;// ---------- your own shader on a board (Shader code): Shadertoy's mainImage(out vec4, in vec2), run in the board ----------&#10;// Its names get a tag of their own (so they meet nothing of Cinemnode's or of another shader), iResolution is the board's&#10;// size in pixels, iTime its time (Speed), iMouse is still, iChannel0 the sound on In A, iChannel1-3 the background.&#10;function glslHash(src) { let h = 5381; for (let i = 0; i &lt; src.length; i++) h = ((h * 33) ^ src.charCodeAt(i)) &gt;&gt;&gt; 0; return h.toString(36); }&#10;function glslCheck(src) {   // what is surely wrong before the graphics card sees it ('' when nothing)&#10;    const isfBad = src.match(/^\/\/ ISF not usable: (.*)/);&#10;    if (isfBad) return isfBad[1];&#10;    if (!/\bvoid\s+mainImage\s*\(/.test(src)) return 'no mainImage(out vec4 fragColor, in vec2 fragCoord) in it';&#10;    let d = 0;&#10;    for (const ch of src.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '')) { if (ch === '{') d++; else if (ch === '}' &amp;&amp; --d &lt; 0) break; }&#10;    if (d !== 0) return 'its { and } do not pair up';&#10;    if (/#pass\b|\bmain\s*\(\s*\)/.test(src)) return 'only one pass with mainImage can run on a board';&#10;    return '';&#10;}&#10;function glslOf(it) { return it.glsl &amp;&amp; !glslCheck(it.glsl) ? it.glsl : ''; }&#10;function glslAdapt(src) {&#10;    const tag = 'u' + glslHash(src);&#10;    let c = src.replace(/\r/g, '').replace(/^\s*(#version|precision|uniform)\b.*$/gm, '');&#10;    const top = c.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/\/\/.*$/gm, '');&#10;    let flat = '', d = 0;   // the code outside every { }: where its own names are made&#10;    for (const ch of top) { if (ch === '{') { d++; flat += ';'; } else if (ch === '}') { d--; flat += ';'; } else if (!d) flat += ch; }&#10;    const names = new Set();&#10;    for (const m of flat.matchAll(/#define\s+([A-Za-z_]\w*)/g)) names.add(m[1]);&#10;    for (const m of flat.matchAll(/\bstruct\s+([A-Za-z_]\w*)/g)) names.add(m[1]);&#10;    for (const m of flat.matchAll(/(?:^|;)\s*(?:(?:const|in|highp|mediump|lowp)\s+)*[A-Za-z_]\w*\s+([A-Za-z_]\w*)\s*\(/gm)) names.add(m[1]);&#10;    for (const m of flat.matchAll(/(?:^|;)\s*(?:(?:const|highp|mediump|lowp)\s+)*(?:float|int|uint|bool|[iu]?vec[234]|mat[234](?:x[234])?)\s+([^;(]+)(?=;)/gm))&#10;        m[1].split(',').forEach(v =&gt; { const n = (v.match(/^\s*([A-Za-z_]\w*)/) || [])[1]; if (n) names.add(n); });&#10;    names.delete('main');&#10;    for (const n of names)&#10;        c = c.replace(new RegExp('\\b' + n + '\\b', 'g'), n + '_' + tag);&#10;    c = c.replace(/\biResolution\b/g, 'csR_' + tag).replace(/\biTime\b/g, 'csT_' + tag).replace(/\biTimeDelta\b/g, '0.0333')&#10;         .replace(/\biMouse\b/g, 'vec4(0.0)').replace(/\biDate\b/g, 'vec4(2026.0, 1.0, 1.0, csT_' + tag + ')')&#10;         .replace(/\biChannelResolution\s*\[\s*\d+\s*\]/g, 'iResolution').replace(/\biChannelTime\s*\[\s*\d+\s*\]/g, 'csT_' + tag)&#10;         .replace(/\biChannel([123])\b/g, state.bg ? 'iImage0' : 'iChannel0').replace(/\biFrame\b/g, 'int(csT_' + tag + ' * 30.0)')&#10;         .replace(/\bP([1-9]\d?)\b/g, (a, n) =&gt; +n &lt;= 8 ? 'csP' + (+n &lt;= 4 ? 'a' : 'b') + '_' + tag + '.' + 'xyzw'[(n - 1) % 4] : '0.5');   // its P1-P8: the board's own sliders&#10;    return { tag: tag, code: '// ---- your own shader (Shader code) ----\nvec3 csR_' + tag + '; float csT_' + tag + '; vec4 csPa_' + tag + ', csPb_' + tag + ';\n' + c + '\n' +&#10;        'vec4 csRun_' + tag + '(vec2 m, float t, vec2 res, vec4 pa, vec4 pb) {\n    csR_' + tag + ' = vec3(res, 1.0); csT_' + tag + ' = t; csPa_' + tag + ' = pa; csPb_' + tag + ' = pb;\n' +&#10;        '    vec4 o = vec4(0.0, 0.0, 0.0, 1.0);\n    mainImage_' + tag + '(o, vec2(m.x, 1.0 - m.y) * res);\n    return o;\n}\n' };&#10;}&#10;function glslCall(it) {   // the board's pixels, as the shader is told; then how it lies on the picture (its Kind)&#10;    const q = boardQuad(it), len = (a, b) =&gt; Math.hypot(q[b][0] - q[a][0], (q[b][1] - q[a][1]) * H / W);&#10;    const bw = (len(0, 1) + len(3, 2)) / 2, bh = (len(0, 3) + len(1, 2)) / 2 * W / H;&#10;    const up = glslP(it);&#10;    const pv = up.map((v, i) =&gt; AN(it, 'p' + (i + 1), f(v)));   // each P as it is, or moved by the timeline or the sound&#10;    const call = 'csRun_' + glslAdapt(glslOf(it)).tag + '(m, t, vec2(' + f(Math.max(0.01, bw)) + ', ' + f(Math.max(0.01, bh)) + ') * R, vec4(' +&#10;                 pv.slice(0, 4).join(', ') + '), vec4(' + pv.slice(4).join(', ') + '))';&#10;    return (it.style || 0) === 1 ? 'seeThrough(' + call + ')' : 'vec4(' + call + '.rgb, 1.0)';&#10;}&#10;// v8.8: ISF (the Interactive Shader Format of VDMX, Resolume and others): a JSON block at the top, then main() with&#10;// gl_FragColor. It is turned into Shadertoy's mainImage here, so it runs as any Shader code board does. Its INPUTS become&#10;// the board's P1-P8 (a number, a switch or a list one each, a point two, a colour three), each from MIN to MAX and starting&#10;// at its DEFAULT; what does not fit stays at its DEFAULT. An image input is the background picture, an audio one the sound&#10;// on In A. One pass only: shaders with PASSES of their own or pictures of their own are not run.&#10;const isISF = src =&gt; /^\s*\/\*\s*\{[\s\S]*?&quot;(?:INPUTS|ISFVSN|CATEGORIES|DESCRIPTION|CREDIT)&quot;[\s\S]*?\}\s*\*\//.test(src) &amp;&amp; /\bvoid\s+main\s*\(/.test(src);&#10;function isfArgs(s, at) {   // the arguments of a call whose ( is at s[at], and where it ends&#10;    const args = []; let d = 0, cur = '', i = at + 1;&#10;    for (; i &lt; s.length; i++) {&#10;        const ch = s[i];&#10;        if (ch === '(') d++;&#10;        else if (ch === ')') { if (!d) break; d--; }&#10;        else if (ch === ',' &amp;&amp; !d) { args.push(cur.trim()); cur = ''; continue; }&#10;        cur += ch;&#10;    }&#10;    args.push(cur.trim());&#10;    return { args: args, end: i + 1 };&#10;}&#10;function isfConvert(src) {   // -&gt; { code (Shadertoy style), up (the P to start with), sig (its inputs), err }&#10;    src = src.replace(/\r/g, '');&#10;    const m = src.match(/^\s*\/\*\s*(\{[\s\S]*?\})\s*\*\//);&#10;    let head;&#10;    try { head = JSON.parse(m[1].replace(/,(\s*[}\]])/g, '$1')); } catch (e) { return { err: 'its JSON block at the top does not read' }; }&#10;    const passes = head.PASSES || [];&#10;    if (passes.length &gt; 1 || passes.some(p =&gt; p.TARGET || p.PERSISTENT)) return { err: 'it has passes of its own (only one pass can run on a board)' };&#10;    if (head.IMPORTED &amp;&amp; Object.keys(head.IMPORTED).length) return { err: 'it needs pictures of its own (IMPORTED)' };&#10;    let code = src.slice(m[0].length);&#10;    const up = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5], defs = [], names = [], chans = {};&#10;    let n = 0;&#10;    const g = v =&gt; { const x = Number(v); return isFinite(x) ? (Math.round(x * 1e5) / 1e5).toString().replace(/^(-?\d+)$/, '$1.0') : '0.0'; };&#10;    const label = s =&gt; { const t = s.replace(/([a-z])([A-Z0-9])/g, '$1 $2').replace(/[^A-Za-z0-9]+/g, ' ').trim().toLowerCase().slice(0, 20).trim(); return t ? t[0].toUpperCase() + t.slice(1) : 'Value'; };&#10;    const P = (k, def, name) =&gt; { up[k] = Math.max(0, Math.min(1, def)); names.push('// P' + (k + 1) + ' ' + label(name)); return 'P' + (k + 1); };&#10;    for (const inp of head.INPUTS || []) {&#10;        const nm = inp.NAME, t = inp.TYPE;&#10;        if (!nm || !/^[A-Za-z_]\w*$/.test(nm)) continue;&#10;        if (t === 'image') { chans[nm] = 'iChannel1'; continue; }&#10;        if (t === 'audio' || t === 'audioFFT') { chans[nm] = 'iChannel0'; continue; }&#10;        const lo = inp.MIN !== undefined ? Number(inp.MIN) : 0, hi = inp.MAX !== undefined ? Number(inp.MAX) : 1;&#10;        if (t === 'float') {&#10;            const d = inp.DEFAULT !== undefined ? Number(inp.DEFAULT) : (lo + hi) / 2;&#10;            defs.push('#define ' + nm + ' ' + (n &lt; 8 ? '(' + g(lo) + ' + ' + P(n++, hi &gt; lo ? (d - lo) / (hi - lo) : 0, inp.LABEL || nm) + ' * ' + g(hi - lo) + ')' : g(d)));&#10;        } else if (t === 'bool' || t === 'event') {&#10;            const d = t === 'bool' &amp;&amp; inp.DEFAULT ? 1 : 0;&#10;            defs.push('#define ' + nm + ' ' + (n &lt; 8 ? '(' + P(n++, d ? 0.75 : 0.25, inp.LABEL || nm) + ' &gt; 0.5)' : d ? 'true' : 'false'));&#10;        } else if (t === 'long') {&#10;            const vals = (inp.VALUES || []).map(Number).filter(isFinite);&#10;            const list = vals.length ? vals : [Math.round(lo), Math.round(hi)];&#10;            const d = Math.max(0, list.indexOf(Number(inp.DEFAULT)));&#10;            if (n &lt; 8 &amp;&amp; list.length &gt; 1) {&#10;                const p = P(n++, (d + 0.5) / list.length, inp.LABEL || nm);&#10;                defs.push('#define ' + nm + ' ' + list.slice(0, -1).reduceRight((acc, v, i) =&gt; '(' + p + ' &lt; ' + g((i + 1) / list.length) + ' ? ' + (v | 0) + ' : ' + acc + ')', String(list[list.length - 1] | 0)));&#10;            } else defs.push('#define ' + nm + ' ' + (list[d] | 0));&#10;        } else if (t === 'point2D') {&#10;            const d = inp.DEFAULT || [0, 0], plo = inp.MIN || null, phi = inp.MAX || null;&#10;            if (n + 2 &lt;= 8 &amp;&amp; plo &amp;&amp; phi) {&#10;                const px = P(n++, (d[0] - plo[0]) / ((phi[0] - plo[0]) || 1), (inp.LABEL || nm) + ' x'), py = P(n++, (d[1] - plo[1]) / ((phi[1] - plo[1]) || 1), (inp.LABEL || nm) + ' y');&#10;                defs.push('#define ' + nm + ' vec2(' + g(plo[0]) + ' + ' + px + ' * ' + g(phi[0] - plo[0]) + ', ' + g(plo[1]) + ' + ' + py + ' * ' + g(phi[1] - plo[1]) + ')');&#10;            } else if (n + 2 &lt;= 8) {   // no MIN and MAX: across the board, in pixels&#10;                const px = P(n++, 0.5, (inp.LABEL || nm) + ' x'), py = P(n++, 0.5, (inp.LABEL || nm) + ' y');&#10;                defs.push('#define ' + nm + ' (vec2(' + px + ', ' + py + ') * iResolution.xy)');&#10;            } else defs.push('#define ' + nm + ' vec2(' + g(d[0]) + ', ' + g(d[1]) + ')');&#10;        } else if (t === 'color') {&#10;            const d = inp.DEFAULT || [1, 1, 1, 1];&#10;            if (n + 3 &lt;= 8) {&#10;                const L = inp.LABEL || nm, r = P(n++, d[0], L + ' red'), gg = P(n++, d[1], L + ' green'), b = P(n++, d[2], L + ' blue');&#10;                defs.push('#define ' + nm + ' vec4(' + r + ', ' + gg + ', ' + b + ', ' + g(d[3] === undefined ? 1 : d[3]) + ')');&#10;            } else defs.push('#define ' + nm + ' vec4(' + [0, 1, 2, 3].map(i =&gt; g(d[i] === undefined ? 1 : d[i])).join(', ') + ')');&#10;        }&#10;    }&#10;    // the picture calls: IMG_NORM_PIXEL(name, uv), IMG_PIXEL(name, pixels), IMG_THIS_(NORM_)PIXEL(name), IMG_SIZE(name)&#10;    const ch = nm =&gt; chans[nm] || 'iChannel1';&#10;    let out = '', i = 0;&#10;    const re = /\b(IMG_NORM_PIXEL|IMG_PIXEL|IMG_THIS_NORM_PIXEL|IMG_THIS_PIXEL|IMG_SIZE)\s*\(/g;&#10;    let r;&#10;    while ((r = re.exec(code))) {&#10;        const a = isfArgs(code, r.index + r[0].length - 1);&#10;        out += code.slice(i, r.index);&#10;        const f = r[1], c = ch(a.args[0]);&#10;        out += f === 'IMG_NORM_PIXEL' ? 'texture(' + c + ', ' + a.args[1] + ')' : f === 'IMG_PIXEL' ? 'texture(' + c + ', (' + a.args[1] + ') / iResolution.xy)' :&#10;               f === 'IMG_SIZE' ? 'iResolution.xy' : 'texture(' + c + ', isfNC)';&#10;        i = re.lastIndex = a.end;&#10;    }&#10;    code = out + code.slice(i);&#10;    for (const nm in chans) code = code.replace(new RegExp('\\b' + nm + '\\b', 'g'), chans[nm]);   // texture2D(inputImage, ...) and the like&#10;    code = code.replace(/\btexture2D(Rect)?\b/g, 'texture').replace(/\bRENDERSIZE\b/g, 'iResolution.xy').replace(/\bTIMEDELTA\b/g, 'iTimeDelta')&#10;               .replace(/\bTIME\b/g, 'iTime').replace(/\bFRAMEINDEX\b/g, 'iFrame').replace(/\bDATE\b/g, 'iDate').replace(/\bPASSINDEX\b/g, '0')&#10;               .replace(/\b(?:isf|vv)_FragNormCoord\b/g, 'isfNC').replace(/\bgl_FragCoord\b/g, 'vec4(isfFC, 0.0, 1.0)').replace(/\bgl_FragColor\b/g, 'isfOut')&#10;               .replace(/^\s*uniform\b.*$/gm, '');&#10;    // what its own vertex shader (.vs) would hand it: here plain values, the usual neighbour places worked out (left_coord, above_coord, ...)&#10;    const vary = new Set();&#10;    code = code.replace(/^(\s*)(?:varying|in)\s+((?:highp|mediump|lowp)\s+)?(float|vec[234])\s+([A-Za-z_]\w*)\s*;/gm, (a, sp, pr, ty, nm) =&gt; { if (ty === 'vec2') vary.add(nm); return sp + ty + ' ' + nm + ';'; });&#10;    const near = nm =&gt; { const k = nm.toLowerCase(), dx = /left/.test(k) ? -1 : /right/.test(k) ? 1 : 0;&#10;        const dy = /above|up/.test(k) || /^(left|right)a/.test(k) ? 1 : /below|down/.test(k) || /^(left|right)b/.test(k) ? -1 : 0;&#10;        return '    ' + nm + ' = isfNC + vec2(' + dx + '.0, ' + dy + '.0) / iResolution.xy;'; };&#10;    const mm = code.match(/\bvoid\s+main\s*\(\s*(void)?\s*\)\s*\{/);&#10;    if (!mm) return { err: 'no main() in it' };&#10;    code = code.slice(0, mm.index) + 'void mainImage(out vec4 isfOut, in vec2 isfCoord)\n{\n    isfFC = isfCoord; isfNC = isfCoord / iResolution.xy;\n' + [...vary].map(near).join('\n') + code.slice(mm.index + mm[0].length);&#10;    return { code: '// ISF' + (head.DESCRIPTION ? ': ' + String(head.DESCRIPTION).split('\n')[0].slice(0, 60) : '') + '\n' + names.join('\n') + '\n' + defs.join('\n') + '\nvec2 isfFC;\nvec2 isfNC;\n' + code,&#10;             up: up, sig: (head.INPUTS || []).map(x =&gt; x.NAME + ':' + x.TYPE).join(',') };&#10;}&#10;function isfUse(t, src) {   // a board takes an ISF shader: its code, and its sliders at their DEFAULT when its inputs are new&#10;    const r = isfConvert(src);&#10;    if (r.err) { t.glsl = '// ISF not usable: ' + r.err + '\n'; t.isf = true; return; }&#10;    t.glsl = r.code; t.isf = true;&#10;    if (t.isfSig !== r.sig) { t.up = r.up; t.isfSig = r.sig; }&#10;}&#10;let wantGlsl = 0;   // the board a shader file is being read for&#10;let glslPend = 0;   // ticks until a P slider's new value goes into a new shader (one when you stop moving it)&#10;function glslP(it) { if (!it.up) it.up = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]; return it.up; }&#10;function glslPNames(src) {   // the P1-P8 the code uses, with a name from its comments where it gives one (&quot;P2 cell size&quot;)&#10;    const used = [...new Set([...src.matchAll(/\bP([1-8])\b/g)].map(m =&gt; +m[1]))].sort((a, b) =&gt; a - b), names = {};&#10;    for (const line of src.split('\n').filter(l =&gt; /\/\//.test(l)))&#10;        for (const m of line.slice(line.indexOf('//')).matchAll(/\bP([1-8])\b[\s:=-]+([A-Za-z][A-Za-z0-9 ]{0,18}[A-Za-z0-9])/g))&#10;            if (!names[m[1]]) names[m[1]] = m[2];&#10;    return used.map(n =&gt; [n, names[n] ? 'P' + n + ' ' + names[n] : 'P' + n]);&#10;}&#10;// the paste box (a Text Input on the front panel, over the picture's top left): only while a Shader code board is&#10;// selected in Edit; shown and hidden through the MilkDrop Player's Out 6 (this Script has no output left)&#10;let glslBoxOn = null;&#10;function glslBox() {&#10;    // opened with Paste code (a Shader code board) or Type text (a text board), at the top&#10;    const it = selected(), kind = state.edit &amp;&amp; state.boxOpen === 'scene' &amp;&amp; !it ? 'scene' :&#10;                                  state.edit &amp;&amp; it &amp;&amp; it.type === 'board' ? (it.fx === 60 &amp;&amp; state.boxOpen === 'code' ? 'code' : it.fx === 1 &amp;&amp; state.boxOpen === 'text' ? 'text' : '') : '';&#10;    const key = kind + (kind === 'text' ? it.id : '');&#10;    if (key !== glslBoxOn) {&#10;        glslBoxOn = key;&#10;        mdSend({ forward: kind === 'scene' ? { visible: true, sendLabel: 'Use name', placeholder: 'The name of this scene, then Use name', text: state.scenes[state.scene].name } :&#10;                          kind === 'text' ? { visible: true, sendLabel: 'Use text', placeholder: 'Type the text for this board (up to 3 lines), then Use text', text: textLines(it).join('\n') } :&#10;                          kind === 'code' ? { visible: true, sendLabel: 'Use code', placeholder: 'Paste your shader code here (Shadertoy mainImage or ISF), then Use code' } : { visible: false } });&#10;    }&#10;}&#10;function glslClean(t) { return t.replace(/&amp;lt;/g, '&lt;').replace(/&amp;gt;/g, '&gt;').replace(/&amp;#39;/g, &quot;'&quot;).replace(/&amp;quot;/g, '&quot;').replace(/&amp;amp;/g, '&amp;'); }&#10;&#10;// the playlist: the presets added, the one playing lit; click one to play it, &lt; and &gt; step through the list&#10;const MDROWS = 8, MDCOL = ['#5fe08a', '#f1c75b', '#f1995b', '#ff6b7a'];&#10;// v8.1: the playlist's rows in a group of their own: the wheel redraws only them, not the whole editor&#10;let mdBox = null, mdAt = null;&#10;function mdScroll(d) {&#10;    const md = state.md, s = Math.max(0, Math.min((md.lscroll || 0) + d, md.list.length - MDROWS));&#10;    if (s === md.lscroll || !mdAt) return;&#10;    md.lscroll = s;&#10;    mdRows(mdAt.panel, mdAt.y, mdAt.PW);&#10;}&#10;function mdRows(panel, y, PW) {&#10;    const md = state.md, RH = 30, L = md.list;&#10;    if (mdBox &amp;&amp; mdAt &amp;&amp; mdAt.panel === panel) mdBox.remove();&#10;    mdAt = { panel: panel, y: y, PW: PW };&#10;    const g = mdBox = panel.group({ x: 0, y: 0 });&#10;    md.lscroll = Math.max(0, Math.min(md.lscroll || 0, L.length - MDROWS));&#10;    const catcher = g.rect({ x: 0, y: y - 2, w: PW, h: Math.min(L.length, MDROWS) * RH + 4, fill: '#00000000', interactive: true });   // the wheel between the rows too&#10;    catcher.on('wheel', e =&gt; { e.stop(); mdScroll(e.delta &gt; 0 ? -1 : 1); });&#10;    L.slice(md.lscroll, md.lscroll + MDROWS).forEach((path, v) =&gt; {&#10;        const i = v + md.lscroll, on = path === md.file;&#10;        const row = g.group({ x: 16, y: y });&#10;        const rb = row.rect({ w: PW - 32, h: RH - 4, radius: 6, fill: on ? '#8a3fff38' : '#00000000', stroke: on ? ACC : '#2f2850', strokeWidth: 1, cursor: 'pointer', tooltip: 'Play' });&#10;        rb.on('click', e =&gt; { e.stop(); mdPlay(path); });&#10;        rb.on('wheel', e =&gt; { e.stop(); mdScroll(e.delta &gt; 0 ? -1 : 1); });&#10;        const lv = md.levels[path];&#10;        row.circle({ x: 14, y: (RH - 4) / 2, r: 5, fill: lv === undefined ? '#5c5774' : MDCOL[lv], interactive: false, tooltip: '' });&#10;        let name = path.split(/[\\/]/).pop().replace(/\.milk2?$/i, '');&#10;        while (name.length &gt; 4 &amp;&amp; textW(name, 16) &gt; PW - 32 - 130) name = name.slice(0, -2);&#10;        if (name !== path.split(/[\\/]/).pop().replace(/\.milk2?$/i, '')) name += '...';&#10;        row.text({ x: 28, y: (RH - 4) / 2, text: (i + 1) + '  ' + name, size: 16, baseline: 'middle', fill: on ? NAMESEL : '#f1ecff', interactive: false });&#10;        const mv = (d) =&gt; { const j = i + d; if (j &lt; 0 || j &gt;= L.length) return; L[i] = L[j]; L[j] = path; rebuild(); };&#10;        const up = row.triangle({ x1: PW - 112, y1: 18, x2: PW - 100, y2: 18, x3: PW - 106, y3: 8, fill: '#b8b2d0', cursor: 'pointer', tooltip: 'Up' });&#10;        up.on('click', e =&gt; { e.stop(); mv(-1); });&#10;        const dn = row.triangle({ x1: PW - 92, y1: 8, x2: PW - 80, y2: 8, x3: PW - 86, y3: 18, fill: '#b8b2d0', cursor: 'pointer', tooltip: 'Down' });&#10;        dn.on('click', e =&gt; { e.stop(); mv(1); });&#10;        const tb = row.rect({ x: PW - 72, y: 0, w: 28, h: RH - 4, fill: '#00000000', cursor: 'pointer', tooltip: 'Take out of the list' });&#10;        tb.on('click', e =&gt; { e.stop(); L.splice(i, 1); rebuild(); });&#10;        trash(row, PW - 58, (RH - 4) / 2, true);&#10;        y += RH;&#10;    });&#10;    if (L.length &gt; MDROWS) {&#10;        g.text({ x: 16, y: y + 6, text: (md.lscroll + 1) + '-' + Math.min(L.length, md.lscroll + MDROWS) + ' of ' + L.length + ' - scroll for more', size: 14, baseline: 'middle', fill: '#5c5774', interactive: false });&#10;        y += 18;&#10;    }&#10;    return y;&#10;}&#10;function mdList(panel, y, PW) {&#10;    const md = state.md, RH = 30, L = md.list;&#10;    if (!L.length) {&#10;        panel.text({ x: 16, y: y + 10, text: 'No presets yet: Add preset... picks a .milk or .milk2 file', size: 15, fill: '#b8b2d0', baseline: 'middle', interactive: false });&#10;        return y + 30;&#10;    }&#10;    y = mdRows(panel, y, PW);&#10;    button(panel, 16, y + 4, 110, '&lt; Prev', () =&gt; mdStep(-1), false);&#10;    button(panel, 132, y + 4, 110, 'Next &gt;', () =&gt; mdStep(1), false);&#10;    return y + 44;&#10;}&#10;&#10;// Shader code's part of Properties&#10;function glslPanel(panel, y, PW, it) {&#10;    const T = (t, yy, size, fill) =&gt; panel.text({ x: 16, y: yy, text: t, size: size, fill: fill, baseline: 'middle', interactive: false });&#10;    T('SHADER CODE - Shadertoy (mainImage) or ISF', y + 6, 16, '#aaa4c6');&#10;    y += 18;&#10;    button(panel, 16, y, 170, 'Load file...', () =&gt; { wantGlsl = it.id; wantMd = 'glsl'; out(2); }, false);&#10;    button(panel, 192, y, 150, state.boxOpen === 'code' ? 'Close box' : 'Paste code', () =&gt; { state.boxOpen = state.boxOpen === 'code' ? '' : 'code'; glslBox(); rebuild(); }, state.boxOpen === 'code');&#10;    button(panel, 348, y, 110, 'Clear', () =&gt; { delete it.glsl; delete it.glslFile; delete it.isf; delete it.isfSig; sendCode(); rebuild(); }, false);&#10;    y += 40;&#10;    if (!it.glsl) {&#10;        T('Load a .glsl, .frag or .fs (ISF) file, or press Paste code: a box opens', y + 6, 15, '#b8b2d0');&#10;        T('at the top; paste the code there and press Use code.', y + 26, 15, '#b8b2d0');&#10;        return y + 44;&#10;    }&#10;    const bad = glslCheck(it.glsl);&#10;    T((it.glslFile ? it.glslFile.split(/[\\/]/).pop() : 'pasted code') + (it.isf ? ' - ISF' : ' - ' + it.glsl.split('\n').length + ' lines'), y + 6, 15, '#b8b2d0');&#10;    T(bad ? 'Not used: ' + bad : 'In use.', y + 28, 15, bad ? '#ff6b7a' : '#5fe08a');&#10;    T('If the picture stops changing, the code has a mistake:', y + 50, 14, '#7f7a99');&#10;    T('the Scene keeps its last good shader and shows the error.', y + 68, 14, '#7f7a99');&#10;    if (it.glslFile)&#10;        T('Saving the file again brings the new code in by itself.', y + 86, 14, '#7f7a99');&#10;    y += it.glslFile ? 106 : 88;&#10;    // its own P1-P8 (Cinemnode's P are the board's corners): a new shader when you let go&#10;    glslPNames(it.glsl).forEach(([n, name]) =&gt; {&#10;        if (tlOn(it, 'p' + n))&#10;            y = lockedRow(panel, 16, y, name);&#10;        else if (auOn(it, 'p' + n))&#10;            y = soundRow(panel, 16, y, name, it, ['p' + n]);&#10;        else&#10;            y = slider(panel, 16, y, PW - 32, name, () =&gt; glslP(it)[n - 1], v =&gt; { glslP(it)[n - 1] = v; glslPend = 8; }, v =&gt; v.toFixed(2));&#10;    });&#10;    return y + 4;&#10;}&#10;&#10;// the MilkDrop window's part of Properties: which preset the player plays, its pictures, and what it made of it&#10;function mdPanel(panel, y, PW) {&#10;    const md = state.md, st = md.status, T = (t, yy, size, fill) =&gt; panel.text({ x: 16, y: yy, text: t, size: size, fill: fill, baseline: 'middle', interactive: false });&#10;    T('MILKDROP - the player shows through this board', y + 6, 16, '#aaa4c6');&#10;    y += 18;&#10;    button(panel, 16, y, 170, 'Add preset...', () =&gt; { wantMd = 'file'; out(2); }, false);&#10;    button(panel, 192, y, 190, 'Textures folder...', () =&gt; { wantMd = 'tex'; out(2); }, false);&#10;    y = mdList(panel, y + 40, PW);&#10;    // the player's own settings (P2-P4 of its Scene: no new shader); the middle is as MilkDrop plays it&#10;    [['Sensitivity', 'sensitivity', v =&gt; 'x' + Math.pow(3, (v - 0.5) * 2).toFixed(2)],&#10;     ['Speed', 'speed', v =&gt; 'x' + (v &lt;= 0.5 ? v * 2 : 1 + (v - 0.5) * 6).toFixed(2)],&#10;     ['Brightness', 'brightness', v =&gt; 'x' + (v &lt;= 0.5 ? v * 2 : 1 + (v - 0.5) * 4).toFixed(2)]].forEach(([n, k, fmt]) =&gt; {&#10;        y = slider(panel, 16, y, PW - 32, n, () =&gt; md.set[k], v =&gt; { md.set[k] = v; mdSend({ [k]: v }); }, fmt);&#10;    });&#10;    y += 6;&#10;    if (st) {&#10;        const col = ['#5fe08a', '#f1c75b', '#f1995b', '#ff6b7a'][Math.max(0, Math.min(3, st.level | 0))];&#10;        T(st.label || '', y + 6, 16, col);&#10;        y += 22;&#10;        (st.why || []).slice(0, 4).forEach(w =&gt; {   // each reason, cut into lines that fit the dock&#10;            let line = '- ';&#10;            String(w).split(' ').forEach(word =&gt; {&#10;                if (line.length + word.length &gt; 52 &amp;&amp; line.trim() !== '-') { T(line, y + 6, 14, '#9a94b8'); y += 19; line = '  '; }&#10;                line += word + ' ';&#10;            });&#10;            T(line, y + 6, 14, '#9a94b8'); y += 19;&#10;        });&#10;        if (st.double) {&#10;            y = chips(panel, 16, y + 4, PW - 32, ['Preset 1', 'Preset 2'], md.which, i =&gt; { md.which = i; mdSend({ which: i }); rebuild(); });&#10;        }&#10;        if ((st.level | 0) === 3 &amp;&amp; !st.playing) {&#10;            button(panel, 16, y + 2, 220, 'Play a stand-in anyway', () =&gt; mdSend({ force: true }), false);&#10;            y += 44;&#10;        }&#10;    }&#10;    if (st &amp;&amp; st.missing &amp;&amp; st.missing.length) {   // only when the preset asks for pictures the folder does not have&#10;        T('missing pictures: ' + st.missing.slice(0, 3).join(', ') + (st.missing.length &gt; 3 ? '...' : ''), y + 6, 16, '#aaa4c6');&#10;        y = chips(panel, 16, y + 18, PW - 32, MDSTANDIN, md.standin, i =&gt; { md.standin = i; mdSend({ standin: i }); rebuild(); });&#10;    }&#10;    T(md.tex ? 'textures: ' + md.tex.replace(/[\\/][^\\/]*\.[a-z0-9]+$/i, '').split(/[\\/]/).pop() : 'textures: not chosen (pick any picture in MilkDrop\'s textures folder)', y + 6, 14, '#7f7a99');&#10;    return y + 26;&#10;}&#10;&#10;function divider(panel, y, PW) {   // v7.5: a thin line between the blocks of the panel&#10;    panel.line({ x1: 16, y1: y + 6, x2: PW - 16, y2: y + 6, width: 1, stroke: '#3a3360', interactive: false });&#10;    return y + 18;&#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: 16, fill: '#aaa4c6', 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 = divider(panel, y, PW);&#10;    }&#10;    if (!it) {&#10;        // v8.9: how big the editor is drawn&#10;        panel.text({ x: 16, y: y + 6, text: 'EDITOR SIZE - text, tools and panels', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, UISIZES.map(k =&gt; Math.round(k * 100) + '%'), state.uiSize, i =&gt; setUiSize(i));&#10;        y = divider(panel, y, PW);&#10;        y = scenePanel(panel, y, PW);&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 6, text: 'BACKGROUND', size: 16, fill: '#aaa4c6', 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: 15, baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;        y += 66;&#10;        y = divider(panel, y, PW);&#10;        // the sound player: what the Audio panel follows (with the sound on the plugin's input), and what you hear&#10;        panel.text({ x: 16, y: y + 6, text: 'SOUND - a file to play, for the Audio panel', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y += 18;&#10;        const snd = state.snd;&#10;        button(panel, 16, y, 170, 'Choose sound...', () =&gt; { wantSound = true; out(2); }, false);&#10;        if (snd.file) {&#10;            button(panel, 192, y, 90, snd.playing ? 'Playing' : 'Play', () =&gt; { snd.playing = true; out(4); rebuild(); }, snd.playing);&#10;            button(panel, 288, y, 80, 'Stop', () =&gt; { snd.playing = false; out(5); rebuild(); }, false);&#10;            button(panel, 374, y, 80, 'Loop', () =&gt; { snd.loop = !snd.loop; sendSound(false); rebuild(); }, snd.loop);&#10;        }&#10;        panel.text({ x: 16, y: y + 46, text: snd.file ? snd.file.split(/[\\/]/).pop() : 'none: WAV, MP3, AIFF, FLAC or OGG', size: 15, baseline: 'middle', fill: '#b8b2d0', interactive: false });&#10;        y += 62;&#10;        if (snd.file) {&#10;            y = slider(panel, 16, y, PW - 32, 'Volume', () =&gt; snd.vol, v =&gt; { snd.vol = v; out(7, sndDb(v)); }, v =&gt; sndDb(v) &lt;= -60 ? 'off' : sndDb(v) + ' dB');&#10;            y += 6;&#10;        }&#10;        y += 10;&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 6, text: 'WHILE EDITING - what the picture shows', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['All effects', 'Only the selected one'], state.solo ? 1 : 0, i =&gt; { state.solo = i === 1; sendCode(); rebuild(); });&#10;        panel.text({ x: 16, y: y + 6, text: 'Only the selected one: faster while you edit; Perform always shows all', size: 15, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y += 34;&#10;        y = divider(panel, y, PW);&#10;        // v7.3: the cables and their round jacks, shown or hidden (they keep working)&#10;        panel.text({ x: 16, y: y + 6, text: 'CABLES - the jacks and cables between elements', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['Show', 'Hide'], state.hideLinks ? 1 : 0, i =&gt; { state.hideLinks = i === 1; rebuild(); });&#10;        panel.text({ x: 16, y: y + 6, text: 'Hidden, the cables still work: an element still follows the one it is joined to', size: 15, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;        y += 34;&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 8, text: 'Click a board, a light or an image to set it up.', size: 18, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        panel.text({ x: 16, y: y + 30, text: 'Double-click the picture for a new light.', size: 18, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        return y + 54;&#10;    } else if (it.type === 'board') {&#10;        const choose = fx =&gt; { it.fx = fx; picking = false; if (fx === 1 &amp;&amp; it.tmove === undefined) it.tmove = 0; if (FXK[fx]) { it.rsize = FXK[fx][2]; it.rstr = FXK[fx][3]; } it.style = 0; sendCode(); rebuild(); };&#10;        let cat = CATS.findIndex(c =&gt; c[1].includes(it.fx));&#10;        if (state.fxCatFor === it.id &amp;&amp; state.fxCat !== undefined) cat = state.fxCat;   // a group looked at, not chosen from yet&#10;        panel.text({ x: 16, y: y + 6, text: 'BOARD - group', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, CATS.map(c =&gt; c[0]), cat, i =&gt; { state.fxCat = i; state.fxCatFor = it.id; rebuild(); });&#10;        const list = CATS[cat][1], needsBg = list.some(MOVES) &amp;&amp; !state.bg;&#10;        panel.text({ x: 16, y: y + 6, text: 'effect' + (needsBg ? ' (these need a background picture)' : ''), size: 15, fill: needsBg ? ACC : '#7f7a99', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, list.map(k =&gt; FX[k]), list.indexOf(it.fx), i =&gt; choose(list[i]));&#10;        y = divider(panel, y, PW);&#10;        if (it.fx === 13 || it.fx === 14 || it.fx === 15) {&#10;            panel.text({ x: 16, y: y + 6, text: 'light mode', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, MODES.slice(0, 7), Math.min(it.mode || 0, 6), 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: 16, fill: '#aaa4c6', 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: 16, fill: '#aaa4c6', 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 {&#10;            if (it.fx === 76) {   // where the piece comes from&#10;                button(panel, 16, y + 2, 190, picking ? 'Click the picture...' : 'Pick where from', () =&gt; { picking = !picking; rebuild(); }, picking);&#10;                panel.text({ x: 216, y: y + 17, text: state.bg ? 'the middle of the piece to copy' : 'needs a background',&#10;                             size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;                y += 40;&#10;            }&#10;            if (FXSTYLES[it.fx]) {&#10;                panel.text({ x: 16, y: y + 6, text: 'kind', size: 16, fill: '#aaa4c6', 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;            }&#10;            if (it.fx &gt;= 61 &amp;&amp; it.fx &lt;= 70) {   // music and stage: they listen by themselves&#10;                panel.text({ x: 16, y: y + 6, text: 'Moves with the sound on In A' + ([61, 62, 70].includes(it.fx) ? '' : ' and the DAW\'s beat'), size: 15, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;                y += 24;&#10;            }&#10;            if (it.fx === 59)&#10;                y = mdPanel(panel, y, PW);&#10;            else if (it.fx === 60)&#10;                y = glslPanel(panel, y, PW, it);&#10;            else {&#10;                panel.text({ x: 16, y: y + 6, text: 'picture' + (state.bg ? '' : ' (needs a background)'), size: 16, fill: '#aaa4c6', 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;        }&#10;        if (it.fx === 1) {   // v5.5: your own words, typed in the box at the top&#10;            panel.text({ x: 16, y: y + 6, text: 'text', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;            const tl = textLines(it);&#10;            (tl.length ? tl : ['(empty)']).forEach((l, k) =&gt; panel.text({ x: 16, y: y + 30 + k * 24, text: l, size: 18, fill: '#ffffff', baseline: 'middle', interactive: false }));&#10;            y += 18 + Math.max(1, tl.length) * 24;&#10;            button(panel, 16, y, 170, state.boxOpen === 'text' ? 'Close box' : 'Type text', () =&gt; { state.boxOpen = state.boxOpen === 'text' ? '' : 'text'; glslBox(); rebuild(); }, state.boxOpen === 'text');&#10;            panel.text({ x: 200, y: y + 15, text: 'up to 3 lines', size: 15, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;            y += 40;&#10;            panel.text({ x: 16, y: y + 6, text: 'motion', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;            y = chips(panel, 16, y + 18, PW - 32, ['Still', 'Scroll', 'Switching on'], it.tmove === undefined ? 1 : it.tmove, i =&gt; { it.tmove = i; sendCode(); rebuild(); });&#10;        }&#10;        y = divider(panel, y, PW);&#10;        button(panel, 16, y + 2, 140, 'Full screen', () =&gt; { if (it.locked) return; it.pts = [[0, 0], [1, 0], [1, 1], [0, 1]]; sendP(); rebuild(); });&#10;        panel.text({ x: 172, y: y + 17, text: 'corners', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        button(panel, 250, y + 2, 84, 'Shape', () =&gt; { it.scaleCorners = false; rebuild(); }, !it.scaleCorners);&#10;        button(panel, 340, y + 2, 84, 'Scale', () =&gt; { it.scaleCorners = true; rebuild(); }, !!it.scaleCorners);&#10;        if (it.locked)&#10;            panel.text({ x: 438, y: y + 17, text: 'locked', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y += 40;&#10;        y = divider(panel, y, PW);&#10;        if (!NOCOLOUR(it.fx))   // the moving picture has no colour of its own (some have a tint)&#10;            y = swatches(panel, 16, y + 4, it);&#10;        y = divider(panel, y, PW);&#10;        if (it.fx !== 59)&#10;            y = it.tlFrom ? lockedRow(panel, 16, y, 'Speed', 'in step with ' + itemName(RHY(it))) : 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;        if (it.fx !== 13)&#10;            y = aslider(panel, 16, y, PW - 32, 'Edge fade', it, 'fade', () =&gt; it.fade || 0, v =&gt; it.fade = v, v =&gt; v &lt; 0.005 ? 'none' : Math.round(v * 100) + '%');&#10;        y = transpRow(panel, y, it, PW);&#10;    } else if (it.type === 'mask') {&#10;        panel.text({ x: 16, y: y + 6, text: 'MASK - the effects do not show', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['inside the shape', 'outside the shape'], it.invert ? 1 : 0, i =&gt; { it.invert = i; sendCode(); rebuild(); });&#10;        y = slider(panel, 16, y, PW - 32, 'Soft edge', () =&gt; it.feather === undefined ? 0.2 : it.feather, v =&gt; { it.feather = v; tlDirty = true; }, v =&gt; Math.round(v * 100) + '%');&#10;        y = transpRow(panel, y, it, PW);&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 6, text: 'masks', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['All effects', 'Only the ones I pick'], it.all === false ? 1 : 0, i =&gt; { it.all = i === 0; if (!it.only) it.only = []; sendCode(); rebuild(); });&#10;        if (it.all === false) {&#10;            const fx = state.items.filter(t =&gt; t.type === 'board' || t.type === 'light');&#10;            if (!fx.length)&#10;                panel.text({ x: 16, y: y + 10, text: 'No boards or lights yet.', size: 18, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;            fx.forEach((t, i) =&gt; {&#10;                const on = it.only.includes(t.id);&#10;                button(panel, 16 + (i % 2) * ((PW - 32) / 2 + 4), y + Math.floor(i / 2) * 36, (PW - 32) / 2 - 4, itemName(t).slice(0, 30),&#10;                       () =&gt; { it.only = on ? it.only.filter(k =&gt; k !== t.id) : it.only.concat([t.id]); sendCode(); rebuild(); }, on);&#10;            });&#10;            y += Math.ceil(Math.max(1, fx.length) / 2) * 36 + 6;&#10;        }&#10;        // v6.0: the brush&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 6, text: 'BRUSH - paint the mask on the picture', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['Off', 'Paint', 'Erase'], state.brush, i =&gt; { state.brush = i; rebuild(); });&#10;        y = slider(panel, 16, y, PW - 32, 'Brush size', () =&gt; state.bsize, v =&gt; { state.bsize = v; }, () =&gt; Math.round(brushR() * 1080) + ' px');&#10;        y = slider(panel, 16, y, PW - 32, 'Brush softness', () =&gt; state.bsoft, v =&gt; { state.bsoft = v; }, v =&gt; Math.round(v * 100) + '%');&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 6, text: 'the shape', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['Shape and brush', 'Brush only'], it.bonly ? 1 : 0, i =&gt; { it.bonly = i === 1; sendCode(); rebuild(); });&#10;        const ns = (it.strokes || []).length;&#10;        button(panel, 16, y + 2, 150, 'Undo stroke', () =&gt; { if (ns) { it.strokes.pop(); sendCode(); rebuild(); } }, false);&#10;        button(panel, 172, y + 2, 150, 'Clear brush', () =&gt; { it.strokes = []; sendCode(); rebuild(); }, false);&#10;        panel.text({ x: 334, y: y + 17, text: ns + (ns === 1 ? ' stroke' : ' strokes'), size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;        y += 44;&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 8, text: 'double-click the edge: a point more - right-click a point: take it away', size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;        panel.text({ x: 16, y: y + 26, text: 'Masks work on the effects; images lie over everything.', size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;        return y + 44;&#10;    } else if (it.type === 'image') {&#10;        panel.text({ x: 16, y: y + 6, text: 'IMAGE - ' + fileName(it.src), size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y += 18;&#10;        button(panel, 16, y, 170, 'Other picture...', () =&gt; { wantImage = 'replace'; out(2); }, false);&#10;        y += 44;&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 6, text: 'in its box', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;        y = chips(panel, 16, y + 18, PW - 32, ['Fit (whole picture)', 'Fill (cut to the box)'], it.fit ? 1 : 0, i =&gt; { it.fit = i; rebuild(); });&#10;        y = slider(panel, 16, y, PW - 32, 'Box width', () =&gt; Math.min(1, it.w), v =&gt; { it.w = Math.max(0.005, v); moveHandles(it); }, v =&gt; Math.round(v * 200) + '%');&#10;        y = slider(panel, 16, y, PW - 32, 'Box height', () =&gt; Math.min(1, it.h), v =&gt; { it.h = Math.max(0.005, v); moveHandles(it); }, v =&gt; Math.round(v * 200) + '%');&#10;        y = divider(panel, y, PW);&#10;        y = aslider(panel, 16, y, PW - 32, 'Size', it, 'scale', () =&gt; it.scale, v =&gt; { it.scale = Math.max(0.01, v); moveHandles(it); }, v =&gt; Math.round(v * 200) + '%');&#10;        y = aslider(panel, 16, y, PW - 32, 'Turn', it, 'rot', () =&gt; it.rot, v =&gt; { it.rot = v; moveHandles(it); }, v =&gt; Math.round((v - 0.5) * 360) + ' deg');&#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; moveHandles(it); }, v =&gt; Math.round(v * 100) + '%');&#10;        if (tlOn(it, 'x') || tlOn(it, 'y'))&#10;            y = lockedRow(panel, 16, y, 'Position', 'animated on the timeline');&#10;        y = divider(panel, y, PW);&#10;        panel.text({ x: 16, y: y + 8, text: 'Pictures lie over all the effects.', size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;        panel.text({ x: 16, y: y + 26, text: 'Drag a corner for the box (Ctrl: keep its shape).', size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;        return y + 48;&#10;    } else {&#10;        panel.text({ x: 16, y: y + 6, text: 'LIGHT - mode', size: 16, fill: '#aaa4c6', 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 = divider(panel, y, PW);&#10;        y = swatches(panel, 16, y + 4, it);&#10;        y = divider(panel, y, PW);&#10;        y = aslider(panel, 16, y, PW - 32, 'Size', it, 'size', () =&gt; it.size, v =&gt; { it.size = v; moveHandles(it); });&#10;        y = it.tlFrom ? lockedRow(panel, 16, y, 'Speed', 'in step with ' + itemName(RHY(it))) : 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;    y = divider(panel, y, PW);&#10;    panel.text({ x: 16, y: y + 8, text: 'drag corners (Ctrl: scale) - drag inside - Alt: no snap', size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;    panel.text({ x: 16, y: y + 26, text: 'wheel = scale - Shift+wheel = rotate - right-click = options', size: 15, fill: '#9a94b8', baseline: 'middle', interactive: false });&#10;    return y + 44;&#10;}&#10;&#10;function setEdit(on) {&#10;    state.edit = !!on;&#10;    sendAids(null);&#10;    if (state.solo)&#10;        sendCode();&#10;    rebuild();&#10;}&#10;&#10;// ---------- v6.1: scenes. Each keeps its own background and elements; only the one shown is in the shader ----------&#10;if (!state.scenes) { state.scenes = [{ name: 'Scene 1' }]; state.scene = 0; state.sfade = 1; state.sdur = 1; }&#10;const SDURS = [0.5, 1, 2, 4];   // how long a change takes, all of it (out and in), in seconds&#10;let sureScene = false;   // Delete pressed once&#10;let sfading = null;             // a change on its way: { to, t, phase: 'out' | 'hold' | 'in' }&#10;function sceneStore() { const sc = state.scenes[state.scene]; sc.items = state.items; sc.bg = state.bg; }&#10;function sceneLoad(i) {&#10;    sceneStore();&#10;    state.scene = i;&#10;    const sc = state.scenes[i], bg = sc.bg || '';&#10;    state.items = sc.items || [];&#10;    state.sel = 0; state.brush = 0; menu = null;&#10;    past = []; future = []; now = null;   // Undo is for one scene: it starts again here&#10;    if (bg !== state.bg) { state.bg = bg; out(1, { image1: bg }); }&#10;    sendCode(); sendAids(null); rebuild();&#10;}&#10;function goScene(i) {   // with Cut at once; otherwise out, the new scene in while it is dark, then in&#10;    if (i &lt; 0 || i &gt;= state.scenes.length || (i === state.scene &amp;&amp; !sfading)) return;&#10;    if (!state.sfade) { sceneLoad(i); return; }&#10;    sfading = { to: i, t: sfading &amp;&amp; sfading.phase === 'out' ? sfading.t : 0, phase: 'out' };&#10;}&#10;function sceneTick(dt) {&#10;    if (!sfading) return;&#10;    const half = SDURS[state.sdur] / 2;&#10;    sfading.t += dt;&#10;    if (sfading.phase === 'out') {&#10;        out(1, { p: { P24: Math.min(1, sfading.t / half) } });&#10;        if (sfading.t &gt;= half) { sceneLoad(sfading.to); sfading.phase = 'hold'; sfading.t = 0; }&#10;    } else if (sfading.phase === 'hold') {   // a moment, so the new scene's shader is ready before it shows&#10;        if (sfading.t &gt;= 0.25) { sfading.phase = 'in'; sfading.t = 0; }&#10;    } else {&#10;        const v = Math.max(0, 1 - sfading.t / half);&#10;        out(1, { p: { P24: v } });&#10;        if (v &lt;= 0) sfading = null;&#10;    }&#10;}&#10;function scenePanel(panel, y, PW) {&#10;    panel.text({ x: 16, y: y + 6, text: 'SCENES - click one to go to it', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;    y = chips(panel, 16, y + 18, PW - 32, state.scenes.map(sc =&gt; sc.name), sfading ? sfading.to : state.scene, i =&gt; goScene(i));&#10;    button(panel, 16, y + 2, 110, '+ New', () =&gt; { sceneStore(); state.scenes.push({ name: 'Scene ' + (state.scenes.length + 1), items: [], bg: state.bg }); sceneLoad(state.scenes.length - 1); }, false);&#10;    button(panel, 132, y + 2, 120, 'Duplicate', () =&gt; { sceneStore(); const cur = state.scenes[state.scene];&#10;        const copy = JSON.parse(JSON.stringify({ items: cur.items, bg: cur.bg }));&#10;        const ids = {};&#10;        copy.items.forEach(t =&gt; { ids[t.id] = state.next; t.id = state.next++; });   // new ids: each element is its own&#10;        copy.items.forEach(t =&gt; { if (t.only) t.only = t.only.map(k =&gt; ids[k] || k); ['tlFrom', 'auFrom'].forEach(k =&gt; { if (t[k]) t[k] = ids[t[k]] || t[k]; }); });   // a mask still masks the copies of its effects, a cable joins the copies&#10;        state.scenes.splice(state.scene + 1, 0, { name: cur.name + ' copy', items: copy.items, bg: copy.bg }); sceneLoad(state.scene + 1); }, false);&#10;    button(panel, 258, y + 2, 110, 'Rename', () =&gt; { state.boxOpen = state.boxOpen === 'scene' ? '' : 'scene'; glslBox(); rebuild(); }, state.boxOpen === 'scene');&#10;    button(panel, 374, y + 2, 110, sureScene ? 'Sure?' : 'Delete', () =&gt; {&#10;        if (state.scenes.length &lt; 2) return;&#10;        if (!sureScene) { sureScene = true; rebuild(); return; }&#10;        sureScene = false; const gone = state.scene; past = []; future = []; now = null;&#10;        state.scenes.splice(gone, 1); state.scene = Math.max(0, gone - 1);&#10;        const sc = state.scenes[state.scene]; state.items = sc.items || []; state.sel = 0;&#10;        if ((sc.bg || '') !== state.bg) { state.bg = sc.bg || ''; out(1, { image1: state.bg }); }&#10;        sendCode(); rebuild(); }, sureScene);&#10;    y += 42;&#10;    y = divider(panel, y, PW);&#10;    panel.text({ x: 16, y: y + 6, text: 'change', size: 16, fill: '#aaa4c6', baseline: 'middle', interactive: false });&#10;    y = chips(panel, 16, y + 18, PW - 32, ['Cut', 'Via black', 'Via background'], state.sfade, i =&gt; { state.sfade = i; sendCode(); rebuild(); });&#10;    if (state.sfade)&#10;        y = chips(panel, 16, y, PW - 32, SDURS.map(d =&gt; d + ' s'), state.sdur, i =&gt; { state.sdur = i; rebuild(); });&#10;    panel.text({ x: 16, y: y + 6, text: 'In 7 of the Script: a number (1, 2, ...) goes to that scene, from the patch or MIDI', size: 14, fill: '#7f7a99', baseline: 'middle', interactive: false });&#10;    return y + 28;&#10;}&#10;function setUiSize(i) {   // v8.9: the editor drawn bigger or smaller (the picture stays as it is)&#10;    if (i === state.uiSize) return;&#10;    state.uiSize = i;&#10;    W = 1920 / UISIZES[i]; H = 1080 / UISIZES[i];&#10;    c.size(W, H, 'stretch');&#10;    helpSize();&#10;    state.zoom = 1; state.panX = 0; state.panY = 0; state.dscroll = 0;&#10;    rebuild();&#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 === 7 || n === 8) &amp;&amp; value === undefined) {   // v6.6: an Event from the Left key (In 7) or the Right key (In 8): the scene before or after, round&#10;        const ns = state.scenes.length;&#10;        if (ns &gt; 1) goScene(((sfading ? sfading.to : state.scene) + (n === 8 ? 1 : -1) + ns) % ns);&#10;        return;&#10;    }&#10;    if (n === 7) {   // v6.1: go to a scene by its number, from 1&#10;        const k = Math.round(Number(value)) - 1;&#10;        if (k &gt;= 0) goScene(k);&#10;        return;&#10;    }&#10;    if (n === 6 &amp;&amp; typeof value === 'string' &amp;&amp; state.boxOpen === 'scene') {   // the scene's new name&#10;        const nm = value.split('\n')[0].trim().slice(0, 24);&#10;        if (nm) state.scenes[state.scene].name = nm;&#10;        state.boxOpen = ''; glslBox(); rebuild();&#10;        return;&#10;    }&#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 === 4) {   // the MilkDrop Player: what it made of the preset&#10;        try { state.md.status = typeof value === 'string' ? JSON.parse(value) : value; } catch (e) { state.md.status = null; }&#10;        if (state.md.status &amp;&amp; state.md.file) state.md.levels[state.md.file] = state.md.status.level | 0;   // for the dot in the playlist&#10;        if (state.md.status &amp;&amp; state.md.status.settings) Object.assign(state.md.set, state.md.status.settings);&#10;        rebuild();&#10;        return;&#10;    }&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length &amp;&amp; wantMd === 'glsl') {   // a shader file: the player's Shader Code node reads it&#10;        const it = state.items.find(t =&gt; t.id === wantGlsl);&#10;        if (it) { it.glslFile = value; state.glslFollow = value; }&#10;        mdSend({ read: value });&#10;        wantMd = ''; wantImage = false;&#10;        return;&#10;    }&#10;    if (n === 6 &amp;&amp; typeof value === 'string' &amp;&amp; state.boxOpen === 'text') {   // v5.5: the words for the selected text board&#10;        const it = selected();&#10;        if (it &amp;&amp; it.type === 'board' &amp;&amp; it.fx === 1) {&#10;            it.label = value.split('\n').map(l =&gt; l.trim().slice(0, 40)).filter(l =&gt; l).slice(0, 3).join('\n');&#10;            state.boxOpen = ''; glslBox(); sendCode(); rebuild();&#10;        }&#10;        return;&#10;    }&#10;    if ((n === 5 || n === 6) &amp;&amp; typeof value === 'string' &amp;&amp; (/\bmainImage\b/.test(value) || isISF(value))) {   // v8.8: or ISF   // shader code: from a file (In 5) or the paste box (In 6)&#10;        const targets = n === 5 ? state.items.filter(t =&gt; t.fx === 60 &amp;&amp; (t.id === wantGlsl || (t.glslFile &amp;&amp; t.glslFile === state.glslFollow))) :&#10;                        state.items.filter(t =&gt; t.id === state.sel &amp;&amp; t.type === 'board' &amp;&amp; t.fx === 60);&#10;        targets.forEach(t =&gt; { if (n === 6) delete t.glslFile; const v = glslClean(value); if (isISF(v)) isfUse(t, v); else { t.glsl = v; delete t.isf; delete t.isfSig; } });&#10;        wantGlsl = 0;&#10;        if (n === 6 &amp;&amp; targets.length) { state.boxOpen = ''; glslBox(); }   // used: the box closes&#10;        if (targets.length) { sendCode(); rebuild(); }&#10;        return;&#10;    }&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length &amp;&amp; (wantMd === 'file' || /\.milk2?$/i.test(value))) {   // a MilkDrop preset&#10;        wantMd = ''; wantSound = false; wantImage = false;&#10;        if (value !== state.md.file || !state.md.list.includes(value))   // (the File node sends its last file again when the project opens)&#10;            mdPlay(value);&#10;        return;&#10;    }&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length &amp;&amp; (wantMd === 'tex' || value === state.md.tex)) {   // MilkDrop's pictures&#10;        if (value !== state.md.tex || wantMd === 'tex') { state.md.tex = value; mdSend({ textures: value }); }&#10;        wantMd = ''; wantImage = false;&#10;        rebuild();&#10;        return;&#10;    }&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length &amp;&amp; (wantSound || AUDIOEXT.test(value))) {   // a sound: for the player&#10;        if (value !== state.snd.file) setSound(value);&#10;        wantSound = false; wantImage = false;&#10;        return;&#10;    }&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length) {&#10;        const it = selected();&#10;        if (wantImage === 'replace' &amp;&amp; it &amp;&amp; it.type === 'image') { it.src = value; rebuild(); }&#10;        else if (wantImage) addImage(value);&#10;        else if (!state.items.some(t =&gt; t.type === 'image' &amp;&amp; t.src === value))   // (the File node sends its last file again when the project opens)&#10;            setBackground(value);&#10;        wantImage = false;&#10;    }&#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;    sendSound(true);&#10;    state.snd.playing = false;&#10;    mdSend({ panel: false });   // the player's own panel would lie under this Scene (it keeps its preset and pictures itself)&#10;    rebuild();&#10;}&#10;" inputs="8" outputs="8" live="1" tick="2"/>
        </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>
        <node id="5" type="audio.in" title="Audio In" expanded="0" x="-700.0" y="1150.0" w="220.0" h="120.0">
          <state channels="2"/>
        </node>
        <node id="6" type="audio.out" title="Audio Out" expanded="0" x="-300.0" y="1150.0" w="220.0" h="120.0">
          <state channels="2"/>
        </node>
        <node id="7" type="cv.transport" title="Transport" expanded="0" x="-700.0" y="1400.0" w="260.0" h="300.0">
          <state syncMode="1"/>
        </node>
        <node id="9" type="visual.gpucanvas" title="MilkDrop" expanded="0" x="0.0" y="1300.0" w="1920.0" h="1080.0">
          <state pcount="4" speed="1.0" code="" zones="" zonevalues="" labels="" image1="" image2="" fontFile="" preserveBuffers="0" resolution="1" framerate="1" transparent="0" background="FF000000" keyboard="0" zoneinputs="0" showOrientation="0" showObjectAxes="0" visible="1" ignoreClicks="1" panelX="0.0" panelY="0.0" panelW="1920.0" panelH="1080.0" tooltipStyle="" exposeToDAW="0" panel_visible="1" p1="0.5" p2="0.5" p3="0.5" p4="0.5"/>
        </node>
        <node id="10" type="flow.script" title="MilkDrop Player" expanded="0" x="-1100.0" y="1300.0" w="900.0" h="1000.0">
          <state code="// MilkDrop Player v0.7: plays MilkDrop presets (.milk, also MilkDrop3's double presets .milk2) in the Scene.&#10;// No presets or pictures are built in: load your own. Each preset is checked when it comes in:&#10;//   Supported: plays as in MilkDrop. Plays, adjusted: plays, with what does not work here left out or simplified.&#10;//   Plays only in part: a big part (megabuf memory, a shader) is left out. Works only in MilkDrop3: its shader is closed&#10;//   MilkDrop3 code that is not in the file, so it does not play (Play stand-in plays a simple stand-in anyway).&#10;// What the check cannot see: whether a preset stays black here. Try it.&#10;// Pictures (sampler_MilkDrop3_017 ...): choose any picture in your textures folder once with &quot;Textures folder...&quot;;&#10;// the first picture a preset reads goes into the Scene's Image 1, the second into Image 2, more get a stand-in.&#10;// The panel: double-click the picture to show or hide it.&#10;// In 1: a preset's whole text (the Text node, or another Script). In 2: a picture in your textures folder (File node).&#10;// In 3: a preset's text from the Shader Code node &quot;Preset file&quot;. In 4: a preset file's path: it goes out of Out 3 into&#10;// that Shader Code's File, which reads it and sends the text back on In 3.&#10;// In 5: everything on one cable, as JSON: {&quot;text&quot;: a preset's text, &quot;name&quot;: its name}, {&quot;file&quot;: a preset file's path}, {&quot;textures&quot;: a picture&#10;// or the folder}, {&quot;panel&quot;: false} (hide this panel), {&quot;which&quot;: 0 or 1}, {&quot;standin&quot;: 0..2}, {&quot;force&quot;: true},&#10;// {&quot;sensitivity&quot;: 0..1, &quot;speed&quot;: 0..1, &quot;brightness&quot;: 0..1} (0.5 is as in MilkDrop; they change the picture at once);&#10;// {&quot;read&quot;: a file's path}: the Shader Code reads it for another patch (it gets the text from the Shader Code's Code itself),&#10;// and the text that comes back on In 3 is left alone; {&quot;forward&quot;: any value}: sent on unchanged out of Out 6 (a relay for&#10;// another patch); several at once work too.&#10;// Out 1 -&gt; Scene Objects. Out 2 -&gt; textures File, Open Dialog. Out 3 -&gt; Shader Code File. Out 4: the check as JSON,&#10;// after every load: {name, level, label, why, notes, settings, missing (pictures that get a stand-in),&#10;// guessed (picture files looked for by name only: if your folder does not have them, the Scene shows none), double, which, playing}. Out 5 -&gt; preset File, Open Dialog.&#10;&#10;const W = 1920, H = 1080, ACC = '#ffb347';&#10;const c = canvas(1);&#10;c.size(W, H, 'stretch');&#10;if (state.sens === undefined) { state.sens = 0.5; state.speed = 0.5; state.bright = 0.5; }   // new in v0.5&#10;if (state.v !== 3 &amp;&amp; state.v !== 4 &amp;&amp; state.v !== 5 &amp;&amp; state.v !== 6 &amp;&amp; state.v !== 7) {   // a new start (or a project of an older version)&#10;    state.v = 7; state.which = 0; state.standin = 1; state.info = true; state.panel = true; state.force = false;&#10;    state.text = state.text || ''; state.texdir = state.texdir || ''; state.known = state.known || {}; state.file = '';&#10;}&#10;// the names of the pictures that come with MilkDrop3 (names only: the pictures are in your own textures folder)&#10;const TEXTURES = [&quot;DeepField_Figures_NASAAstronaut_NASA_PUBD.png&quot;, &quot;DeepField_Figures_Nkisi_ArteKongo_CC0.png&quot;, &quot;DeepField_Figures_WatPhoBuddha_NeonAngel_CC0.png&quot;, &quot;DeepField_Figures_WireframeDeer_WALLPAPER_CC0.jpg&quot;, &quot;DeepField_FineArt_Miscellaneous_BlueTemplePanel_NeonAngel_CC0.jpg&quot;, &quot;DeepField_Heads_Brain2_NeonAngel_GordanJohnson_CC0.png&quot;, &quot;DeepField_Heads_HuicholBead12_NovicaCoop_PRODIMG - Copy.png&quot;, &quot;DeepField_Heads_Serpent_ManuelMorneo_PRODIMG.png&quot;, &quot;DeepField_Objects_WinampWoofer_MilkDrop2.png&quot;, &quot;DeepField_Psychedelic_IlluminatiEye_WALLPAPER_CC0.jpg&quot;, &quot;DeepField_Symbols_Checkerboard_GordanJohnson_PIXA_CC0.png&quot;, &quot;DeepField_Symbols_SpiderWebHypnotic_OCA_CC0.png&quot;, &quot;DeepField_Symbols_YinYan_PubDomainPictures_PIXA_CC0.png&quot;, &quot;Image415.jpg&quot;, &quot;MilkDrop3_001.jpg&quot;, &quot;MilkDrop3_002.jpg&quot;, &quot;MilkDrop3_002b.jpg&quot;, &quot;MilkDrop3_003.jpg&quot;, &quot;MilkDrop3_003b.jpg&quot;, &quot;MilkDrop3_004.jpg&quot;, &quot;MilkDrop3_004b.jpg&quot;, &quot;MilkDrop3_005.jpg&quot;, &quot;MilkDrop3_005b.jpg&quot;, &quot;MilkDrop3_006.jpg&quot;, &quot;MilkDrop3_006b.jpg&quot;, &quot;MilkDrop3_007.jpg&quot;, &quot;MilkDrop3_008.jpg&quot;, &quot;MilkDrop3_009.jpg&quot;, &quot;MilkDrop3_009b.jpg&quot;, &quot;MilkDrop3_010.jpg&quot;, &quot;MilkDrop3_011.jpg&quot;, &quot;MilkDrop3_012.jpg&quot;, &quot;MilkDrop3_013.jpg&quot;, &quot;MilkDrop3_014.jpg&quot;, &quot;MilkDrop3_015.jpg&quot;, &quot;MilkDrop3_016.jpg&quot;, &quot;MilkDrop3_017.jpg&quot;, &quot;MilkDrop3_018.jpg&quot;, &quot;MilkDrop3_019.jpg&quot;, &quot;MilkDrop3_020.jpg&quot;, &quot;MilkDrop3_021.jpg&quot;, &quot;MilkDrop3_022.jpg&quot;, &quot;MilkDrop3_023.jpg&quot;, &quot;MilkDrop3_024.jpg&quot;, &quot;MilkDrop3_025.png&quot;, &quot;MilkDrop3_026.jpg&quot;, &quot;MilkDrop3_027.jpg&quot;, &quot;OIcurved3.jpg&quot;, &quot;Pattern_000.jpg&quot;, &quot;Pattern_001.jpg&quot;, &quot;Pattern_002.jpg&quot;, &quot;Pattern_002b.jpg&quot;, &quot;Pattern_003.jpg&quot;, &quot;Pattern_004.jpg&quot;, &quot;Pattern_005.jpg&quot;, &quot;Pattern_006.png&quot;, &quot;Pattern_007.png&quot;, &quot;Pattern_008.jpg&quot;, &quot;Pattern_009.jpg&quot;, &quot;Pattern_010.jpg&quot;, &quot;Pattern_011.jpg&quot;, &quot;Pattern_012.png&quot;, &quot;Pattern_013.png&quot;, &quot;Pattern_014.jpg&quot;, &quot;Pattern_015.png&quot;, &quot;Pattern_016.png&quot;, &quot;Pattern_017.jpg&quot;, &quot;Pattern_018.png&quot;, &quot;Pattern_019.png&quot;, &quot;Pattern_020.png&quot;, &quot;Pattern_021.jpg&quot;, &quot;Pattern_022.jpg&quot;, &quot;Pattern_023.jpg&quot;, &quot;Pattern_024.jpg&quot;, &quot;Pattern_025.png&quot;, &quot;Pattern_026.png&quot;, &quot;Pattern_027.jpg&quot;, &quot;Pattern_028.jpg&quot;, &quot;Pattern_029.jpg&quot;, &quot;Pattern_030.jpg&quot;, &quot;Pattern_031.jpg&quot;, &quot;Pattern_032.jpg&quot;, &quot;Pattern_033.jpg&quot;, &quot;Pattern_034.jpg&quot;, &quot;Pattern_034b.jpg&quot;, &quot;Pattern_035.jpg&quot;, &quot;Pattern_036.jpg&quot;, &quot;Pattern_037.jpg&quot;, &quot;Pattern_038.jpg&quot;, &quot;Pattern_039.jpg&quot;, &quot;Pattern_040.jpg&quot;, &quot;Pattern_041.jpg&quot;, &quot;Pattern_042.jpg&quot;, &quot;Pattern_043.jpg&quot;, &quot;Pattern_044.jpg&quot;, &quot;Pattern_045.jpg&quot;, &quot;Pattern_046.jpg&quot;, &quot;Pattern_047.jfif&quot;, &quot;Pattern_048.jpg&quot;, &quot;cells.jpg&quot;, &quot;clipboard03.jpg&quot;, &quot;clouds.jpg&quot;, &quot;clouds2.jpg&quot;, &quot;facade01.jpg&quot;, &quot;hack355.jpg&quot;, &quot;heart.jpg&quot;, &quot;janetmandala.jpg&quot;, &quot;kaite.jpg&quot;, &quot;lichen.jpg&quot;, &quot;manyfish.jpg&quot;, &quot;moss1.jpg&quot;, &quot;pano_earth.jpg&quot;, &quot;pano_earth_clouds.jpg&quot;, &quot;pano_earth_night.jpg&quot;, &quot;pano_earth_spec.jpg&quot;, &quot;pano_mars.jpg&quot;, &quot;pano_starsmap.jpg&quot;, &quot;paper.jpg&quot;, &quot;prayerwheel.jpg&quot;, &quot;ruin.jpg&quot;, &quot;seaweed.jpg&quot;, &quot;sky.jpg&quot;, &quot;smalltiled_colors3.jpg&quot;, &quot;smalltiled_electric_nebula.jpg&quot;, &quot;smalltiled_ensign_meat.jpg&quot;, &quot;smalltiled_lizard_scales.jpg&quot;, &quot;stoy_london.jpg&quot;, &quot;sunrise.jpg&quot;, &quot;wrenches.jpg&quot;];&#10;&#10;const STANDINS = ['Picture', 'Pattern', 'Grey'];   // 0 the picture itself, 1 a pattern, 2 grey&#10;const LEVELS = ['#9fd88a', '#e8c36a', '#e88a6a', '#e86a6a'];&#10;function filemap() {   // picture name -&gt; file in your textures folder; one this list does not know is looked for as &lt;name&gt;.jpg&#10;    const m = { __guess: true };&#10;    TEXTURES.forEach(f =&gt; { m[f.replace(/\.[^.]*$/, '').toLowerCase()] = f; });&#10;    return Object.assign(m, state.known);&#10;}&#10;&#10;let last = null, waiting = 0, reading = 0;   // reading: a file read for another patch, its text not ours&#10;function play() {&#10;    if (!state.text) { last = null; status(); draw(); return; }&#10;    try {&#10;        last = mdConvert(state.text, state.which, state.standin, state.texdir ? filemap() : {});&#10;    } catch (err) {&#10;        last = { name: 'This preset could not be read', notes: [String(err &amp;&amp; err.message || err)], double: false, glsl: null, pictures: [],&#10;                 check: { level: 2, label: 'Could not be read', why: ['the converter stopped on it'] } };&#10;    }&#10;    last.playing = !!last.glsl &amp;&amp; (last.check.level &lt; 3 || state.force);&#10;    if (last.playing) {&#10;        const o = Object.assign({ code: last.glsl, reset: true }, settings());&#10;        o.p.P1 = Math.round(Math.random() * 100000) / 100000 + 0.00001;&#10;        const sep = state.texdir.indexOf('\\') &gt;= 0 ? '\\' : '/';&#10;        for (const pic of last.pictures || [])&#10;            if (pic.slot &gt;= 0 &amp;&amp; state.texdir) o['image' + (pic.slot + 1)] = state.texdir + sep + pic.file;&#10;        out(1, o);&#10;    }&#10;    status();&#10;    draw();&#10;}&#10;// the pictures of this preset that get a stand-in (none: the stand-in choice does not matter)&#10;const missing = () =&gt; (last &amp;&amp; last.pictures || []).filter(p =&gt; p.slot &lt; 0).map(p =&gt; p.name);&#10;const shown = () =&gt; state.name || (last &amp;&amp; last.name) || '';   // a .milk names itself rarely: the file's name&#10;// the settings: P2 Sensitivity, P3 Speed, P4 Brightness (the Scene's code reads them), and the Scene's own Speed for its clock&#10;const SETTINGS = [['sens', 'Sensitivity', 'How strongly the bass, mids and highs move the preset'], ['speed', 'Speed', 'How fast the preset runs'],&#10;                  ['bright', 'Brightness', 'How bright the picture is']];&#10;function settings() {&#10;    const s = state.speed;&#10;    return { p: { P2: state.sens, P3: state.speed, P4: state.bright }, speed: s &lt; 0.5 ? s * 2 : 1 + (s - 0.5) * 6 };&#10;}&#10;function setting(k, v) {&#10;    state[k] = Math.round(Math.max(0, Math.min(1, +v || 0)) * 100) / 100;&#10;}&#10;function status() {&#10;    if (!last) return;&#10;    out(4, { name: shown(), level: last.check.level, label: last.check.label, why: last.check.why,&#10;             notes: (last.notes || []).filter(n =&gt; !/^Shape \d|bracket too many|Skipped a character/.test(n)),&#10;             settings: { sensitivity: state.sens, speed: state.speed, brightness: state.bright }, missing: missing(), guessed: (last.pictures || []).filter(p =&gt; p.guessed).map(p =&gt; p.file), double: !!last.double, which: state.which, playing: last.playing });&#10;}&#10;function take(text, later, name) {   // a preset's text came in; later: play() comes after&#10;    const from = waiting ? state.file.replace(/^.*[\\/]/, '').replace(/\.milk2?$/i, '') : '';&#10;    waiting = 0;&#10;    if (text === state.text) return false;   // the same again (the Text node sends its text again on load)&#10;    state.text = text; state.which = 0; state.force = false; state.name = name || from;&#10;    if (!later) play();&#10;    return true;&#10;}&#10;const isPreset = v =&gt; typeof v === 'string' &amp;&amp; /\[preset\d\d\]|^\s*(zoom|fdecay|per_frame_1|warp_1)\s*=/im.test(v);&#10;&#10;let layer = null;&#10;function button(g, x, y, w, label, fn, on, tip) {&#10;    const b = g.group({ x: x, y: y, cursor: 'pointer' });&#10;    b.rect({ w: w, h: 34, radius: 7, fill: on ? ACC : '#22252c', stroke: on ? ACC : '#3a3e48', strokeWidth: 1, tooltip: tip });&#10;    b.text({ x: w / 2, y: 17, text: label, size: 16, align: 'center', baseline: 'middle', fill: on ? '#111111' : '#e8e4dc', interactive: false });&#10;    b.on('click', e =&gt; { e.stop(); fn(); });&#10;    return x + w + 8;&#10;}&#10;function label(g, x, y, text) {&#10;    g.text({ x: x, y: y + 17, text: text, size: 14, baseline: 'middle', fill: '#7d786f', interactive: false });&#10;    return x + text.length * 7.4 + 12;&#10;}&#10;function line(g, y, text, fill, size) {&#10;    g.text({ x: 20, y: y, text: text.slice(0, 130), size: size || 14, baseline: 'middle', fill: fill || '#b9b4aa', interactive: false });&#10;    return y + (size ? size + 8 : 22);&#10;}&#10;function draw() {&#10;    if (layer) layer.remove();&#10;    layer = c.group({});&#10;    if (!state.panel) return;   // another patch shows the panel (Cinemnode)&#10;    const sheet = layer.rect({ x: 0, y: 0, w: W, h: H, fill: '#00000000', interactive: true });&#10;    sheet.on('doubleclick', () =&gt; { state.info = !state.info; draw(); });&#10;    if (!state.info) return;&#10;    const g = layer.group({ x: 40, y: H - 300 });&#10;    const bg = g.rect({ w: 1060, h: 10, radius: 12, fill: '#0f1013e8', stroke: '#3a3e48', strokeWidth: 1, interactive: true });&#10;    g.text({ x: 20, y: 30, text: 'MILKDROP PLAYER', size: 15, baseline: 'middle', fill: ACC, interactive: false });&#10;    g.text({ x: 190, y: 30, text: 'v0.7 · double-click the picture to hide this', size: 13, baseline: 'middle', fill: '#7d786f', interactive: false });&#10;    let y = 62, x = 20;&#10;    x = button(g, x, y, 160, 'Load preset...', () =&gt; out(5), false, 'Choose a .milk or .milk2 file');&#10;    label(g, x + 4, y, waiting ? 'reading ' + state.file.slice(-70) + ' ...' : 'or paste one into the Text node');&#10;    y += 48;&#10;    if (!last) {&#10;        y = line(g, y, 'No preset yet.', '#e8e4dc', 18);&#10;    } else {&#10;        y = line(g, y, shown().slice(0, 90), '#e8e4dc', 20);&#10;        const k = last.check;&#10;        y = line(g, y, k.label + (k.why.length ? ': ' + k.why.join(', ') : ''), LEVELS[k.level]);&#10;        if (k.level === 3 &amp;&amp; !state.force) y = line(g, y, 'Not played. &quot;Play stand-in&quot; plays the simple stand-in that is in the file.');&#10;        (last.notes || []).filter(n =&gt; !/^Shape \d|bracket too many|Skipped a character|^Closed MilkDrop3|^Picture &quot;/.test(n)).slice(0, 3)&#10;            .forEach(n =&gt; { y = line(g, y, '· ' + n); });&#10;        y += 8;&#10;        x = 20;&#10;        if (k.level === 3) x = button(g, x, y, 150, 'Play stand-in', () =&gt; { state.force = !state.force; play(); }, state.force, 'Play the simple stand-in shader that is in the file');&#10;        if (last.double) {&#10;            x = label(g, x, y, 'double preset:');&#10;            for (let j = 0; j &lt; 2; j++) x = button(g, x, y, 110, 'Preset ' + (j + 1), () =&gt; { state.which = j; play(); }, state.which === j);&#10;            x += 12;&#10;        }&#10;        if (missing().length) {&#10;            x = label(g, x, y, 'stand-in for ' + missing().slice(0, 2).join(', ') + ':');&#10;            [1, 0, 2].forEach(j =&gt; { x = button(g, x, y, 92, STANDINS[j], () =&gt; { state.standin = j; play(); }, state.standin === j); });&#10;        }&#10;        if (x &gt; 20) y += 44;&#10;    }&#10;    x = 20;&#10;    SETTINGS.forEach(([k, name, tip]) =&gt; {&#10;        x = label(g, x, y, name);&#10;        x = button(g, x - 6, y, 34, '−', () =&gt; { setting(k, state[k] - 0.05); out(1, settings()); draw(); }, false, tip);&#10;        g.text({ x: x + 22, y: y + 17, text: String(Math.round(state[k] * 100)), size: 15, align: 'center', baseline: 'middle', fill: state[k] === 0.5 ? '#b9b4aa' : ACC, interactive: false });&#10;        x = button(g, x + 44, y, 34, '+', () =&gt; { setting(k, state[k] + 0.05); out(1, settings()); draw(); }, false, tip) + 14;&#10;    });&#10;    button(g, x, y, 80, 'Reset', () =&gt; { state.sens = state.speed = state.bright = 0.5; out(1, settings()); draw(); }, false, '50 each: as in MilkDrop');&#10;    y += 44;&#10;    x = 20;&#10;    x = button(g, x, y, 190, 'Textures folder...', () =&gt; out(2), !!state.texdir, 'Choose any picture in your MilkDrop textures folder: the presets take their pictures from there');&#10;    label(g, x, y, state.texdir ? state.texdir.slice(-80) : 'not chosen yet: pictures get a stand-in');&#10;    y += 44;&#10;    bg.set({ h: y + 6 });&#10;    g.set({ y: H - 40 - (y + 6) });&#10;}&#10;&#10;function onTick() {&#10;    if (reading &amp;&amp; time() - reading &gt; 3) reading = 0;   // nothing came back&#10;    if (waiting &amp;&amp; time() - waiting &gt; 3) {   // the Shader Code did not send the file on&#10;        waiting = 0;&#10;        last = { name: state.file.replace(/^.*[\\/]/, ''), notes: [], double: false, pictures: [], playing: false,&#10;                 check: { level: 2, label: 'Could not read the file', why: ['the Shader Code node did not pass it on: open the file in a text editor and paste it into the Text node'] } };&#10;        status(); draw();&#10;    }&#10;}&#10;&#10;function textures(value) {   // a picture in your textures folder, or the folder&#10;    const k = Math.max(value.lastIndexOf('\\'), value.lastIndexOf('/'));&#10;    const isFile = /\.[a-z0-9]{2,4}$/i.test(value);&#10;    if (isFile) { const f = value.slice(k + 1); state.known[f.replace(/\.[^.]*$/, '').toLowerCase()] = f; }   // a picture you chose is known by its own name&#10;    state.texdir = isFile &amp;&amp; k &gt; 0 ? value.slice(0, k) : value.replace(/[\\/]+$/, '');&#10;}&#10;function file(value) {   // a preset file: the Shader Code reads it&#10;    state.file = value; waiting = time() || 0.001;&#10;    out(3, value);&#10;}&#10;&#10;function onInput(n, value) {&#10;    if (n === 3 &amp;&amp; reading) { reading = 0; return; }   // the text of a file read for another patch&#10;    if ((n === 1 || n === 3) &amp;&amp; isPreset(value)) take(value);&#10;    if (n === 2 &amp;&amp; typeof value === 'string' &amp;&amp; value.length) { textures(value); play(); }&#10;    if (n === 4 &amp;&amp; typeof value === 'string' &amp;&amp; value.length) { file(value); draw(); }&#10;    if (n === 5) {   // everything on one cable, for another patch (Cinemnode)&#10;        let cmd = value;&#10;        if (typeof cmd === 'string') { try { cmd = JSON.parse(cmd); } catch (e) { if (isPreset(value)) take(value); return; } }&#10;        if (!cmd || typeof cmd !== 'object') return;&#10;        let again = isPreset(cmd.text) &amp;&amp; take(cmd.text, true, typeof cmd.name === 'string' ? cmd.name : '');&#10;        if ('panel' in cmd) state.panel = !!cmd.panel;&#10;        if ('which' in cmd) { state.which = cmd.which ? 1 : 0; again = true; }&#10;        if ('standin' in cmd) { state.standin = Math.max(0, Math.min(2, cmd.standin | 0)); again = true; }&#10;        if ('force' in cmd) { state.force = !!cmd.force; again = true; }&#10;        if (typeof cmd.textures === 'string' &amp;&amp; cmd.textures) { textures(cmd.textures); again = true; }&#10;        if ('forward' in cmd) out(6, cmd.forward);&#10;        if (typeof cmd.file === 'string' &amp;&amp; cmd.file) file(cmd.file);&#10;        else if (typeof cmd.read === 'string' &amp;&amp; cmd.read) { reading = time() || 0.001; waiting = 0; out(3, cmd.read); }&#10;        let set = false;&#10;        [['sensitivity', 'sens'], ['speed', 'speed'], ['brightness', 'bright']].forEach(([a, k]) =&gt; { if (a in cmd) { setting(k, cmd[a]); set = true; } });&#10;        if (set &amp;&amp; !again) out(1, settings());   // at once, with no new code&#10;        if (again) play(); else draw();&#10;    }&#10;}&#10;&#10;function onStart() {&#10;    play();&#10;}&#10;&#10;&#10;// ---------------- the converter ----------------&#10;// MilkDrop's warp and comp shaders (HLSL, shader model 2/3) -&gt; GLSL ES 3 for the MNodes Scene.&#10;// Not a text swap: the code is read into a tree and every expression gets its type, so the conversions HLSL makes&#10;// by itself (float3 -&gt; float2, a number -&gt; a vector, bool -&gt; float, int / int) are written out where GLSL wants them.&#10;// mdHlsl(src, kind, env) -&gt; GLSL text with the function md_warpShader / md_compShader, or null.&#10;// env: { note(text), sampler(name) -&gt; GLSL code of its number or null, texsize(name) -&gt; vec4 code }&#10;&#10;function mdHlsl(src, kind, env) {&#10;    const note = env.note;&#10;&#10;    // ---------- the preprocessor: comments, #define (also with arguments), #if/#ifdef ----------&#10;    src = String(src).replace(/\r/g, '');&#10;    src = src.replace(/\/\*[\s\S]*?\*\//g, m =&gt; m.replace(/[^\n]/g, ' ')).replace(/\/\/[^\n]*/g, '');&#10;    src = src.replace(/\\\n/g, ' ');&#10;    const macros = {};&#10;    const lines = src.split('\n'), kept = [], cond = [];&#10;    const active = () =&gt; cond.every(c =&gt; c.on);&#10;    for (const line of lines) {&#10;        const d = line.match(/^\s*#\s*(\w+)\s*(.*)$/);&#10;        if (!d) { kept.push(active() ? line : ''); continue; }&#10;        const [, dir, rest] = d;&#10;        if (dir === 'ifdef' || dir === 'ifndef') { const has = macros[rest.trim()] !== undefined; cond.push({ on: dir === 'ifdef' ? has : !has, done: false }); cond[cond.length - 1].done = cond[cond.length - 1].on; }&#10;        else if (dir === 'if') { const v = ppEval(rest); cond.push({ on: v, done: v }); }&#10;        else if (dir === 'elif') { const c = cond[cond.length - 1]; if (c) { const v = !c.done &amp;&amp; ppEval(rest); c.on = v; c.done = c.done || v; } }&#10;        else if (dir === 'else') { const c = cond[cond.length - 1]; if (c) { c.on = !c.done; c.done = true; } }&#10;        else if (dir === 'endif') cond.pop();&#10;        else if (dir === 'define' &amp;&amp; active()) {&#10;            const m = rest.match(/^(\w+)(\(([^)]*)\))?\s*(.*)$/);&#10;            if (m) macros[m[1]] = { args: m[2] ? m[3].split(',').map(s =&gt; s.trim()).filter(Boolean) : null, body: m[4] };&#10;        }&#10;        else if (dir === 'undef' &amp;&amp; active()) delete macros[rest.trim()];&#10;        kept.push('');&#10;    }&#10;    function ppEval(e) {&#10;        e = e.replace(/defined\s*\(?\s*(\w+)\s*\)?/g, (_, n) =&gt; macros[n] !== undefined ? '1' : '0');&#10;        e = e.replace(/\b[A-Za-z_]\w*\b/g, n =&gt; macros[n] &amp;&amp; !macros[n].args ? '(' + (macros[n].body || '0') + ')' : '0');&#10;        if (!/^[\d\s.+\-*/%()&lt;&gt;=!&amp;|?:]*$/.test(e)) return false;&#10;        try { return !!Function('return (' + e + ');')(); } catch (err) { return false; }&#10;    }&#10;    src = kept.join('\n');&#10;&#10;    // ---------- tokens ----------&#10;    function lex(s) {&#10;        const out = [];&#10;        const re = /\s*(?:(0[xX][0-9a-fA-F]+[uUlL]?|(?:\d+\.\d*|\.\d+|\d+)(?:[eE][+-]?\d+)?[fFhHlLuU]?)|([A-Za-z_]\w*)|(&lt;&lt;=|&gt;&gt;=|\+\+|--|\+=|-=|\*=|\/=|%=|&amp;=|\|=|\^=|==|!=|&lt;=|&gt;=|&amp;&amp;|\|\||&lt;&lt;|&gt;&gt;|::|[-+*\/%=&lt;&gt;!~&amp;|^?:;,.(){}\[\]#@$\\'&quot;`]))/y;&#10;        let p = 0;&#10;        while (p &lt; s.length) {&#10;            re.lastIndex = p;&#10;            const m = re.exec(s);&#10;            if (!m || m[0].length === 0) { if (/\s/.test(s[p])) { p++; continue; } p++; continue; }&#10;            p = re.lastIndex;&#10;            if (m[1] !== undefined) out.push({ k: 'n', v: m[1] });&#10;            else if (m[2] !== undefined) out.push({ k: 'id', v: m[2] });&#10;            else if (m[3] !== undefined) out.push({ k: 'op', v: m[3] });&#10;        }&#10;        return out;&#10;    }&#10;    // macro expansion on the tokens (a macro is not expanded again inside itself)&#10;    function expand(toks, hide) {&#10;        const out = [];&#10;        for (let i = 0; i &lt; toks.length; i++) {&#10;            const t = toks[i];&#10;            const m = t.k === 'id' &amp;&amp; !hide.has(t.v) ? macros[t.v] : undefined;&#10;            if (!m) { out.push(t); continue; }&#10;            if (!m.args) { const h = new Set(hide); h.add(t.v); out.push(...expand(lex(m.body), h)); continue; }&#10;            if (!(toks[i + 1] &amp;&amp; toks[i + 1].v === '(')) { out.push(t); continue; }&#10;            const args = [[]]; let d = 0, j = i + 2;&#10;            for (; j &lt; toks.length; j++) {&#10;                const x = toks[j];&#10;                if (x.v === '(' || x.v === '[') d++;&#10;                else if (x.v === ')' || x.v === ']') { if (d === 0) break; d--; }&#10;                else if (x.v === ',' &amp;&amp; d === 0) { args.push([]); continue; }&#10;                args[args.length - 1].push(x);&#10;            }&#10;            const body = lex(m.body), sub = [];&#10;            for (const b of body) {&#10;                const ai = b.k === 'id' ? m.args.indexOf(b.v) : -1;&#10;                if (ai &gt;= 0) sub.push(...expand(args[ai] || [], hide)); else sub.push(b);&#10;            }&#10;            const h = new Set(hide); h.add(t.v);&#10;            out.push(...expand(sub, h));&#10;            i = j;&#10;        }&#10;        return out;&#10;    }&#10;    const T = expand(lex(src), new Set());&#10;&#10;    // ---------- types ----------&#10;    // { b: 'f' | 'i' | 'b', n: 1..4 } a number or vector; { m: true, r, c } a matrix (HLSL rows x columns); { s: 'sampler' };&#10;    // { st: name } a struct; { v: true } nothing; arrays add len.&#10;    const F = n =&gt; ({ b: 'f', n }), I = n =&gt; ({ b: 'i', n }), B = n =&gt; ({ b: 'b', n });&#10;    const VOID = { v: true }, SAMPLER = { s: 'sampler' };&#10;    const M = (r, c) =&gt; ({ m: true, r, c });&#10;    function typeFromName(nm) {&#10;        let m;&#10;        if ((m = nm.match(/^(?:float|half|double|min16float|min10float)([1-4])x([1-4])$/))) return M(+m[1], +m[2]);&#10;        if ((m = nm.match(/^(?:float|half|double|min16float|min10float)([1-4])?$/))) return F(+(m[1] || 1));&#10;        if ((m = nm.match(/^(?:int|uint|dword|min16int|min16uint)([1-4])?$/))) return I(+(m[1] || 1));&#10;        if ((m = nm.match(/^bool([1-4])?$/))) return B(+(m[1] || 1));&#10;        if ((m = nm.match(/^vec([234])$/))) return F(+m[1]);&#10;        if (nm === 'void') return VOID;&#10;        if (/^(sampler|sampler1D|sampler2D|sampler3D|samplerCUBE|texture|Texture2D|texture2D|texture3D)$/.test(nm)) return SAMPLER;&#10;        if (structs[nm]) return { st: nm };&#10;        return null;&#10;    }&#10;    const isNum = t =&gt; t &amp;&amp; t.b !== undefined;&#10;    function glType(t) {&#10;        if (t.v) return 'void';&#10;        if (t.s) return 'int';&#10;        if (t.m) return t.r === t.c ? 'mat' + t.r : 'mat' + t.r + 'x' + t.c;&#10;        if (t.st) return t.st;&#10;        if (t.n === 1) return t.b === 'f' ? 'float' : t.b === 'i' ? 'int' : 'bool';&#10;        return (t.b === 'f' ? 'vec' : t.b === 'i' ? 'ivec' : 'bvec') + t.n;&#10;    }&#10;    const same = (a, b) =&gt; a &amp;&amp; b &amp;&amp; glType(a) === glType(b) &amp;&amp; (a.len || 0) === (b.len || 0);&#10;    const SW = 'xyzw';&#10;    // turn code of type `from` into type `to`, the way HLSL would by itself (or with a cast)&#10;    function conv(code, from, to) {&#10;        if (!from || !to || same(from, to) || to.v) return code;&#10;        if (to.s || from.s) return code;&#10;        if (to.m || from.m) {&#10;            if (to.m &amp;&amp; from.m) return glType(to) + '(' + code + ')';&#10;            if (to.m &amp;&amp; isNum(from) &amp;&amp; from.n === 1) return glType(to) + '(' + conv(code, from, F(1)) + ')';&#10;            return code;&#10;        }&#10;        if (!isNum(from) || !isNum(to)) return code;&#10;        if (from.b === 'i' &amp;&amp; to.b === 'f' &amp;&amp; /^-?\d+$/.test(code)) { code = code + '.0'; from = F(from.n); if (to.n === 1) return code; }&#10;        if (to.n === 1) {&#10;            const c = from.n &gt; 1 ? (/^[\w.\[\]]+$/.test(code) ? code : '(' + code + ')') + '.x' : code;&#10;            return from.b === to.b ? c : glType(to) + '(' + c + ')';&#10;        }&#10;        if (from.n === 1) return glType(to) + '(' + code + ')';&#10;        if (from.n &gt; to.n) { const c = (/^[\w.\[\]]+$/.test(code) ? code : '(' + code + ')') + '.' + SW.slice(0, to.n); return from.b === to.b ? c : glType(to) + '(' + c + ')'; }&#10;        if (from.n &lt; to.n) {&#10;            const pad = to.b === 'b' ? 'false' : to.b === 'i' ? '0' : '0.0';&#10;            return glType(to) + '(' + (from.b === to.b ? code : glType({ b: to.b, n: from.n }) + '(' + code + ')') + new Array(to.n - from.n + 1).join(', ' + pad) + ')';&#10;        }&#10;        return glType(to) + '(' + code + ')';&#10;    }&#10;    const rank = b =&gt; b === 'f' ? 2 : b === 'i' ? 1 : 0;&#10;    const maxB = (a, b) =&gt; rank(a) &gt;= rank(b) ? a : b;&#10;    const toBool = e =&gt; isNum(e.t) ? conv(e.c, e.t, B(1)) : e.c;&#10;&#10;    // ---------- reading the code into a tree ----------&#10;    let p = 0;&#10;    const peek = (o = 0) =&gt; T[p + o];&#10;    const isOp = (v, o = 0) =&gt; T[p + o] &amp;&amp; T[p + o].k === 'op' &amp;&amp; T[p + o].v === v;&#10;    const isId = (v, o = 0) =&gt; T[p + o] &amp;&amp; T[p + o].k === 'id' &amp;&amp; T[p + o].v === v;&#10;    const eat = v =&gt; { if (isOp(v)) { p++; return true; } return false; };&#10;    function expect(v) { if (!eat(v)) throw new Error('expected ' + v + ' near ' + around()); }&#10;    function around() { return T.slice(Math.max(0, p - 4), p + 4).map(t =&gt; t.v).join(' '); }&#10;    const structs = {};&#10;    const QUAL = new Set(['static', 'const', 'uniform', 'extern', 'shared', 'volatile', 'row_major', 'column_major', 'precise',&#10;                          'inline', 'nointerpolation', 'linear', 'centroid', 'noperspective', 'sample', 'groupshared', 'register']);&#10;    function skipAttr() { while (isOp('[') &amp;&amp; peek(1) &amp;&amp; peek(1).k === 'id' &amp;&amp; /^(unroll|loop|branch|flatten|fastopt|allow_uav_condition|call|forcecase)$/i.test(peek(1).v)) { let d = 0; do { if (isOp('[')) d++; if (isOp(']')) d--; p++; } while (p &lt; T.length &amp;&amp; d &gt; 0); } }&#10;    function typeAt(o) { const t = peek(o); return t &amp;&amp; t.k === 'id' ? typeFromName(t.v) : null; }&#10;    function readType() {&#10;        const quals = [];&#10;        while (peek() &amp;&amp; peek().k === 'id' &amp;&amp; (QUAL.has(peek().v) || peek().v === 'in' || peek().v === 'out' || peek().v === 'inout')) quals.push(T[p++].v);&#10;        // vector&lt;float, 3&gt; / matrix&lt;float, 3, 3&gt;&#10;        if (isId('vector') &amp;&amp; isOp('&lt;', 1)) { p += 2; const b = T[p++].v; eat(','); const n = +T[p++].v; expect('&gt;'); return { t: Object.assign(typeFromName(b), { n }), quals }; }&#10;        if (isId('matrix') &amp;&amp; isOp('&lt;', 1)) { p += 2; T[p++]; eat(','); const r = +T[p++].v; eat(','); const c = +T[p++].v; expect('&gt;'); return { t: M(r, c), quals }; }&#10;        const t = typeAt(0);&#10;        if (!t) return null;&#10;        p++;&#10;        return { t, quals };&#10;    }&#10;    function skipSemantic() { if (isOp(':') &amp;&amp; peek(1) &amp;&amp; peek(1).k === 'id') { p += 2; if (isOp('(')) { let d = 0; do { if (isOp('(')) d++; if (isOp(')')) d--; p++; } while (p &lt; T.length &amp;&amp; d &gt; 0); } } }&#10;    function skipBraces() { let d = 0; do { if (isOp('{')) d++; if (isOp('}')) d--; p++; } while (p &lt; T.length &amp;&amp; d &gt; 0); }&#10;&#10;    // expressions: plain objects, typed later&#10;    function expr() { const a = assignE(); if (isOp(',')) { const list = [a]; while (eat(',')) list.push(assignE()); return { k: 'comma', list }; } return a; }&#10;    const ASSIGN = new Set(['=', '+=', '-=', '*=', '/=', '%=', '&amp;=', '|=', '^=', '&lt;&lt;=', '&gt;&gt;=']);&#10;    function assignE() {&#10;        const a = ternE();&#10;        if (peek() &amp;&amp; peek().k === 'op' &amp;&amp; ASSIGN.has(peek().v)) { const op = T[p++].v; return { k: 'assign', op, a, b: assignE() }; }&#10;        return a;&#10;    }&#10;    function ternE() {&#10;        const c = binE(0);&#10;        if (eat('?')) { const a = assignE(); expect(':'); const b = assignE(); return { k: 'tern', c, a, b }; }&#10;        return c;&#10;    }&#10;    const LEVELS = [['||'], ['&amp;&amp;'], ['|'], ['^'], ['&amp;'], ['==', '!='], ['&lt;', '&gt;', '&lt;=', '&gt;='], ['&lt;&lt;', '&gt;&gt;'], ['+', '-'], ['*', '/', '%']];&#10;    function binE(l) {&#10;        if (l &gt;= LEVELS.length) return unE();&#10;        let a = binE(l + 1);&#10;        while (peek() &amp;&amp; peek().k === 'op' &amp;&amp; LEVELS[l].includes(peek().v)) { const op = T[p++].v; a = { k: 'bin', op, a, b: binE(l + 1) }; }&#10;        return a;&#10;    }&#10;    function unE() {&#10;        const t = peek();&#10;        if (!t) throw new Error('code ends too early');&#10;        if (t.k === 'op' &amp;&amp; ['-', '+', '!', '~', '++', '--'].includes(t.v)) { p++; return { k: 'un', op: t.v, a: unE() }; }&#10;        // a cast: (float3)x&#10;        if (isOp('(') &amp;&amp; typeAt(1) &amp;&amp; isOp(')', 2)) { p++; const tt = typeFromName(T[p++].v); p++; return { k: 'cast', t: tt, a: unE() }; }&#10;        if (isOp('(') &amp;&amp; isId('vector', 1)) { /* rare */ }&#10;        return postE(primE());&#10;    }&#10;    function primE() {&#10;        const t = T[p];&#10;        if (t.k === 'n') { p++; return { k: 'num', v: t.v }; }&#10;        if (t.k === 'id') {&#10;            p++;&#10;            if (t.v === 'true' || t.v === 'false') return { k: 'bool', v: t.v };&#10;            if (isOp('(')) {&#10;                p++;&#10;                const args = [];&#10;                if (!isOp(')')) { do args.push(assignE()); while (eat(',')); }&#10;                expect(')');&#10;                return { k: 'call', f: t.v, args };&#10;            }&#10;            return { k: 'id', v: t.v };&#10;        }&#10;        if (eat('(')) { const e = expr(); expect(')'); return { k: 'paren', a: e }; }&#10;        if (isOp('{')) { p++; const list = []; if (!isOp('}')) { do { if (isOp('}')) break; list.push(isOp('{') ? primE() : assignE()); } while (eat(',')); } expect('}'); return { k: 'init', list }; }&#10;        throw new Error('did not expect &quot;' + t.v + '&quot; near ' + around());&#10;    }&#10;    function postE(a) {&#10;        for (;;) {&#10;            if (eat('.')) { const f = T[p++]; if (isOp('(')) { p++; const args = []; if (!isOp(')')) { do args.push(assignE()); while (eat(',')); } expect(')'); a = { k: 'method', a, f: f.v, args }; } else a = { k: 'dot', a, f: f.v }; }&#10;            else if (eat('[')) { const i = expr(); expect(']'); a = { k: 'index', a, i }; }&#10;            else if (isOp('++') || isOp('--')) { a = { k: 'post', op: T[p++].v, a }; }&#10;            else return a;&#10;        }&#10;    }&#10;&#10;    // statements&#10;    function stmt() {&#10;        skipAttr();&#10;        if (isOp('{')) { p++; const list = []; while (!isOp('}')) { if (p &gt;= T.length) throw new Error('a { is not closed'); list.push(stmt()); } p++; return { k: 'block', list }; }&#10;        if (eat(';')) return { k: 'empty' };&#10;        const t = peek();&#10;        if (t.k === 'id') {&#10;            if (t.v === 'if') { p++; expect('('); const c = expr(); expect(')'); const a = stmt(); let b = null; if (isId('else')) { p++; b = stmt(); } return { k: 'if', c, a, b }; }&#10;            if (t.v === 'for') {&#10;                p++; expect('(');&#10;                let init = null; if (!isOp(';')) init = declOrExpr(); else p++;&#10;                const c = isOp(';') ? null : expr(); expect(';');&#10;                const step = isOp(')') ? null : expr(); expect(')');&#10;                return { k: 'for', init, c, step, body: stmt() };&#10;            }&#10;            if (t.v === 'while') { p++; expect('('); const c = expr(); expect(')'); return { k: 'while', c, body: stmt() }; }&#10;            if (t.v === 'do') { p++; const body = stmt(); if (!isId('while')) throw new Error('do without while'); p++; expect('('); const c = expr(); expect(')'); eat(';'); return { k: 'do', c, body }; }&#10;            if (t.v === 'return') { p++; const e = isOp(';') ? null : expr(); eat(';'); return { k: 'return', e }; }&#10;            if (t.v === 'break' || t.v === 'continue') { p++; eat(';'); return { k: t.v }; }&#10;            if (t.v === 'discard') { p++; eat(';'); return { k: 'discard' }; }&#10;            if (t.v === 'switch') throw new Error('switch is not supported');&#10;        }&#10;        return declOrExpr();&#10;    }&#10;    function looksLikeDecl() {&#10;        let o = 0;&#10;        while (peek(o) &amp;&amp; peek(o).k === 'id' &amp;&amp; QUAL.has(peek(o).v)) o++;&#10;        if (isId('vector', o) || isId('matrix', o)) return true;&#10;        return typeAt(o) &amp;&amp; peek(o + 1) &amp;&amp; peek(o + 1).k === 'id';&#10;    }&#10;    function declOrExpr() {&#10;        if (looksLikeDecl()) {&#10;            const rt = readType();&#10;            const vars = [];&#10;            do {&#10;                const name = T[p++].v;&#10;                let len = null;&#10;                while (eat('[')) { len = isOp(']') ? { k: 'num', v: '0' } : expr(); expect(']'); }&#10;                skipSemantic();&#10;                let init = null;&#10;                if (eat('=')) { if (isId('sampler_state')) { p++; skipBraces(); } else init = assignE(); }&#10;                vars.push({ name, len, init });&#10;            } while (eat(','));&#10;            eat(';');&#10;            return { k: 'decl', t: rt.t, quals: rt.quals, vars };&#10;        }&#10;        const e = expr(); eat(';');&#10;        return { k: 'expr', e };&#10;    }&#10;&#10;    // the whole file: declarations, functions and shader_body&#10;    const top = [];&#10;    let body = null;&#10;    try {&#10;    while (p &lt; T.length) {&#10;        if (eat(';')) continue;&#10;        if (isId('shader_body')) { p++; body = stmt(); continue; }&#10;        if (isId('struct')) {&#10;            p++; const name = T[p++].v; expect('{');&#10;            const fields = [];&#10;            while (!isOp('}')) { const rt = readType(); if (!rt) { p++; continue; } do { const fn = T[p++].v; let len = null; if (eat('[')) { len = expr(); expect(']'); } skipSemantic(); fields.push({ name: fn, t: rt.t, len }); } while (eat(',')); eat(';'); }&#10;            p++; eat(';');&#10;            structs[name] = fields;&#10;            top.push({ k: 'struct', name, fields });&#10;            continue;&#10;        }&#10;        if (isId('sampler_state')) { p++; skipBraces(); continue; }&#10;        if (isId('technique') || isId('pass')) { while (p &lt; T.length &amp;&amp; !isOp('{')) p++; skipBraces(); continue; }&#10;        const save = p;&#10;        const rt = readType();&#10;        if (!rt || !peek() || peek().k !== 'id') { p = save + 1; continue; }&#10;        if (isOp('(', 1)) {   // a function&#10;            const name = T[p++].v; p++;&#10;            const params = [];&#10;            if (!isOp(')') &amp;&amp; !(isId('void') &amp;&amp; isOp(')', 1))) {&#10;                do {&#10;                    const pt = readType();&#10;                    if (!pt) throw new Error('parameter type unknown near ' + around());&#10;                    const pn = T[p++].v;&#10;                    let len = null; if (eat('[')) { len = expr(); expect(']'); }&#10;                    skipSemantic();&#10;                    let def = null; if (eat('=')) def = assignE();&#10;                    params.push({ t: pt.t, name: pn, out: pt.quals.includes('out') ? 'out' : pt.quals.includes('inout') ? 'inout' : '', def, len });&#10;                } while (eat(','));&#10;            } else if (isId('void')) p++;&#10;            expect(')');&#10;            skipSemantic();&#10;            if (eat(';')) { top.push({ k: 'proto', name, rt: rt.t, params }); continue; }&#10;            const fb = stmt();&#10;            top.push({ k: 'func', name, rt: rt.t, params, body: fb });&#10;            continue;&#10;        }&#10;        // global variables&#10;        p = save;&#10;        const d = declOrExpr();&#10;        top.push(d);&#10;    }&#10;    } catch (err) {&#10;        note('The ' + kind + ' shader could not be read (' + err.message + '): left out');&#10;        return null;&#10;    }&#10;    if (!body) { note('The ' + kind + ' shader has no shader_body: left out'); return null; }&#10;&#10;    // ---------- what is there before the preset's own code ----------&#10;    const GLSL_NAMES = new Set(('attribute const uniform varying layout centroid flat smooth noperspective patch sample break continue do for while switch case default ' +&#10;        'if else subroutine in out inout float double int void bool true false invariant precise discard return mat2 mat3 mat4 dmat2 dmat3 dmat4 ' +&#10;        'mat2x2 mat2x3 mat2x4 mat3x2 mat3x3 mat3x4 mat4x2 mat4x3 mat4x4 vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 dvec2 dvec3 dvec4 ' +&#10;        'uint uvec2 uvec3 uvec4 lowp mediump highp precision sampler1D sampler2D sampler3D samplerCube struct common partition active asm class union enum ' +&#10;        'typedef template this resource goto inline noinline public static extern external interface long short half fixed unsigned superp input output ' +&#10;        'hvec2 hvec3 hvec4 fvec2 fvec3 fvec4 filter sizeof cast namespace using row_major buffer shared coherent volatile restrict readonly writeonly ' +&#10;        'texture radians degrees sin cos tan asin acos atan sinh cosh tanh asinh acosh atanh pow exp log exp2 log2 sqrt inversesqrt abs sign floor trunc ' +&#10;        'round roundEven ceil fract mod modf min max clamp mix step smoothstep isnan isinf floatBitsToInt intBitsToFloat packSnorm2x16 length distance ' +&#10;        'dot cross normalize faceforward reflect refract matrixCompMult outerProduct transpose determinant inverse lessThan lessThanEqual greaterThan ' +&#10;        'greaterThanEqual equal notEqual any all not textureSize textureLod textureProj textureGrad texelFetch dFdx dFdy fwidth main mainImage').split(' '));&#10;    const rename = n =&gt; (GLSL_NAMES.has(n) || /__/.test(n) || /^gl_/.test(n) || /^md_|^MDS_|^p_|^f_|^qi_/.test(n)) ? 'u_' + n.replace(/__+/g, '_') + '_' : n;&#10;    const scopes = [{}];&#10;    const declare = (name, t, gl) =&gt; { scopes[scopes.length - 1][name] = { t, gl: gl || name }; };&#10;    const lookup = name =&gt; { for (let i = scopes.length - 1; i &gt;= 0; i--) if (scopes[i][name]) return scopes[i][name]; return null; };&#10;    // MilkDrop's own names (include.fx), as the player keeps them&#10;    ['time', 'fps', 'frame', 'progress', 'bass', 'mid', 'treb', 'vol', 'bass_att', 'mid_att', 'treb_att', 'vol_att',&#10;     'blur1_min', 'blur1_max', 'blur2_min', 'blur2_max', 'blur3_min', 'blur3_max'].forEach(n =&gt; declare(n, F(1)));&#10;    for (let k = 1; k &lt;= 64; k++) declare('q' + k, F(1));&#10;    ['aspect', 'texsize', 'roam_cos', 'roam_sin', 'slow_roam_cos', 'slow_roam_sin', 'rand_frame', 'rand_preset'].forEach(n =&gt; declare(n, F(4)));&#10;    'abcdefghijklmnop'.split('').forEach((c, k) =&gt; declare('_q' + c, F(4), 'vec4(q' + (k * 4 + 1) + ', q' + (k * 4 + 2) + ', q' + (k * 4 + 3) + ', q' + (k * 4 + 4) + ')'));&#10;    declare('mouse', F(4), 'vec4(0.5, 0.5, 0.0, 0.0)'); declare('mouse_pos', F(2), 'vec2(0.5)');&#10;    ['mouse_x', 'mouse_y'].forEach(n =&gt; declare(n, F(1), '0.5')); ['mouse_z', 'mouse_w'].forEach(n =&gt; declare(n, F(1), '0.0'));&#10;    declare('mip_x', F(1), '1.0'); declare('mip_y', F(1), '1.0'); declare('mip_xy', F(2), 'vec2(1.0)'); declare('mip_avg', F(1), '0.5');&#10;    declare('_c0', F(4), 'aspect'); declare('_c2', F(4), 'vec4(time, fps, frame, progress)'); declare('_c3', F(4), 'vec4(bass, mid, treb, vol)');&#10;    declare('_c4', F(4), 'vec4(bass_att, mid_att, treb_att, vol_att)'); declare('_c5', F(4), 'vec4(1.0, 0.0, 1.0, 0.0)'); declare('_c6', F(4), 'vec4(1.0, 0.0, blur1_min, blur1_max)');&#10;    declare('_c7', F(4), 'texsize'); declare('_c8', F(4), 'roam_cos'); declare('_c9', F(4), 'roam_sin'); declare('_c10', F(4), 'slow_roam_cos'); declare('_c11', F(4), 'slow_roam_sin');&#10;    declare('_c12', F(4), 'vec4(1.0, 1.0, 0.5, 0.0)'); declare('_c13', F(4), 'vec4(blur2_min, blur2_max, blur3_min, blur3_max)'); declare('_c14', F(4), 'vec4(0.5, 0.5, 0.0, 0.0)');&#10;    declare('_c1', F(4), 'vec4(0.0)');&#10;    ['s', 'd', 'f', 'vf', 'uf', 'rand'].forEach((s, si) =&gt; { for (let k = 1; k &lt;= 4; k++) declare('rot_' + s + k, M(4, 3), 'md_rot(' + (si * 4 + k) + '.0, ' + si + ')'); });&#10;    const M_CONST = { M_PI: '3.14159265359', M_PI_2: '6.28318530718', M_INV_PI_2: '0.159154943091895', M_PI_4: '0.785398163397', M_E: '2.718281828459', M_1_PI: '0.318309886184', M_SQRT2: '1.414213562373' };&#10;    for (const k in M_CONST) declare(k, F(1), M_CONST[k]);&#10;    scopes.push({});   // the preset's own globals hide ours&#10;&#10;    // ---------- writing GLSL ----------&#10;    const userFns = {};   // name -&gt; [{ gl, rt, params }]&#10;    let curRet = VOID;&#10;    let helpers = new Set();&#10;    function num(v) {&#10;        let s = v.replace(/[fFhHlLuU]$/, '');&#10;        if (/^0[xX]/.test(s)) return { c: String(parseInt(s, 16)), t: I(1) };&#10;        if (/[.eE]/.test(s)) { if (s[0] === '.') s = '0' + s; if (/\.$/.test(s)) s += '0'; if (/^\d+[eE]/.test(s)) s = s.replace(/[eE]/, '.0e'); s = s.replace(/\.([eE])/, '.0$1'); return { c: s, t: F(1) }; }&#10;        if (/[fFhH]$/.test(v)) return { c: s + '.0', t: F(1) };&#10;        return { c: String(parseInt(s, 10)), t: I(1) };&#10;    }&#10;    const fl = e =&gt; conv(e.c, e.t, isNum(e.t) ? F(e.t.n) : e.t);   // as float(s)&#10;    function dimOf(list) {   // HLSL: the vectors in a call or a sum set the size; a vector beats a number, the smaller vector wins&#10;        let n = 0;&#10;        for (const e of list) if (isNum(e.t) &amp;&amp; e.t.n &gt; 1) n = n ? Math.min(n, e.t.n) : e.t.n;&#10;        return n || 1;&#10;    }&#10;    const isLit = (e, val) =&gt; e &amp;&amp; e.t &amp;&amp; isNum(e.t) &amp;&amp; e.t.n === 1 &amp;&amp; /^-?\d+(\.0*)?$/.test(e.c) &amp;&amp; +e.c === val;&#10;    function cw(gl, args, extra) {   // a function that works per component&#10;        const n = dimOf(args);&#10;        return { c: gl + '(' + args.map(a =&gt; conv(a.c, a.t, F(n))).join(', ') + (extra || '') + ')', t: F(n) };&#10;    }&#10;    const BUILTIN = {&#10;        abs: 1, acos: 1, asin: 1, atan: 1, ceil: 1, cos: 1, cosh: 1, degrees: 1, exp: 1, exp2: 1, floor: 1, log2: 1, radians: 1, round: 1,&#10;        sign: 1, sin: 1, sinh: 1, tan: 1, tanh: 1, trunc: 1, fwidth: 1, frac: 'fract', rsqrt: 'inversesqrt', ddx: 'dFdx', ddy: 'dFdy',&#10;        min: 1, max: 1, step: 1, clamp: 1, smoothstep: 1, lerp: 'mix', atan2: 'atan', reflect: 1, ldexp: 'md_ldexp', fmod: 'md_fmod'&#10;    };&#10;    function call(f, args, node) {&#10;        // the preset's own functions first&#10;        const uf = userFns[f];&#10;        if (uf) {&#10;            let best = null, score = -1;&#10;            for (const o of uf) {&#10;                const need = o.params.filter(q =&gt; !q.def).length;&#10;                if (args.length &lt; need || args.length &gt; o.params.length) continue;&#10;                let s = 1;&#10;                args.forEach((a, i) =&gt; { if (same(a.t, o.params[i].t)) s += 2; else if (isNum(a.t) &amp;&amp; isNum(o.params[i].t) &amp;&amp; a.t.n === o.params[i].t.n) s += 1; });&#10;                if (s &gt; score) { score = s; best = o; }&#10;            }&#10;            if (best) {&#10;                const parts = best.params.map((q, i) =&gt; {&#10;                    if (i &lt; args.length) return q.out || q.len ? args[i].c : conv(args[i].c, args[i].t, q.t);&#10;                    return conv(gen(q.def).c, gen(q.def).t, q.t);&#10;                });&#10;                return { c: best.gl + '(' + parts.join(', ') + ')', t: best.rt };&#10;            }&#10;        }&#10;        // a constructor: float3(...), float2x2(...)&#10;        const ct = typeFromName(f);&#10;        if (ct &amp;&amp; !ct.s &amp;&amp; !ct.v) {&#10;            if (ct.st) return { c: f + '(' + args.map(a =&gt; a.c).join(', ') + ')', t: ct };&#10;            if (args.length === 1 &amp;&amp; (isNum(args[0].t) &amp;&amp; (args[0].t.n === 1 || args[0].t.n &gt;= ct.n) || args[0].t.m)) return { c: conv(args[0].c, args[0].t, ct), t: ct };&#10;            if (ct.m) return { c: glType(ct) + '(' + args.map(a =&gt; isNum(a.t) ? conv(a.c, a.t, F(a.t.n)) : a.c).join(', ') + ')', t: ct };&#10;            // each argument as many components as it has, in the constructor's own kind&#10;            let have = 0;&#10;            const parts = [];&#10;            for (const a of args) {&#10;                if (have &gt;= ct.n) break;&#10;                let n = isNum(a.t) ? a.t.n : a.t.m ? a.t.r * a.t.c : 1;&#10;                if (a.t.m) { parts.push(a.c); have += n; continue; }&#10;                if (have + n &gt; ct.n) { const k = ct.n - have; parts.push(conv(a.c, a.t, { b: ct.b, n: k })); have += k; continue; }&#10;                parts.push(conv(a.c, a.t, { b: ct.b, n }));&#10;                have += n;&#10;            }&#10;            while (have &lt; ct.n) { parts.push(ct.b === 'f' ? '0.0' : ct.b === 'i' ? '0' : 'false'); have++; }&#10;            return { c: glType(ct) + '(' + parts.join(', ') + ')', t: ct };&#10;        }&#10;        const a = args;&#10;        const lf = f.toLowerCase();&#10;        if (BUILTIN[f]) return cw(BUILTIN[f] === 1 ? f : BUILTIN[f], a);&#10;        switch (f) {&#10;            case 'sqrt': return cw('sqrt', a.map(x =&gt; ({ c: 'abs(' + fl(x) + ')', t: F(x.t.n) })));   // HLSL gives nothing (NaN) below 0: MilkDrop presets mostly mean the size&#10;            case 'log': return cw('log', a.map(x =&gt; ({ c: 'max(' + fl(x) + ', 1e-30)', t: F(x.t.n) })));&#10;            case 'log10': { const r = cw('log', [{ c: 'max(' + fl(a[0]) + ', 1e-30)', t: F(a[0].t.n) }]); return { c: '(' + r.c + ' * 0.4342944819)', t: r.t }; }&#10;            case 'saturate': { const n = dimOf(a); return { c: 'clamp(' + conv(a[0].c, a[0].t, F(n)) + ', 0.0, 1.0)', t: F(n) }; }&#10;            case 'rcp': { const n = dimOf(a); return { c: '(1.0 / ' + conv(a[0].c, a[0].t, F(n)) + ')', t: F(n) }; }&#10;            case 'pow': {&#10;                const n = dimOf(a), x = conv(a[0].c, a[0].t, F(n));&#10;                if (isLit(a[1], 1)) return { c: '(' + x + ')', t: F(n) };&#10;                if (isLit(a[1], 2) || isLit(a[1], 3) || isLit(a[1], 4)) { helpers.add('pow'); return { c: 'md_ipow(' + x + ', ' + (+a[1].c) + ')', t: F(n) }; }&#10;                return { c: 'pow(abs(' + x + '), ' + conv(a[1].c, a[1].t, F(n)) + ')', t: F(n) };&#10;            }&#10;            case 'mad': { const n = dimOf(a); return { c: '(' + a.map(x =&gt; conv(x.c, x.t, F(n))).slice(0, 2).join(' * ') + ' + ' + conv(a[2].c, a[2].t, F(n)) + ')', t: F(n) }; }&#10;            case 'dot': { const n = dimOf(a); return { c: 'dot(' + conv(a[0].c, a[0].t, F(n)) + ', ' + conv(a[1].c, a[1].t, F(n)) + ')', t: F(1) }; }&#10;            case 'cross': return { c: 'cross(' + conv(a[0].c, a[0].t, F(3)) + ', ' + conv(a[1].c, a[1].t, F(3)) + ')', t: F(3) };&#10;            case 'length': return { c: 'length(' + fl(a[0]) + ')', t: F(1) };&#10;            case 'distance': { const n = dimOf(a); return { c: 'distance(' + conv(a[0].c, a[0].t, F(n)) + ', ' + conv(a[1].c, a[1].t, F(n)) + ')', t: F(1) }; }&#10;            case 'normalize': return { c: 'normalize(' + fl(a[0]) + ')', t: F(a[0].t.n) };&#10;            case 'refract': { const n = dimOf(a.slice(0, 2)); return { c: 'refract(' + conv(a[0].c, a[0].t, F(n)) + ', ' + conv(a[1].c, a[1].t, F(n)) + ', ' + conv(a[2].c, a[2].t, F(1)) + ')', t: F(n) }; }&#10;            case 'faceforward': return cw('faceforward', a);&#10;            case 'determinant': return { c: 'determinant(' + a[0].c + ')', t: F(1) };&#10;            case 'transpose': return { c: 'transpose(' + a[0].c + ')', t: M(a[0].t.c, a[0].t.r) };&#10;            case 'any': case 'all': { const x = a[0]; if (x.t.n === 1) return { c: toBool(x), t: B(1) }; return { c: f + '(' + conv(x.c, x.t, B(x.t.n)) + ')', t: B(1) }; }&#10;            case 'isnan': case 'isinf': return { c: f + '(' + fl(a[0]) + ')', t: B(a[0].t.n) };&#10;            case 'isfinite': return { c: '!isinf(' + fl(a[0]) + ')', t: B(a[0].t.n) };&#10;            case 'sincos': return { c: '(' + a[1].c + ' = sin(' + fl(a[0]) + '), ' + a[2].c + ' = cos(' + fl(a[0]) + '))', t: VOID };&#10;            case 'modf': return { c: 'modf(' + fl(a[0]) + ', ' + a[1].c + ')', t: F(a[0].t.n) };&#10;            case 'mul': {&#10;                const [x, y] = a;&#10;                if (x.t.m &amp;&amp; y.t.m) return { c: '(' + y.c + ' * ' + x.c + ')', t: M(x.t.r, y.t.c) };&#10;                if (y.t.m) return { c: '(' + y.c + ' * ' + conv(x.c, x.t, F(y.t.r)) + ')', t: F(y.t.c) };&#10;                if (x.t.m) return { c: '(' + conv(y.c, y.t, F(x.t.c)) + ' * ' + x.c + ')', t: F(x.t.r) };&#10;                const n = dimOf(a); return { c: '(' + conv(x.c, x.t, F(n)) + ' * ' + conv(y.c, y.t, F(n)) + ')', t: F(n) };&#10;            }&#10;            case 'clip': return { c: '0.0', t: F(1) };&#10;            case 'noise': helpers.add('noise'); return { c: 'md_hnoise(' + conv(a[0].c, a[0].t, F(3)) + ')', t: F(1) };&#10;            case 'tex2D': case 'tex2d': case 'tex2Dlod': case 'tex2Dbias': case 'tex2Dgrad': case 'tex2Dproj': case 'tex1D': {&#10;                const s = a[0].t.s ? a[0].c : 'MDS_0';&#10;                let u = a[1];&#10;                if (!u) return { c: 'vec4(0.0)', t: F(4) };&#10;                let uc = f === 'tex2Dproj' ? '((' + conv(u.c, u.t, F(4)) + ').xy / (' + conv(u.c, u.t, F(4)) + ').w)' : f === 'tex1D' ? 'vec2(' + conv(u.c, u.t, F(1)) + ', 0.5)' : conv(u.c, u.t, F(2));&#10;                return { c: 'md_tex2D(' + s + ', ' + uc + ')', t: F(4) };&#10;            }&#10;            case 'tex3D': case 'tex3d': case 'tex3Dlod': {&#10;                const s = a[0].t.s ? a[0].c : 'MDS_20';&#10;                return { c: 'md_tex3D(' + s + ', ' + conv(a[1].c, a[1].t, F(3)) + ')', t: F(4) };&#10;            }&#10;            case 'texCUBE': return { c: 'md_tex3D(MDS_20, ' + conv(a[1].c, a[1].t, F(3)) + ')', t: F(4) };&#10;            case 'GetPixel': case 'GetMain': return { c: 'md_pixel(' + conv(a[0].c, a[0].t, F(2)) + ')', t: F(3) };&#10;            case 'GetBlur1': case 'GetBlur2': case 'GetBlur3': return { c: 'md_blur' + f.slice(-1) + '(' + conv(a[0].c, a[0].t, F(2)) + ')', t: F(3) };&#10;            case 'lum': { const x = a[0]; if (x.t.n === 1) return { c: fl(x), t: F(1) }; return { c: 'dot(' + conv(x.c, x.t, F(3)) + ', vec3(0.32, 0.49, 0.29))', t: F(1) }; }&#10;            case 'get_fft': return { c: 'md_fft(' + conv(a[0].c, a[0].t, F(1)) + ')', t: F(1) };&#10;            case 'get_fft_hz': return { c: 'md_fft(' + conv(a[0].c, a[0].t, F(1)) + ' / 22050.0)', t: F(1) };&#10;            case 'asfloat': case 'asint': case 'asuint': return a[0];&#10;        }&#10;        if (/^tex/.test(lf)) return { c: 'vec4(0.0)', t: F(4) };&#10;        note('Unknown function ' + f + '() in the ' + kind + ' shader: reads 0');&#10;        return { c: '0.0', t: F(1) };&#10;    }&#10;    function lvalueType(e) { return e.t; }&#10;    function gen(n) {&#10;        switch (n.k) {&#10;            case 'num': return num(n.v);&#10;            case 'bool': return { c: n.v, t: B(1) };&#10;            case 'paren': { const e = gen(n.a); return { c: '(' + e.c + ')', t: e.t, lv: e.lv }; }&#10;            case 'comma': { const l = n.list.map(gen); return { c: '(' + l.map(x =&gt; x.c).join(', ') + ')', t: l[l.length - 1].t }; }&#10;            case 'id': {&#10;                const v = n.v;&#10;                const s = lookup(v);&#10;                if (s) return { c: constMode &amp;&amp; s.cv !== undefined ? String(s.cv) : s.gl, t: s.t, lv: true };&#10;                if (/^sampler_/i.test(v)) { const c = env.sampler(v.slice(8)); return { c: c || 'MDS_0', t: SAMPLER }; }&#10;                if (/^texsize_/i.test(v)) return { c: env.texsize(v.slice(8)), t: F(4) };&#10;                note('Unknown name &quot;' + v + '&quot; in the ' + kind + ' shader: reads 0');&#10;                declare(v, F(1), '0.0');&#10;                return { c: '0.0', t: F(1) };&#10;            }&#10;            case 'cast': {&#10;                const e = gen(n.a);&#10;                if (n.t.st) return { c: n.t.st + '(' + structs[n.t.st].map(f =&gt; conv(e.c, e.t, f.t)).join(', ') + ')', t: n.t };&#10;                return { c: conv(e.c, e.t, n.t), t: n.t };&#10;            }&#10;            case 'init': return { init: n.list, c: '', t: null };&#10;            case 'un': {&#10;                const e = gen(n.a);&#10;                if (n.op === '!') { if (isNum(e.t) &amp;&amp; e.t.n &gt; 1) return { c: 'not(' + conv(e.c, e.t, B(e.t.n)) + ')', t: B(e.t.n) }; return { c: '!(' + toBool(e) + ')', t: B(1) }; }&#10;                if (n.op === '~') return { c: '~' + conv(e.c, e.t, I(e.t.n || 1)), t: I(e.t.n || 1) };&#10;                if (n.op === '++' || n.op === '--') return { c: n.op + e.c, t: e.t };&#10;                if (isNum(e.t) &amp;&amp; e.t.b === 'b') return { c: n.op + conv(e.c, e.t, F(e.t.n)), t: F(e.t.n) };&#10;                return { c: n.op + e.c, t: e.t };&#10;            }&#10;            case 'post': { const e = gen(n.a); return { c: e.c + n.op, t: e.t }; }&#10;            case 'tern': {&#10;                const c = gen(n.c), a = gen(n.a), b = gen(n.b);&#10;                if (!isNum(a.t) || !isNum(b.t)) return { c: '(' + toBool(c) + ' ? ' + a.c + ' : ' + b.c + ')', t: a.t };&#10;                const nn = Math.max(a.t.n, b.t.n), bb = maxB(a.t.b, b.t.b), tt = { b: bb, n: nn };&#10;                if (isNum(c.t) &amp;&amp; c.t.n &gt; 1) { const m = Math.min(c.t.n, nn &gt; 1 ? nn : c.t.n); const t2 = F(m); return { c: 'mix(' + conv(b.c, b.t, t2) + ', ' + conv(a.c, a.t, t2) + ', ' + conv(c.c, c.t, t2) + ')', t: t2 }; }&#10;                return { c: '(' + toBool(c) + ' ? ' + conv(a.c, a.t, tt) + ' : ' + conv(b.c, b.t, tt) + ')', t: tt };&#10;            }&#10;            case 'bin': return bin(n.op, gen(n.a), gen(n.b));&#10;            case 'assign': {&#10;                const a = gen(n.a);&#10;                const b = gen(n.b);&#10;                if (b.init) return { c: a.c + ' = ' + initList(b.init, a.t).c, t: a.t };&#10;                if (n.op === '=') return { c: a.c + ' = ' + conv(b.c, b.t, a.t), t: a.t };&#10;                const op = n.op.slice(0, -1);&#10;                if (!isNum(a.t)) return { c: a.c + ' ' + n.op + ' ' + b.c, t: a.t };&#10;                if (op === '%' || op === '&amp;' || op === '|' || op === '^' || op === '&lt;&lt;' || op === '&gt;&gt;' || a.t.b !== 'f' &amp;&amp; b.t.b === 'f' || b.t.b === 'b' || a.t.b === 'b') {&#10;                    const r = bin(op, { c: a.c, t: a.t }, b);&#10;                    return { c: a.c + ' = ' + conv(r.c, r.t, a.t), t: a.t };&#10;                }&#10;                if (isNum(b.t) &amp;&amp; b.t.n === 1) return { c: a.c + ' ' + n.op + ' ' + conv(b.c, b.t, { b: a.t.b, n: 1 }), t: a.t };&#10;                return { c: a.c + ' ' + n.op + ' ' + conv(b.c, b.t, a.t), t: a.t };&#10;            }&#10;            case 'dot': {&#10;                const e = gen(n.a), f = n.f;&#10;                if (e.t &amp;&amp; e.t.st) { const fd = structs[e.t.st].find(x =&gt; x.name === f); return { c: e.c + '.' + f, t: fd ? (fd.len ? Object.assign({}, fd.t, { len: 1 }) : fd.t) : F(1), lv: true }; }&#10;                if (e.t &amp;&amp; e.t.m) {   // ._m00, ._11&#10;                    const mm = f.match(/^(?:_m([0-3])([0-3]))+$/) ? [...f.matchAll(/_m([0-3])([0-3])/g)].map(x =&gt; [+x[1], +x[2]]) :&#10;                               f.match(/^(?:_([1-4])([1-4]))+$/) ? [...f.matchAll(/_([1-4])([1-4])/g)].map(x =&gt; [+x[1] - 1, +x[2] - 1]) : null;&#10;                    if (mm) { const parts = mm.map(([r, c]) =&gt; e.c + '[' + r + '][' + c + ']'); return parts.length === 1 ? { c: parts[0], t: F(1), lv: true } : { c: 'vec' + parts.length + '(' + parts.join(', ') + ')', t: F(parts.length) }; }&#10;                }&#10;                if (isNum(e.t) &amp;&amp; /^[xyzw]{1,4}$|^[rgba]{1,4}$/.test(f)) {&#10;                    if (e.t.n === 1) { if (f.length === 1) return { c: e.c, t: e.t, lv: e.lv }; return { c: glType({ b: e.t.b, n: f.length }) + '(' + e.c + ')', t: { b: e.t.b, n: f.length } }; }&#10;                    // a component beyond the vector: HLSL refuses, read 0&#10;                    const idx = f.split('').map(ch =&gt; 'xyzwrgba'.indexOf(ch) % 4);&#10;                    if (idx.some(k =&gt; k &gt;= e.t.n)) { const parts = idx.map(k =&gt; k &lt; e.t.n ? '(' + e.c + ').' + SW[k] : '0.0'); return f.length === 1 ? { c: parts[0], t: F(1) } : { c: 'vec' + f.length + '(' + parts.join(', ') + ')', t: F(f.length) }; }&#10;                    const base = /^[\w.\[\]]+$/.test(e.c) ? e.c : '(' + e.c + ')';&#10;                    return { c: base + '.' + f, t: { b: e.t.b, n: f.length }, lv: e.lv };&#10;                }&#10;                note('Unknown part .' + f + ' in the ' + kind + ' shader');&#10;                return { c: e.c, t: e.t };&#10;            }&#10;            case 'index': {&#10;                const e = gen(n.a), i = gen(n.i);&#10;                const ic = conv(i.c, i.t, I(1));&#10;                if (e.t &amp;&amp; e.t.len) { const t = Object.assign({}, e.t); delete t.len; return { c: e.c + '[' + ic + ']', t, lv: true }; }&#10;                if (e.t &amp;&amp; e.t.m) return { c: e.c + '[' + ic + ']', t: F(e.t.c), lv: true };&#10;                if (isNum(e.t) &amp;&amp; e.t.n &gt; 1) return { c: e.c + '[' + ic + ']', t: { b: e.t.b, n: 1 }, lv: true };&#10;                return e;&#10;            }&#10;            case 'call': return call(n.f, n.args.map(gen), n);&#10;            case 'method': {&#10;                // Texture.Sample(sampler, uv) of newer HLSL&#10;                const args = n.args.map(gen);&#10;                if (/^Sample/.test(n.f)) return { c: 'md_tex2D(' + (gen(n.a).t &amp;&amp; gen(n.a).t.s ? gen(n.a).c : 'MDS_0') + ', ' + conv(args[args.length - 1].c, args[args.length - 1].t, F(2)) + ')', t: F(4) };&#10;                note('Unknown function .' + n.f + '() in the ' + kind + ' shader: reads 0');&#10;                return { c: '0.0', t: F(1) };&#10;            }&#10;        }&#10;        throw new Error('unknown part ' + n.k);&#10;    }&#10;    function bin(op, a, b) {&#10;        if (op === '&amp;&amp;' || op === '||') {&#10;            const n = Math.max(a.t.n || 1, b.t.n || 1);&#10;            if (n &gt; 1) return { c: (op === '&amp;&amp;' ? 'notEqual(' + conv(a.c, a.t, F(n)) + ' * ' + conv(b.c, b.t, F(n)) : 'notEqual(abs(' + conv(a.c, a.t, F(n)) + ') + abs(' + conv(b.c, b.t, F(n)) + ')') + ', vec' + n + '(0.0))', t: B(n) };&#10;            return { c: '(' + toBool(a) + ' ' + op + ' ' + toBool(b) + ')', t: B(1) };&#10;        }&#10;        if (!isNum(a.t) || !isNum(b.t)) {   // matrices&#10;            if (isNum(a.t)) a = { c: conv(a.c, a.t, F(1)), t: F(1) };&#10;            if (isNum(b.t)) b = { c: conv(b.c, b.t, F(1)), t: F(1) };&#10;            if (op === '*' &amp;&amp; a.t.m &amp;&amp; b.t.m) return { c: 'matrixCompMult(' + a.c + ', ' + b.c + ')', t: a.t };&#10;            return { c: '(' + a.c + ' ' + op + ' ' + b.c + ')', t: a.t.m ? a.t : b.t };&#10;        }&#10;        const n = a.t.n === 1 ? b.t.n : b.t.n === 1 ? a.t.n : Math.min(a.t.n, b.t.n);&#10;        if (['&lt;', '&gt;', '&lt;=', '&gt;=', '==', '!='].includes(op)) {&#10;            const bb = maxB(maxB(a.t.b, b.t.b), 'i'), t = { b: bb, n };&#10;            if (a.t.b === 'b' &amp;&amp; b.t.b === 'b' &amp;&amp; n === 1 &amp;&amp; (op === '==' || op === '!=')) return { c: '(' + a.c + ' ' + op + ' ' + b.c + ')', t: B(1) };&#10;            if (n === 1) return { c: '(' + conv(a.c, a.t, t) + ' ' + op + ' ' + conv(b.c, b.t, t) + ')', t: B(1) };&#10;            const fn = { '&lt;': 'lessThan', '&gt;': 'greaterThan', '&lt;=': 'lessThanEqual', '&gt;=': 'greaterThanEqual', '==': 'equal', '!=': 'notEqual' }[op];&#10;            return { c: fn + '(' + conv(a.c, a.t, t) + ', ' + conv(b.c, b.t, t) + ')', t: B(n) };&#10;        }&#10;        if (['&amp;', '|', '^', '&lt;&lt;', '&gt;&gt;'].includes(op)) {&#10;            const t = I(n);&#10;            return { c: '(' + conv(a.c, a.t, t) + ' ' + op + ' ' + conv(b.c, b.t, t) + ')', t };&#10;        }&#10;        let bb = maxB(a.t.b, b.t.b); if (bb === 'b') bb = 'f';&#10;        if (op === '%') {&#10;            if (bb === 'i') return { c: '(' + conv(a.c, a.t, I(n)) + ' % ' + conv(b.c, b.t, I(n)) + ')', t: I(n) };&#10;            helpers.add('fmod');&#10;            return { c: 'md_fmod(' + conv(a.c, a.t, F(n)) + ', ' + conv(b.c, b.t, F(n)) + ')', t: F(n) };&#10;        }&#10;        // a number stays a number (GLSL allows vector * number), only of the same kind&#10;        const ca = a.t.n === 1 &amp;&amp; n &gt; 1 ? conv(a.c, a.t, { b: bb, n: 1 }) : conv(a.c, a.t, { b: bb, n });&#10;        const cb = b.t.n === 1 &amp;&amp; n &gt; 1 ? conv(b.c, b.t, { b: bb, n: 1 }) : conv(b.c, b.t, { b: bb, n });&#10;        return { c: '(' + ca + ' ' + op + ' ' + cb + ')', t: { b: bb, n } };&#10;    }&#10;    function initList(list, t) {   // { a, b, c } for an array, a vector, a matrix or a struct&#10;        const flat = [];&#10;        (function walk(l) { for (const x of l) { if (x.k === 'init') walk(x.list); else flat.push(gen(x)); } })(list);&#10;        if (t.len) {&#10;            const et = Object.assign({}, t); delete et.len;&#10;            const per = isNum(et) ? et.n : et.m ? et.r * et.c : 1;&#10;            const items = [];&#10;            if (flat.length === t.len || per === 1) flat.forEach(x =&gt; items.push(conv(x.c, x.t, et)));&#10;            else for (let i = 0; i + per &lt;= flat.length; i += per) items.push(call(glTypeToH(et), flat.slice(i, i + per)).c);&#10;            while (items.length &lt; t.len) items.push(conv('0.0', F(1), et));&#10;            return { c: glType(et) + '[' + t.len + '](' + items.slice(0, t.len).join(', ') + ')', t };&#10;        }&#10;        if (t.st) return { c: t.st + '(' + structs[t.st].map((f, i) =&gt; flat[i] ? conv(flat[i].c, flat[i].t, f.t) : conv('0.0', F(1), f.t)).join(', ') + ')', t };&#10;        return call(glTypeToH(t), flat);&#10;    }&#10;    function glTypeToH(t) { if (t.m) return 'float' + t.r + 'x' + t.c; return (t.b === 'f' ? 'float' : t.b === 'i' ? 'int' : 'bool') + (t.n &gt; 1 ? t.n : ''); }&#10;    let constMode = false;&#10;    function constInt(e) {   // an array's size&#10;        if (!e) return 1;&#10;        constMode = true; const g = gen(e); constMode = false;&#10;        try { const v = Function('return (' + g.c.replace(/\b(\d+)\.0\b/g, '$1') + ');')(); if (isFinite(v)) return Math.max(1, Math.floor(v)); } catch (err) {}&#10;        return 1;&#10;    }&#10;&#10;    let indent = '    ';&#10;    const out = [];&#10;    let globalsInit = [];&#10;    function decl(s, global) {&#10;        const lines = [];&#10;        if (s.t.s) { for (const v of s.vars) env.sampler(v.name.replace(/^sampler_/i, '')); return ''; }   // samplers: the player knows them by name&#10;        for (const v of s.vars) {&#10;            // our own names (time, q1, texsize ...): a preset may declare them again; keep ours&#10;            if (global &amp;&amp; scopes[0][v.name]) continue;&#10;            const t = Object.assign({}, s.t);&#10;            if (v.len) t.len = constInt(v.len);&#10;            const gl = rename(v.name);&#10;            let init = '';&#10;            if (v.init) {&#10;                const g = gen(v.init);&#10;                init = g.init ? initList(g.init, t).c : conv(g.c, g.t, t);&#10;            }&#10;            declare(v.name, t, gl);&#10;            if (v.init &amp;&amp; !t.len &amp;&amp; isNum(t) &amp;&amp; t.n === 1) { try { const cv = Function('return (' + init.replace(/\b(\d+)\.0\b/g, '$1').replace(/\b(?:float|int)\b/g, '') + ');')(); if (isFinite(cv)) lookup(v.name).cv = cv; } catch (err) {} }&#10;            const dt = glType(t) + ' ' + gl + (t.len ? '[' + t.len + ']' : '');&#10;            if (global) { lines.push(dt + ';'); if (init) globalsInit.push(gl + ' = ' + init + ';'); }&#10;            else lines.push(gl + (t.len ? '[' + t.len + ']' : '') + (init ? ' = ' + init : ''));&#10;        }&#10;        if (global) return lines.join(' ');&#10;        return lines.length ? glType(s.t) + ' ' + lines.join(', ') + ';' : '';&#10;    }&#10;    function st(s, ind) {&#10;        switch (s.k) {&#10;            case 'block': { scopes.push({}); const r = '{\n' + s.list.map(x =&gt; ind + '    ' + st(x, ind + '    ')).join('\n') + '\n' + ind + '}'; scopes.pop(); return r; }&#10;            case 'empty': return ';';&#10;            case 'decl': return decl(s, false) || ';';&#10;            case 'expr': { const e = gen(s.e); return (e.c || '') + ';'; }&#10;            case 'if': { const c = gen(s.c); const a = st(s.a, ind); return 'if (' + toBoolS(c) + ') ' + a + (s.b ? ' else ' + st(s.b, ind) : ''); }&#10;            case 'for': {&#10;                scopes.push({});&#10;                const init = s.init ? (s.init.k === 'decl' ? decl(s.init, false) : gen(s.init.e).c + ';') : ';';&#10;                const c = s.c ? toBoolS(gen(s.c)) : '';&#10;                const step = s.step ? gen(s.step).c : '';&#10;                const r = 'for (' + init + ' ' + c + '; ' + step + ') ' + st(s.body, ind);&#10;                scopes.pop();&#10;                return r;&#10;            }&#10;            case 'while': return 'while (' + toBoolS(gen(s.c)) + ') ' + st(s.body, ind);&#10;            case 'do': return 'do ' + st(s.body, ind) + ' while (' + toBoolS(gen(s.c)) + ');';&#10;            case 'return': {&#10;                if (curRet === 'body') return 'return ret;';&#10;                if (!s.e) return 'return;';&#10;                const e = gen(s.e);&#10;                return 'return ' + conv(e.c, e.t, curRet) + ';';&#10;            }&#10;            case 'break': case 'continue': return s.k + ';';&#10;            case 'discard': return curRet === 'body' ? 'return ret;' : ';';&#10;        }&#10;        return ';';&#10;    }&#10;    function toBoolS(e) { if (!isNum(e.t)) return e.c; if (e.t.n &gt; 1) return conv(e.c, e.t, B(1)); return toBool(e); }&#10;&#10;    const pieces = [];&#10;    try {&#10;        for (const s of top) {&#10;            if (s.k === 'struct') {&#10;                pieces.push('struct ' + s.name + ' {\n' + s.fields.map(f =&gt; '    ' + glType(f.t) + ' ' + f.name + (f.len ? '[' + constInt(f.len) + ']' : '') + ';').join('\n') + '\n};');&#10;                continue;&#10;            }&#10;            if (s.k === 'decl') { const d = decl(s, true); if (d) pieces.push(d); continue; }&#10;            if (s.k === 'func' || s.k === 'proto') {&#10;                const gl = rename(s.name);&#10;                const params = s.params.map(q =&gt; Object.assign({}, q, { t: q.len ? Object.assign({}, q.t, { len: constInt(q.len) }) : q.t }));&#10;                const entry = { gl, rt: s.rt, params };&#10;                const list = userFns[s.name] || (userFns[s.name] = []);&#10;                const sig = params.map(q =&gt; glType(q.t)).join(',');&#10;                if (!list.some(o =&gt; o.params.map(q =&gt; glType(q.t)).join(',') === sig)) list.push(entry);&#10;                const head = glType(s.rt) + ' ' + gl + '(' + params.map(q =&gt; (q.out ? q.out + ' ' : '') + glType(q.t) + ' ' + rename(q.name) + (q.t.len ? '[' + q.t.len + ']' : '')).join(', ') + ')';&#10;                if (s.k === 'proto') { pieces.push(head + ';'); continue; }&#10;                scopes.push({});&#10;                params.forEach(q =&gt; declare(q.name, q.t, rename(q.name)));&#10;                curRet = s.rt;&#10;                const b = st(s.body, '');&#10;                scopes.pop();&#10;                pieces.push(head + ' ' + b);&#10;            }&#10;        }&#10;        // the body: uv, uv_orig, rad, ang (and hue_shader) come in, ret goes out&#10;        scopes.push({});&#10;        declare('uv', F(2)); declare('uv_orig', F(2)); declare('rad', F(1)); declare('ang', F(1)); declare('ret', F(3));&#10;        if (kind === 'comp') declare('hue_shader', F(3));&#10;        curRet = 'body';&#10;        var bodyGL = st(body, '');&#10;        scopes.pop();&#10;    } catch (err) {&#10;        note('The ' + kind + ' shader could not be read (' + err.message + '): left out');&#10;        return null;&#10;    }&#10;    const fnName = kind === 'warp' ? 'md_wGlobals' : 'md_cGlobals';&#10;    const sig = kind === 'warp' ? 'vec3 md_warpShader(vec2 uv, vec2 uv_orig, float rad, float ang)' : 'vec3 md_compShader(vec2 uv, vec2 uv_orig, float rad, float ang, vec3 hue_shader)';&#10;    let h = '';&#10;    if (helpers.has('pow')) h += 'float md_ipow(float x, int n) { return n == 2 ? x * x : n == 3 ? x * x * x : x * x * x * x; }\nvec2 md_ipow(vec2 x, int n) { return n == 2 ? x * x : n == 3 ? x * x * x : x * x * x * x; }\nvec3 md_ipow(vec3 x, int n) { return n == 2 ? x * x : n == 3 ? x * x * x : x * x * x * x; }\nvec4 md_ipow(vec4 x, int n) { return n == 2 ? x * x : n == 3 ? x * x * x : x * x * x * x; }\n';&#10;    if (helpers.has('noise')) h += 'float md_hnoise(vec3 p) { return md_noise3(p, 32.0).x * 2.0 - 1.0; }\n';&#10;    return h + pieces.join('\n') + '\n' +&#10;        'void ' + fnName + '() {\n    ' + globalsInit.join('\n    ') + '\n}\n' +&#10;        sig + '\n{\n    vec3 ret = vec3(0.0);\n    ' + fnName + '();\n    ' + bodyGL + '\n    return ret;\n}\n';&#10;}&#10;&#10;&#10;&#10;// MilkDrop preset -&gt; MNodes Scene GLSL (#pass A, #pass B, #pass Image).&#10;// Buffer A: the picture MilkDrop keeps (warp of the last frame, then shapes, waves and borders on it).&#10;// Buffer B: a blurred copy of A (GetBlur1/2/3), and in its bottom row the per-frame state: every variable of&#10;// the per_frame code, worked out on the graphics card from the row of the frame before (so the sound is read&#10;// there too, from In A). P1 says which preset this is: a new one starts its variables again.&#10;&#10;// files: { lower-case texture name: file name } of the pictures you have (MilkDrop3\textures); the first two a preset reads go&#10;// into the Scene's Image 1 and Image 2, the rest get a stand-in.&#10;function mdConvert(text, which, standin, files) {&#10;    files = files || {};&#10;    const pictures = [];   // { name, file, slot }&#10;    const notes = [];&#10;    const note = s =&gt; { if (notes.indexOf(s) &lt; 0) notes.push(s); };&#10;&#10;    // ---------- reading the preset ----------&#10;    text = String(text).replace(/&amp;lt;/g, '&lt;').replace(/&amp;gt;/g, '&gt;').replace(/&amp;#39;/g, &quot;'&quot;).replace(/&amp;quot;/g, '&quot;').replace(/&amp;amp;/g, '&amp;');&#10;    const blocks = [];&#10;    const re = /\[PRESET(\d)_BEGIN\]([\s\S]*?)\[PRESET\1_END\]/gi;&#10;    let mm;&#10;    while ((mm = re.exec(text))) blocks.push(mm[2]);&#10;    const double = blocks.length &gt; 1;&#10;    const body = blocks.length ? blocks[Math.min(which || 0, blocks.length - 1)] : text;&#10;    const kv = {};&#10;    body.split(/\r?\n/).forEach(line =&gt; {&#10;        const i = line.indexOf('=');&#10;        if (i &lt;= 0) return;&#10;        kv[line.slice(0, i).trim().toLowerCase()] = line.slice(i + 1);&#10;    });&#10;    const num = (k, d) =&gt; { const v = parseFloat(kv[k.toLowerCase()]); return isFinite(v) ? v : d; };&#10;    const lines = prefix =&gt; {   // per_frame_1, per_frame_2 ... joined in order&#10;        const out = [];&#10;        for (const k in kv) {&#10;            const m = k.match(/^(.*?)(\d+)$/);&#10;            if (m &amp;&amp; m[1] === prefix) out.push([+m[2], kv[k]]);&#10;        }&#10;        out.sort((a, b) =&gt; a[0] - b[0]);&#10;        return out.map(x =&gt; x[1].replace(/^`/, '')).join('\n');&#10;    };&#10;    const name = (kv['name'] || '').trim() || 'MilkDrop preset';&#10;    // MilkDrop3 keeps some shaders to itself (only the compiled form, in its own cache): the text in the preset is a stand-in&#10;    const closed = /^\s*MD3[12]\s*=/mi.test(text) || /works only with MD3/i.test(text);&#10;    if (closed) note('Closed MilkDrop3 shader: its real code is not in the preset, only a simple stand-in plays');&#10;&#10;    // ---------- EEL (the per_frame / per_pixel / wave / shape code) -&gt; GLSL ----------&#10;    function eel(src, ctx) {&#10;        // ctx: { name: v =&gt; glsl name, seed: 'glsl float expr' for rand, used: Set of variable names }&#10;        src = src.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '');&#10;        const toks = [];&#10;        const tr = /\s*(?:(\d*\.\d+(?:e[+-]?\d+)?|\d+\.?(?:e[+-]?\d+)?)|([A-Za-z_][A-Za-z0-9_]*)|(\+=|-=|\*=|\/=|%=|\^=|\|=|&amp;=|==|!=|&lt;=|&gt;=|&amp;&amp;|\|\||[-+*\/%^=&lt;&gt;!(),;?:|&amp;~]))/iy;&#10;        let p = 0;&#10;        while (p &lt; src.length) {&#10;            tr.lastIndex = p;&#10;            const t = tr.exec(src);&#10;            if (!t) { if (/\s/.test(src[p])) { p++; continue; } note('Skipped a character it did not know: ' + src[p]); p++; continue; }&#10;            p = tr.lastIndex;&#10;            if (t[1] !== undefined) toks.push({ k: 'n', v: t[1] });&#10;            else if (t[2] !== undefined) toks.push({ k: 'id', v: t[2].toLowerCase().replace(/__+/g, '_u') });&#10;            else toks.push({ k: 'op', v: t[3] });&#10;        }&#10;        let i = 0;&#10;        const peek = () =&gt; toks[i], isOp = v =&gt; toks[i] &amp;&amp; toks[i].k === 'op' &amp;&amp; toks[i].v === v;&#10;        const eat = v =&gt; { if (isOp(v)) { i++; return true; } return false; };&#10;        const F = s =&gt; /^[0-9]/.test(s) || /^\./.test(s) ? (/[.e]/i.test(s) ? (s[0] === '.' ? '0' + s : s.replace(/\.$/, '.0')) : s + '.0') : s;&#10;        let site = 0;&#10;        const fn = {&#10;            sin: 1, cos: 1, tan: 1, asin: 1, acos: 1, atan: 1, sqrt: 'sqrt(abs(#0))', abs: 1, exp: 1, log: 'log(max(#0,1e-30))',&#10;            log10: '(log(max(#0,1e-30))/2.302585)', floor: 1, ceil: 1, sign: 1, min: 1, max: 1, pow: 'md_pow(#0,#1)', atan2: 'atan(#0,#1)',&#10;            sqr: '((#0)*(#0))', int: 'trunc(#0)', above: 'float((#0)&gt;(#1))', below: 'float((#0)&lt;(#1))', equal: 'float(abs((#0)-(#1))&lt;0.00001)',&#10;            bnot: 'float(abs(#0)&lt;0.00001)', band: 'float(abs(#0)&gt;0.00001&amp;&amp;abs(#1)&gt;0.00001)', bor: 'float(abs(#0)&gt;0.00001||abs(#1)&gt;0.00001)',&#10;            sigmoid: '(1.0/(1.0+exp(-(#0)*(#1))))', invsqrt: 'inversesqrt(abs(#0))', fmod: 'md_mod(#0,#1)', 'if': '((abs(#0)&gt;0.00001)?(#1):(#2))',&#10;            exec2: '(#0,#1)', exec3: '(#0,#1,#2)', clamp: 'clamp(#0,#1,#2)'&#10;        };&#10;        const vname = v =&gt; { ctx.used.add(v); return ctx.name(v); };&#10;        function primary() {&#10;            const t = peek();&#10;            if (!t) return '0.0';&#10;            if (t.k === 'n') { i++; return F(t.v); }&#10;            if (t.k === 'id') {&#10;                i++;&#10;                if (isOp('(')) {&#10;                    i++;&#10;                    const args = [];&#10;                    if (!isOp(')')) { do args.push(seq([',', ')'])); while (eat(',')); }&#10;                    eat(')');&#10;                    if (t.v === 'rand') { site++; return 'floor(md_hash(vec2(' + site + '.0+' + ctx.seed + ', ' + (ctx.seed2 || 'md_frame') + '))*max(' + (args[0] || '1.0') + ',1.0))'; }&#10;                    if (t.v === 'megabuf' || t.v === 'gmegabuf' || t.v === 'loop' || t.v === 'while') { note('megabuf/loop in the code: not supported (reads 0)'); return '0.0'; }&#10;                    const f = fn[t.v];&#10;                    if (!f) { note('Unknown function ' + t.v + '(): reads 0'); return '0.0'; }&#10;                    if (f === 1) return t.v + '(' + args.join(',') + ')';&#10;                    return '(' + f.replace(/#(\d)/g, (_, n) =&gt; args[+n] || '0.0') + ')';&#10;                }&#10;                return vname(t.v);&#10;            }&#10;            if (isOp('(')) { i++; const e = seq([')']); eat(')'); return '(' + e + ')'; }&#10;            if (isOp('-')) { i++; return '(-' + unary() + ')'; }&#10;            if (isOp('+')) { i++; return unary(); }&#10;            if (isOp('!')) { i++; return 'float(abs(' + unary() + ')&lt;0.00001)'; }&#10;            i++;&#10;            return '0.0';&#10;        }&#10;        function unary() { return primary(); }&#10;        function power() { let a = unary(); while (isOp('^')) { i++; a = 'md_pow(' + a + ',' + unary() + ')'; } return a; }&#10;        function mul() {&#10;            let a = power();&#10;            for (;;) {&#10;                if (isOp('*')) { i++; a = '(' + a + '*' + power() + ')'; }&#10;                else if (isOp('/')) { i++; a = 'md_div(' + a + ',' + power() + ')'; }&#10;                else if (isOp('%')) { i++; a = 'md_imod(' + a + ',' + power() + ')'; }&#10;                else return a;&#10;            }&#10;        }&#10;        function add() { let a = mul(); for (;;) { if (isOp('+')) { i++; a = '(' + a + '+' + mul() + ')'; } else if (isOp('-')) { i++; a = '(' + a + '-' + mul() + ')'; } else return a; } }&#10;        function cmp() {&#10;            let a = add();&#10;            for (;;) {&#10;                const t = peek();&#10;                if (t &amp;&amp; t.k === 'op' &amp;&amp; ['&lt;', '&gt;', '&lt;=', '&gt;='].includes(t.v)) { i++; a = 'float(' + a + t.v + add() + ')'; }&#10;                else if (isOp('==')) { i++; a = 'float(abs(' + a + '-' + add() + ')&lt;0.00001)'; }&#10;                else if (isOp('!=')) { i++; a = 'float(abs(' + a + '-' + add() + ')&gt;=0.00001)'; }&#10;                else return a;&#10;            }&#10;        }&#10;        function bits() { let a = cmp(); for (;;) { if (isOp('|')) { i++; a = 'float(int(' + a + ')|int(' + cmp() + '))'; } else if (isOp('&amp;')) { i++; a = 'float(int(' + a + ')&amp;int(' + cmp() + '))'; } else return a; } }&#10;        function and() { let a = bits(); while (isOp('&amp;&amp;')) { i++; a = 'float(abs(' + a + ')&gt;0.00001&amp;&amp;abs(' + bits() + ')&gt;0.00001)'; } return a; }&#10;        function or() { let a = and(); while (isOp('||')) { i++; a = 'float(abs(' + a + ')&gt;0.00001||abs(' + and() + ')&gt;0.00001)'; } return a; }&#10;        function tern() {&#10;            const c = or();&#10;            if (isOp('?')) { i++; const a = assign(); eat(':'); const b = assign(); return '((abs(' + c + ')&gt;0.00001)?(' + a + '):(' + b + '))'; }&#10;            return c;&#10;        }&#10;        function assign() {&#10;            const t = peek(), t2 = toks[i + 1];&#10;            if (t &amp;&amp; t.k === 'id' &amp;&amp; t2 &amp;&amp; t2.k === 'op' &amp;&amp; ['=', '+=', '-=', '*=', '/=', '%=', '^='].includes(t2.v)) {&#10;                i += 2;&#10;                const v = vname(t.v), e = assign();&#10;                if (t2.v === '=') return '(' + v + '=' + e + ')';&#10;                if (t2.v === '/=') return '(' + v + '=md_div(' + v + ',' + e + '))';&#10;                if (t2.v === '%=') return '(' + v + '=md_imod(' + v + ',' + e + '))';&#10;                if (t2.v === '^=') return '(' + v + '=md_pow(' + v + ',' + e + '))';&#10;                return '(' + v + t2.v + e + ')';&#10;            }&#10;            return tern();&#10;        }&#10;        function seq(stop) {   // a;b;c inside brackets: GLSL's comma&#10;            const parts = [];&#10;            for (;;) {&#10;                while (eat(';')) {}&#10;                if (!peek() || stop.some(s =&gt; isOp(s))) break;&#10;                parts.push(assign());&#10;                if (!eat(';')) break;&#10;            }&#10;            return parts.length ? parts.join(',') : '0.0';&#10;        }&#10;        const out = [];&#10;        let guard = 0;&#10;        while (i &lt; toks.length &amp;&amp; guard++ &lt; 100000) {&#10;            if (eat(';')) continue;&#10;            const s = assign();&#10;            out.push('    ' + s + ';');&#10;            if (i &lt; toks.length &amp;&amp; !eat(';')) {&#10;                if (isOp(')') || isOp(',')) { note('A bracket too many in the code: skipped'); i++; }&#10;                else if (!isOp(';')) { /* EEL lets statements touch: &quot;a=1 b=2&quot; is rare, carry on */ }&#10;            }&#10;        }&#10;        return out.join('\n');&#10;    }&#10;&#10;    // ---------- the variables MilkDrop keeps from frame to frame ----------&#10;    const FRAMEVARS = {   // name: preset key (and its default)&#10;        zoom: ['zoom', 1], zoomexp: ['fZoomExponent', 1], rot: ['rot', 0], warp: ['warp', 1], cx: ['cx', 0.5], cy: ['cy', 0.5],&#10;        dx: ['dx', 0], dy: ['dy', 0], sx: ['sx', 1], sy: ['sy', 1], decay: ['fDecay', 0.98], gamma: ['fGammaAdj', 2],&#10;        echo_zoom: ['fVideoEchoZoom', 2], echo_alpha: ['fVideoEchoAlpha', 0], echo_orient: ['nVideoEchoOrientation', 0],&#10;        wave_mode: ['nWaveMode', 0], wave_x: ['wave_x', 0.5], wave_y: ['wave_y', 0.5], wave_r: ['wave_r', 1], wave_g: ['wave_g', 1],&#10;        wave_b: ['wave_b', 1], wave_a: ['fWaveAlpha', 0.8], wave_mystery: ['fWaveParam', 0], wave_usedots: ['bWaveDots', 0],&#10;        wave_thick: ['bWaveThick', 0], wave_additive: ['bAdditiveWaves', 0], wave_brighten: ['bMaximizeWaveColor', 1],&#10;        wave_scale: ['fWaveScale', 1],&#10;        ob_size: ['ob_size', 0.01], ob_r: ['ob_r', 0], ob_g: ['ob_g', 0], ob_b: ['ob_b', 0], ob_a: ['ob_a', 0],&#10;        ib_size: ['ib_size', 0.01], ib_r: ['ib_r', 0.25], ib_g: ['ib_g', 0.25], ib_b: ['ib_b', 0.25], ib_a: ['ib_a', 0],&#10;        mv_x: ['nMotionVectorsX', 12], mv_y: ['nMotionVectorsY', 9], mv_dx: ['mv_dx', 0], mv_dy: ['mv_dy', 0], mv_l: ['mv_l', 0.9],&#10;        mv_r: ['mv_r', 1], mv_g: ['mv_g', 1], mv_b: ['mv_b', 1], mv_a: ['mv_a', 0],&#10;        darken_center: ['bDarkenCenter', 0], brighten: ['bBrighten', 0], darken: ['bDarken', 0], solarize: ['bSolarize', 0],&#10;        invert: ['bInvert', 0], warpanimspeed: ['fWarpAnimSpeed', 1], warpscale: ['fWarpScale', 1],&#10;        b1n: ['b1n', 0], b2n: ['b2n', 0], b3n: ['b3n', 0], b1x: ['b1x', 1], b2x: ['b2x', 1], b3x: ['b3x', 1], b1ed: ['b1ed', 0.25],&#10;        monitor: ['', 0]&#10;    };&#10;    const AUDIO = ['bass', 'mid', 'treb', 'bass_att', 'mid_att', 'treb_att', 'vol', 'vol_att'];&#10;    const READONLY = ['time', 'fps', 'frame', 'progress', 'meshx', 'meshy', 'pixelsx', 'pixelsy', 'aspectx', 'aspecty'];&#10;    const Q = []; for (let k = 1; k &lt;= 64; k++) Q.push('q' + k);&#10;&#10;    const initCode = lines('per_frame_init_'), frameCode = lines('per_frame_'), pixelCode = lines('per_pixel_');&#10;    const used = new Set();&#10;    const fctx = { name: v =&gt; 'f_' + v, seed: '0.0', used: used };&#10;    const glInit = eel(initCode, fctx), glFrame = eel(frameCode, fctx);&#10;    // every variable kept: MilkDrop's own, the q's, the sound, and what the code made up&#10;    const slots = Object.keys(FRAMEVARS).concat(Q, AUDIO, READONLY);&#10;    used.forEach(v =&gt; { if (slots.indexOf(v) &lt; 0) slots.push(v); });&#10;    const qinit = Q.map(q =&gt; 'qi_' + q);&#10;    const extra = ['md_id', 'md_bl', 'md_ml', 'md_tl', 'md_bs', 'md_ms', 'md_ts'];   // which preset, long and short sound levels&#10;    const all = slots.concat(qinit, extra);&#10;    const NT = Math.ceil(all.length / 4);&#10;    const slotOf = v =&gt; all.indexOf(v);&#10;    const sget = k =&gt; 'md_S[' + (k &gt;&gt; 2) + '].' + 'xyzw'[k &amp; 3];&#10;&#10;    const userVars = slots.filter(v =&gt; !FRAMEVARS[v] &amp;&amp; Q.indexOf(v) &lt; 0 &amp;&amp; AUDIO.indexOf(v) &lt; 0 &amp;&amp; READONLY.indexOf(v) &lt; 0);&#10;    const base = Object.keys(FRAMEVARS).map(v =&gt; {&#10;        const [key, d] = FRAMEVARS[v];&#10;        let val = key ? num(key, d) : d;&#10;        if (v === 'wave_a') val = Math.min(val, 1);&#10;        return '    f_' + v + ' = ' + glf(val) + ';';&#10;    }).join('\n');&#10;&#10;    // ---------- the pixel code (per_pixel) ----------&#10;    const PIXVARS = ['zoom', 'zoomexp', 'rot', 'warp', 'cx', 'cy', 'dx', 'dy', 'sx', 'sy'];&#10;    const pused = new Set();&#10;    const pctx = { name: v =&gt; 'p_' + v, seed: '(md_uvo.x*913.0+md_uvo.y*77.0)', used: pused };&#10;    const glPixel = eel(pixelCode, pctx);&#10;    const pixLocals = [];&#10;    pused.forEach(v =&gt; { if (PIXVARS.indexOf(v) &lt; 0 &amp;&amp; ['x', 'y', 'rad', 'ang'].indexOf(v) &lt; 0) pixLocals.push(v); });&#10;&#10;    // what a code (pixel, wave, shape) sees of the frame: the q's, the sound and the time&#10;    const frameView = (prefix, set, skip) =&gt; {&#10;        const out = [];&#10;        set.forEach(v =&gt; {&#10;            if (skip.indexOf(v) &gt;= 0) return;&#10;            const k = slotOf(v);&#10;            if (k &gt;= 0 &amp;&amp; (Q.indexOf(v) &gt;= 0 || AUDIO.indexOf(v) &gt;= 0 || READONLY.indexOf(v) &gt;= 0 || FRAMEVARS[v])) out.push('    float ' + prefix + v + ' = ' + sget(k) + ';');&#10;            else out.push('    float ' + prefix + v + ' = 0.0;');&#10;        });&#10;        return out.join('\n');&#10;    };&#10;&#10;    // ---------- custom waves ----------&#10;    let wavesGL = '';&#10;    for (let w = 0; w &lt; 16; w++) {&#10;        if (num('wavecode_' + w + '_enabled', 0) &lt; 0.5) continue;&#10;        const N = Math.max(2, Math.min(512, Math.round(num('wavecode_' + w + '_samples', 512))));&#10;        const wused = new Set(), wpused = new Set();&#10;        const wf = eel(lines('wave_' + w + '_per_frame'), { name: v =&gt; 'w_' + v, seed: '0.0', used: wused });&#10;        const wp = eel(lines('wave_' + w + '_per_point'), { name: v =&gt; 'w_' + v, seed: 'w_sample*1000.0', used: wpused });&#10;        const own = ['r', 'g', 'b', 'a', 'x', 'y', 'sample', 'value1', 'value2', 'samples', 'scaling', 'smoothing', 'sep',&#10;                     't1', 't2', 't3', 't4', 't5', 't6', 't7', 't8'];&#10;        const both = new Set([...wused, ...wpused]);&#10;        const dots = num('wavecode_' + w + '_busedots', 0) &gt; 0.5, thick = num('wavecode_' + w + '_bdrawthick', 0) &gt; 0.5;&#10;        const addv = num('wavecode_' + w + '_badditive', 0) &gt; 0.5, spec = num('wavecode_' + w + '_bspectrum', 0) &gt; 0.5;&#10;        wavesGL += `&#10;    {   // custom wave ${w}&#10;        float w_r = ${glf(num('wavecode_' + w + '_r', 1))}, w_g = ${glf(num('wavecode_' + w + '_g', 1))}, w_b = ${glf(num('wavecode_' + w + '_b', 1))}, w_a = ${glf(num('wavecode_' + w + '_a', 1))};&#10;        float w_x = 0.5, w_y = 0.5, w_sample = 0.0, w_value1 = 0.0, w_value2 = 0.0, w_samples = ${N}.0;&#10;        float w_scaling = ${glf(num('wavecode_' + w + '_scaling', 1))}, w_smoothing = ${glf(num('wavecode_' + w + '_smoothing', 0.5))}, w_sep = ${glf(num('wavecode_' + w + '_sep', 0))};&#10;        float w_t1 = 0.0, w_t2 = 0.0, w_t3 = 0.0, w_t4 = 0.0, w_t5 = 0.0, w_t6 = 0.0, w_t7 = 0.0, w_t8 = 0.0;&#10;${frameView('w_', both, own)}&#10;${wf}&#10;        float fr = w_r, fg = w_g, fb = w_b, fa = w_a;&#10;        vec2 prev = vec2(-1e5);&#10;        for (int i = 0; i &lt; ${N}; i++) {&#10;            w_sample = float(i) / ${N - 1}.0;&#10;            w_value1 = md_wave(w_sample, ${spec ? 1 : 0}) * w_scaling * 0.25;&#10;            w_value2 = md_wave(fract(w_sample + 0.37), ${spec ? 1 : 0}) * w_scaling * 0.25;&#10;            w_x = 0.5 + w_value1; w_y = 0.5 + w_value2;&#10;            w_r = fr; w_g = fg; w_b = fb; w_a = fa;&#10;${wp.replace(/^/gm, '    ')}&#10;            vec2 P = vec2(w_x, w_y) * md_R;&#10;            float d = ${dots ? 'length(fc - P)' : '(prev.x &lt; -1e4 ? 1e5 : md_seg(fc, prev, P))'};&#10;            float cov = clamp(${thick ? '1.6' : '0.9'} - d, 0.0, 1.0) * clamp(w_a, 0.0, 1.0);&#10;            ${addv ? 'col += vec3(w_r, w_g, w_b) * cov;' : 'col = mix(col, vec3(w_r, w_g, w_b), cov);'}&#10;            prev = P;&#10;        }&#10;    }`;&#10;    }&#10;&#10;    // ---------- custom shapes ----------&#10;    let shapesGL = '';&#10;    for (let s = 0; s &lt; 16; s++) {&#10;        if (num('shapecode_' + s + '_enabled', 0) &lt; 0.5) continue;&#10;        const inst = Math.max(1, Math.min(64, Math.round(num('shapecode_' + s + '_num_inst', 1))));&#10;        if (num('shapecode_' + s + '_num_inst', 1) &gt; 64) note('Shape ' + s + ': only the first 64 copies are drawn');&#10;        const sused = new Set();&#10;        const si = eel(lines('shape_' + s + '_init'), { name: v =&gt; 's_' + v, seed: 's_instance', seed2: '7.0', used: sused });&#10;        const sf = eel(lines('shape_' + s + '_per_frame'), { name: v =&gt; 's_' + v, seed: 's_instance', used: sused });&#10;        const own = ['x', 'y', 'rad', 'ang', 'r', 'g', 'b', 'a', 'r2', 'g2', 'b2', 'a2', 'border_r', 'border_g', 'border_b', 'border_a',&#10;                     'sides', 'additive', 'thick', 'textured', 'tex_zoom', 'tex_ang', 'instance', 'num_inst',&#10;                     't1', 't2', 't3', 't4', 't5', 't6', 't7', 't8'];&#10;        if (/\bro\s*=\s*ro\s*\+/.test(lines('shape_' + s + '_per_frame'))) note('Shape ' + s + ' counts up from frame to frame: drawn as at its start');&#10;        const K = k =&gt; glf(num('shapecode_' + s + '_' + k, 0));&#10;        shapesGL += `&#10;    for (int n = 0; n &lt; ${inst}; n++) {   // custom shape ${s}&#10;        float s_instance = float(n), s_num_inst = ${inst}.0;&#10;        float s_x = ${K('x')}, s_y = ${K('y')}, s_rad = ${K('rad')}, s_ang = ${K('ang')}, s_sides = ${K('sides')};&#10;        float s_r = ${K('r')}, s_g = ${K('g')}, s_b = ${K('b')}, s_a = ${K('a')}, s_r2 = ${K('r2')}, s_g2 = ${K('g2')}, s_b2 = ${K('b2')}, s_a2 = ${K('a2')};&#10;        float s_border_r = ${K('border_r')}, s_border_g = ${K('border_g')}, s_border_b = ${K('border_b')}, s_border_a = ${K('border_a')};&#10;        float s_additive = ${K('additive')}, s_thick = ${K('thickoutline')}, s_textured = ${K('textured')}, s_tex_zoom = ${K('tex_zoom')}, s_tex_ang = ${K('tex_ang')};&#10;        float s_t1 = 0.0, s_t2 = 0.0, s_t3 = 0.0, s_t4 = 0.0, s_t5 = 0.0, s_t6 = 0.0, s_t7 = 0.0, s_t8 = 0.0;&#10;${frameView('s_', sused, own)}&#10;${si}&#10;${sf}&#10;        col = md_shape(col, fc, vec2(s_x, s_y), s_rad, s_ang, max(3.0, floor(s_sides)), vec4(s_r, s_g, s_b, s_a), vec4(s_r2, s_g2, s_b2, s_a2),&#10;                       vec4(s_border_r, s_border_g, s_border_b, s_border_a), s_additive, s_thick, s_textured, s_tex_zoom, s_tex_ang);&#10;    }`;&#10;    }&#10;&#10;    // ---------- the warp and comp shaders (HLSL) -&gt; GLSL ----------&#10;    const SAMPLERS = { main: 0, fc_main: 0, pc_main: 1, fw_main: 0, pw_main: 1, blur1: 2, blur2: 3, blur3: 4,&#10;                       noise_lq: 10, noise_mq: 11, noise_hq: 12, noise_lite: 13, pw_noise_lq: 14, pw_noise_mq: 15, pw_noise_hq: 16, pw_noise_lite: 17,&#10;                       fc_noise_lq: 10, fw_noise_lq: 10, noisevol_lq: 20, noisevol_hq: 21, pw_noisevol_lq: 20, pw_noisevol_hq: 21 };&#10;    const SIZES = { noise_lq: 256, noise_mq: 256, noise_hq: 256, noise_lite: 32, noisevol_lq: 32, noisevol_hq: 32 };&#10;    const custom = {};   // pictures MNodes does not have: a pattern stands in&#10;    const RESERVED = new Set(('input output sample filter smooth flat half fixed long short double inline noinline active common partition ' +&#10;        'namespace using cast goto union superp lowp mediump highp precision invariant layout centroid buffer shared ' +&#10;        'coherent volatile restrict readonly writeonly resource patch subroutine sizeof template this packed interface external texture').split(' '));&#10;&#10;    // a picture's file: by its name, or &lt;name&gt;.jpg; rand00 ... rand15 (rand03_smalltiled: only files starting with smalltiled)&#10;    // are, as in MilkDrop, a picture out of the textures folder, here always the same one for the same preset&#10;    let seed = 0;&#10;    for (let i = 0; i &lt; text.length; i += 7) seed = (seed * 31 + text.charCodeAt(i)) &gt;&gt;&gt; 0;&#10;    function resolve(k) {&#10;        const r = k.match(/^rand(\d\d)(?:_(.*))?$/);&#10;        if (r) {&#10;            const all = Object.keys(files).filter(x =&gt; x !== '__guess' &amp;&amp; (!r[2] || x.startsWith(r[2].toLowerCase()))).sort();&#10;            if (!all.length) return undefined;&#10;            let h = (seed ^ (+r[1] * 2654435761)) &gt;&gt;&gt; 0; h = Math.imul(h ^ (h &gt;&gt;&gt; 15), 2246822507) &gt;&gt;&gt; 0; h = (h ^ (h &gt;&gt;&gt; 13)) &gt;&gt;&gt; 0;&#10;            return files[all[h % all.length]];&#10;        }&#10;        return k !== '__guess' &amp;&amp; files[k] || (files.__guess ? k + '.jpg' : undefined);&#10;    }&#10;    const isCustom = k =&gt; SAMPLERS[k] === undefined &amp;&amp; SAMPLERS[k.replace(/^(fw|fc|pw|pc)_/, '')] === undefined;&#10;    const key = n =&gt; { const k = n.toLowerCase(); return SAMPLERS[k] !== undefined ? k : k.replace(/^(fw|fc|pw|pc)_/, ''); };&#10;    // which pictures matter most: how often the comp shader reads them (twice as much: it is what you see), and the warp shader&#10;    const score = {};&#10;    [[lines('comp_'), 2], [lines('warp_'), 1]].forEach(([src, w]) =&gt; {&#10;        src = src.replace(/\/\/[^\n]*/g, '');&#10;        const names = new Set();   // sampler_X, and samplers declared without sampler_ (sampler MilkDrop3_001;)&#10;        (src.match(/\bsampler_\w+/g) || []).forEach(m =&gt; names.add(m.slice(8)));&#10;        (src.match(/\bsampler\s+\w+\s*[;=]/g) || []).forEach(m =&gt; names.add(m.replace(/^sampler\s+(sampler_)?|\s*[;=]$/g, '')));&#10;        names.forEach(nm =&gt; {&#10;            const k = key(nm);&#10;            if (!isCustom(k)) return;&#10;            const uses = (src.match(new RegExp('\\b(sampler_)?' + nm + '\\b', 'gi')) || []).length;&#10;            score[k] = (score[k] || 0) + w * (2 + uses);&#10;        });&#10;    });&#10;    const top = Object.keys(score).filter(k =&gt; resolve(k)).sort((a, b) =&gt; score[b] - score[a]).slice(0, 2);&#10;    function samplerCode(n) {&#10;        let k = n.toLowerCase();&#10;        if (SAMPLERS[k] !== undefined) return 'MDS_' + SAMPLERS[k];&#10;        k = k.replace(/^(fw|fc|pw|pc)_/, '');&#10;        if (SAMPLERS[k] !== undefined) return 'MDS_' + SAMPLERS[k];&#10;        if (custom[k] === undefined) {&#10;            if (Object.keys(custom).length &gt;= 8) return 'MDS_30';&#10;            custom[k] = 30 + Object.keys(custom).length;&#10;            const file = resolve(k);&#10;            // Image 1 and 2 go to the two pictures that matter most (top); a third picture gets the stand-in&#10;            const slot = file &amp;&amp; top.indexOf(k) &gt;= 0 ? pictures.filter(x =&gt; x.slot &gt;= 0).length : -1;&#10;            const guessed = !!file &amp;&amp; !files[k] &amp;&amp; !/^rand\d\d/.test(k);   // not a picture the player knows: looked for by its name&#10;            if (slot &gt;= 0 &amp;&amp; slot &lt; 2) { pictures.push({ name: n, file, slot, id: custom[k], guessed }); note('Picture &quot;' + n + '&quot;: ' + file + ' in Image ' + (slot + 1) + (guessed ? ' (if your textures folder has it)' : '')); }&#10;            else { pictures.push({ name: n, file: file || '', slot: -1, id: custom[k] }); note('Picture &quot;' + n + '&quot; ' + (file ? 'is a third picture' : 'is not in your textures') + ': ' + ['the picture itself', 'a pattern', 'grey'][standin === undefined ? 1 : standin] + ' stands in'); }&#10;        }&#10;        return 'MDS_' + custom[k];&#10;    }&#10;    function texsizeCode(n) { const k = n.toLowerCase().replace(/^(pw|pc|fw|fc)_/, '');&#10;        const pic = pictures.find(x =&gt; x.name.toLowerCase().replace(/^(pw|pc|fw|fc)_/, '') === k &amp;&amp; x.slot &gt;= 0);&#10;        if (pic) return 'md_imgsize(' + pic.slot + ')'; const z = SIZES[k] || 256; return k === 'main' ? 'texsize' : 'vec4(' + z + '.0,' + z + '.0,' + (1 / z) + ',' + (1 / z) + ')'; }&#10;    function hlsl(src, kind) {&#10;        if (!src.trim()) return null;&#10;        return mdHlsl(src, kind, { note, sampler: samplerCode, texsize: texsizeCode });&#10;    }&#10;    function splitTop(s, sep) {&#10;        const out = []; let d = 0, cur = '';&#10;        for (const ch of s) { if (ch === '(' || ch === '[') d++; if (ch === ')' || ch === ']') d--; if (ch === sep &amp;&amp; d === 0) { out.push(cur); cur = ''; } else cur += ch; }&#10;        out.push(cur);&#10;        return out;&#10;    }&#10;    function callRewrite(s, fname, fnc) {&#10;        const rx = new RegExp('\\b' + fname + '\\s*\\(', 'g');&#10;        let m, guard = 0;&#10;        while ((m = rx.exec(s)) &amp;&amp; guard++ &lt; 1000) {&#10;            let d = 0, j = m.index + m[0].length - 1;&#10;            for (; j &lt; s.length; j++) { if (s[j] === '(') d++; else if (s[j] === ')' &amp;&amp; --d === 0) break; }&#10;            const args = splitTop(s.slice(m.index + m[0].length, j), ',');&#10;            const rep = fnc(args);&#10;            s = s.slice(0, m.index) + rep + s.slice(j + 1);&#10;            rx.lastIndex = m.index + rep.length;&#10;        }&#10;        return s;&#10;    }&#10;    function glf(v) { v = +v; if (!isFinite(v)) v = 0; let s = String(Math.round(v * 1e6) / 1e6); if (!/[.e]/.test(s)) s += '.0'; return s; }&#10;&#10;    const warpGL = num('psversion_warp', 2) &gt;= 2 ? hlsl(lines('warp_'), 'warp') : null;&#10;    const compGL = num('psversion_comp', 2) &gt;= 2 ? hlsl(lines('comp_'), 'comp') : null;&#10;    if (num('wavecode_0_enabled', 0) &lt; 0.5 &amp;&amp; num('fwavealpha', 0.8) &lt; 0.01) {}&#10;&#10;    // ---------- putting it together ----------&#10;    const L = [];&#10;    L.push('// ' + name.replace(/[^\x20-\x7e]/g, '') + ': made by the MilkDrop Player Script from a pasted preset.');&#10;    L.push(MD_SHARED.replace('@NT@', NT).replace('@SI@', String(standin === undefined ? 1 : standin)).replace('@P1@', String((pictures.find(x =&gt; x.slot === 0) || { id: -1 }).id)).replace('@P2@', String((pictures.find(x =&gt; x.slot === 1) || { id: -1 }).id)));&#10;    // the frame's view for every pass: q1..q32 and the sound as globals the shaders use by name&#10;    const qdecl = Q.map(q =&gt; 'float ' + q + ';').join(' ');&#10;    L.push(qdecl);&#10;    L.push('void md_load() {\n    for (int i = 0; i &lt; ' + NT + '; i++) md_S[i] = readB(ivec2(i, 0));\n' +&#10;        Q.map(q =&gt; '    ' + q + ' = ' + sget(slotOf(q)) + ';').join('\n') + '\n' +&#10;        ['bass', 'mid', 'treb', 'bass_att', 'mid_att', 'treb_att', 'vol', 'vol_att'].map(a =&gt; '    ' + a + ' = ' + sget(slotOf(a)) + ';').join('\n') + '\n' +&#10;        '    md_common();\n}');&#10;    L.push('float md_fv(int k) { return md_S[k &gt;&gt; 2][k &amp; 3]; }');&#10;&#10;    // pass A: the warp of the last frame, then the shapes, the waves and the borders&#10;    L.push('#pass A');&#10;    if (warpGL) L.push(warpGL);&#10;    L.push(`void mainImage(out vec4 o, in vec2 fc)&#10;{&#10;    md_load();&#10;    vec2 uvGL = fc / md_R;&#10;    vec2 md_uvo = vec2(uvGL.x, 1.0 - uvGL.y);&#10;    float p_x = md_uvo.x, p_y = md_uvo.y;&#10;    vec2 cc = (md_uvo - 0.5) * 2.0 * vec2(1.0, md_R.y / md_R.x);&#10;    float p_rad = length(cc) * 0.7071, p_ang = atan(cc.y, cc.x);&#10;${PIXVARS.map(v =&gt; '    float p_' + v + ' = ' + sget(slotOf(v)) + ';').join('\n')}&#10;${frameView('p_', pused, PIXVARS.concat(['x', 'y', 'rad', 'ang']))}&#10;${glPixel}&#10;    vec2 uv = md_motion(md_uvo, p_x, p_y, p_rad, p_zoom, p_zoomexp, p_rot, p_warp, p_cx, p_cy, p_dx, p_dy, p_sx, p_sy, md_fv(${slotOf('warpanimspeed')}), md_fv(${slotOf('warpscale')}));&#10;    uv = md_uvo + (uv - md_uvo) * md_spd();   // Speed (P3): the motion of one frame, more or less of it&#10;    vec3 col;&#10;${warpGL ? '    col = md_warpShader(uv, md_uvo, p_rad, p_ang);' : '    col = md_tex2D(MDS_0, uv).rgb * pow(max(md_fv(' + slotOf('decay') + '), 0.0), md_spd());'}&#10;${shapesGL}&#10;${wavesGL}&#10;    col = md_mainWave(col, fc, md_fv(${slotOf('wave_mode')}), vec4(md_fv(${slotOf('wave_r')}), md_fv(${slotOf('wave_g')}), md_fv(${slotOf('wave_b')}), md_fv(${slotOf('wave_a')})),&#10;                      vec2(md_fv(${slotOf('wave_x')}), md_fv(${slotOf('wave_y')})), md_fv(${slotOf('wave_scale')}), md_fv(${slotOf('wave_additive')}), md_fv(${slotOf('wave_brighten')}), md_fv(${slotOf('wave_thick')}), md_fv(${slotOf('wave_mystery')}));&#10;    col = md_borders(col, md_uvo, md_fv(${slotOf('ob_size')}), vec4(md_fv(${slotOf('ob_r')}), md_fv(${slotOf('ob_g')}), md_fv(${slotOf('ob_b')}), md_fv(${slotOf('ob_a')})),&#10;                     md_fv(${slotOf('ib_size')}), vec4(md_fv(${slotOf('ib_r')}), md_fv(${slotOf('ib_g')}), md_fv(${slotOf('ib_b')}), md_fv(${slotOf('ib_a')})));&#10;    o = vec4(clamp(col, 0.0, 1.0), 1.0);   // MilkDrop's picture is 8 bits: nothing above white&#10;}`);&#10;&#10;    // pass B: the blur of A, and in the bottom row the frame's variables&#10;    const loadF = all.map((v, k) =&gt; (v.startsWith('qi_') || v.startsWith('md_')) ? '    float ' + v + ' = ' + sget(k) + ';' : '    f_' + v + ' = ' + sget(k) + ';').join('\n');&#10;    L.push('#pass B');&#10;    L.push('float ' + slots.map(v =&gt; 'f_' + v).join(', ') + ';');&#10;    L.push(`void mainImage(out vec4 o, in vec2 fc)&#10;{&#10;    md_common();&#10;    ivec2 t = texelAt(fc);&#10;    if (t.y != 0) { o = vec4(md_blurOf(fc), 1.0); return; }&#10;    if (t.x &gt;= ${NT}) { o = vec4(0.0); return; }&#10;    for (int i = 0; i &lt; ${NT}; i++) md_S[i] = readB(ivec2(i, 0));&#10;${loadF}&#10;    bool first = abs(md_id - P1) &gt; 0.0001 || iFrame &lt; 2;&#10;    // the sound: bass, mids and highs, each against its own long average (about 1 when the music is steady)&#10;    vec3 lv = md_levels();&#10;    if (first) { md_bl = max(lv.x, 0.01); md_ml = max(lv.y, 0.01); md_tl = max(lv.z, 0.01); md_bs = lv.x; md_ms = lv.y; md_ts = lv.z; }&#10;    float dt = clamp(iTimeDelta, 0.001, 0.1);&#10;    md_bl = mix(md_bl, max(lv.x, 0.001), clamp(dt / 6.0, 0.0, 1.0));&#10;    md_ml = mix(md_ml, max(lv.y, 0.001), clamp(dt / 6.0, 0.0, 1.0));&#10;    md_tl = mix(md_tl, max(lv.z, 0.001), clamp(dt / 6.0, 0.0, 1.0));&#10;    md_bs = mix(md_bs, lv.x, clamp(dt / 0.25, 0.0, 1.0));&#10;    md_ms = mix(md_ms, lv.y, clamp(dt / 0.25, 0.0, 1.0));&#10;    md_ts = mix(md_ts, lv.z, clamp(dt / 0.25, 0.0, 1.0));&#10;    if (md_bl + md_ml + md_tl &lt; 0.004) {   // silence: a steady made-up beat, so the preset still moves&#10;        float bt = fract(iTime * 2.0), env = exp(-bt * 7.0);&#10;        f_bass = 0.7 + 0.9 * env; f_mid = 0.85 + 0.4 * exp(-fract(iTime * 4.0) * 5.0); f_treb = 0.9 + 0.3 * md_hash(vec2(iTime, 3.0));&#10;        f_bass_att = 1.0; f_mid_att = 1.0; f_treb_att = 1.0;&#10;    } else {&#10;        f_bass = lv.x / md_bl; f_mid = lv.y / md_ml; f_treb = lv.z / md_tl;&#10;        f_bass_att = md_bs / md_bl; f_mid_att = md_ms / md_ml; f_treb_att = md_ts / md_tl;&#10;    }&#10;    // Sensitivity (P2, 0.5 as MilkDrop): how far the sound goes from its steady 1&#10;    float md_g = md_sens();&#10;    f_bass = max(1.0 + (f_bass - 1.0) * md_g, 0.0); f_mid = max(1.0 + (f_mid - 1.0) * md_g, 0.0); f_treb = max(1.0 + (f_treb - 1.0) * md_g, 0.0);&#10;    f_bass_att = max(1.0 + (f_bass_att - 1.0) * md_g, 0.0); f_mid_att = max(1.0 + (f_mid_att - 1.0) * md_g, 0.0); f_treb_att = max(1.0 + (f_treb_att - 1.0) * md_g, 0.0);&#10;    f_vol = (f_bass + f_mid + f_treb) / 3.0; f_vol_att = (f_bass_att + f_mid_att + f_treb_att) / 3.0;&#10;    f_time = iTime; f_fps = 1.0 / dt; f_frame = float(iFrame); f_progress = fract(iTime / 60.0);&#10;    f_meshx = 48.0; f_meshy = 36.0; f_pixelsx = md_R.x; f_pixelsy = md_R.y; f_aspectx = md_R.y / md_R.x; f_aspecty = 1.0;&#10;    if (first) {&#10;${userVars.map(v =&gt; '        f_' + v + ' = 0.0;').join('\n')}&#10;${Q.map(q =&gt; '        f_' + q + ' = 0.0;').join('\n')}&#10;${base.replace(/^/gm, '    ')}&#10;${glInit.replace(/^/gm, '    ')}&#10;${Q.map(q =&gt; '        qi_' + q + ' = f_' + q + ';').join('\n')}&#10;    }&#10;${base}&#10;${Q.map(q =&gt; '    f_' + q + ' = qi_' + q + ';').join('\n')}&#10;${glFrame}&#10;    md_id = P1;&#10;    float v[4];&#10;${[0, 1, 2, 3].map(c =&gt; '    v[' + c + '] = 0.0;').join('\n')}&#10;${all.map((vn, k) =&gt; '    if (t.x == ' + (k &gt;&gt; 2) + ') v[' + (k &amp; 3) + '] = ' + (vn.startsWith('qi_') || vn.startsWith('md_') ? vn : 'f_' + vn) + ';').join('\n')}&#10;    o = vec4(v[0], v[1], v[2], v[3]);&#10;}`);&#10;&#10;    // the picture: the comp shader, or MilkDrop's own (echo, gamma, brighten, darken, solarize, invert)&#10;    L.push('#pass Image');&#10;    if (compGL) L.push(compGL);&#10;    L.push(`void mainImage(out vec4 o, in vec2 fc)&#10;{&#10;    md_load();&#10;    vec2 uvGL = fc / md_R;&#10;    vec2 uv = vec2(uvGL.x, 1.0 - uvGL.y);&#10;    vec2 cc = (uv - 0.5) * 2.0 * vec2(1.0, md_R.y / md_R.x);&#10;    vec3 col;&#10;${compGL ? '    col = md_compShader(uv, uv, length(cc) * 0.7071, atan(cc.y, cc.x), md_hue(uv));' :&#10;    `    col = md_defaultComp(uv, md_fv(${slotOf('echo_zoom')}), md_fv(${slotOf('echo_alpha')}), md_fv(${slotOf('echo_orient')}), md_fv(${slotOf('gamma')}),&#10;                         md_fv(${slotOf('brighten')}), md_fv(${slotOf('darken')}), md_fv(${slotOf('solarize')}), md_fv(${slotOf('invert')}));`}&#10;    o = vec4(clamp(col * md_gain(), 0.0, 1.0), 1.0);   // Brightness (P4)&#10;}`);&#10;    const glsl = L.join('\n\n');&#10;    // the check made on loading: how well this preset can play here (MNodes cannot see the picture, so a preset that stays black is not found here)&#10;    const N = notes.join('\n'), why = [];&#10;    let level = 0;&#10;    if (closed) { level = 3; why.push('its shader is closed MilkDrop3 code that is not in the file'); }&#10;    if (/megabuf\/loop/.test(N)) { level = Math.max(level, 2); why.push('it uses megabuf or loop memory, which reads 0 here'); }&#10;    if (/could not be read|no shader_body/.test(N)) { level = Math.max(level, 2); why.push('a shader could not be read and is left out'); }&#10;    if (/Unknown function|Unknown name/.test(N)) { level = Math.max(level, 1); why.push('some names in the code are unknown and read 0'); }&#10;    if (/not in your textures|third picture/.test(N)) { level = Math.max(level, 1); why.push('a picture gets a stand-in'); }&#10;    if (/counts up from frame|only the first 64/.test(N)) { level = Math.max(level, 1); why.push('shapes are simplified'); }&#10;    if (double) { level = Math.max(level, 1); why.push('double preset: one half at a time, no blend'); }&#10;    const check = { level, label: ['Supported', 'Plays, adjusted', 'Plays only in part', 'Works only in MilkDrop3'][level], why };&#10;    return { glsl, name, notes, double, presets: blocks.length || 1, pictures, closed, check };&#10;}&#10;&#10;const MD_SHARED = `&#10;#define MD_STANDIN @SI@&#10;#define MD_PIC1 @P1@&#10;#define MD_PIC2 @P2@&#10;// the player's settings, 0 to 1 with 0.5 as in MilkDrop: P2 Sensitivity, P3 Speed, P4 Brightness&#10;float md_sens() { return pow(3.0, clamp(P2, 0.0, 1.0) * 2.0 - 1.0); }&#10;float md_spd() { float s = clamp(P3, 0.0, 1.0); return s &lt; 0.5 ? s * 2.0 : 1.0 + (s - 0.5) * 6.0; }&#10;float md_gain() { float b = clamp(P4, 0.0, 1.0); return b &lt; 0.5 ? b * 2.0 : 1.0 + (b - 0.5) * 4.0; }&#10;vec4 md_imgsize(int k) { vec2 z = vec2(k == 0 ? textureSize(iImage0, 0) : textureSize(iImage1, 0)); return vec4(z, 1.0 / max(z, vec2(1.0))); }&#10;vec4 md_S[@NT@];&#10;vec2 md_R;&#10;float md_frame, time, fps, frame, progress, bass, mid, treb, bass_att, mid_att, treb_att, vol, vol_att;&#10;vec4 texsize, aspect, rand_frame, rand_preset, roam_cos, roam_sin, slow_roam_cos, slow_roam_sin;&#10;vec4 _qa, _qb, _qc, _qd, _qe, _qf, _qg, _qh;&#10;float blur1_min = 0.0, blur1_max = 1.0, blur2_min = 0.0, blur2_max = 1.0, blur3_min = 0.0, blur3_max = 1.0;&#10;const int MDS_0 = 0, MDS_1 = 1, MDS_2 = 2, MDS_3 = 3, MDS_4 = 4, MDS_10 = 10, MDS_11 = 11, MDS_12 = 12, MDS_13 = 13, MDS_14 = 14,&#10;          MDS_15 = 15, MDS_16 = 16, MDS_17 = 17, MDS_20 = 20, MDS_21 = 21, MDS_30 = 30, MDS_31 = 31, MDS_32 = 32, MDS_33 = 33,&#10;          MDS_34 = 34, MDS_35 = 35, MDS_36 = 36, MDS_37 = 37;&#10;&#10;// no mip levels and no derivatives: the same in loops on every graphics card (D3D refuses gradients in loops)&#10;vec4 md_tA(vec2 u) { return textureLod(iBufferA, u, 0.0); }&#10;vec4 md_tB(vec2 u) { return textureLod(iBufferB, u, 0.0); }&#10;vec4 md_tC(vec2 u) { return textureLod(iChannel0, u, 0.0); }&#10;float md_hash(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }&#10;vec4 md_hash4(vec3 p) {&#10;    vec4 p4 = fract(vec4(p.xyzx) * vec4(0.1031, 0.1030, 0.0973, 0.1099));&#10;    p4 += dot(p4, p4.wzxy + 33.33);&#10;    return fract((p4.xxyz + p4.yzzw) * p4.zywx);&#10;}&#10;float md_pow(float a, float b) { if (a &gt;= 0.0) return pow(a, b); return fract(b) == 0.0 ? (mod(b, 2.0) == 0.0 ? pow(-a, b) : -pow(-a, b)) : 0.0; }&#10;vec2 md_pow(vec2 a, vec2 b) { return pow(abs(a), b); }&#10;vec3 md_pow(vec3 a, vec3 b) { return pow(abs(a), b); }&#10;vec4 md_pow(vec4 a, vec4 b) { return pow(abs(a), b); }&#10;vec2 md_pow(vec2 a, float b) { return pow(abs(a), vec2(b)); }&#10;vec3 md_pow(vec3 a, float b) { return pow(abs(a), vec3(b)); }&#10;vec4 md_pow(vec4 a, float b) { return pow(abs(a), vec4(b)); }&#10;float md_div(float a, float b) { return b == 0.0 ? 0.0 : a / b; }&#10;float md_imod(float a, float b) { float bb = trunc(b); return bb == 0.0 ? 0.0 : trunc(a) - bb * trunc(trunc(a) / bb); }&#10;float md_mod(float a, float b) { return b == 0.0 ? 0.0 : a - b * trunc(a / b); }&#10;float md_fmod(float a, float b) { return md_mod(a, b); }&#10;vec2 md_fmod(vec2 a, vec2 b) { return a - b * trunc(a / b); }&#10;vec3 md_fmod(vec3 a, vec3 b) { return a - b * trunc(a / b); }&#10;vec2 md_fmod(vec2 a, float b) { return a - b * trunc(a / b); }&#10;vec3 md_fmod(vec3 a, float b) { return a - b * trunc(a / b); }&#10;vec4 md_fmod(vec4 a, vec4 b) { return a - b * trunc(a / b); }&#10;float md_ldexp(float a, float b) { return a * exp2(b); }&#10;vec2 md_ldexp(vec2 a, vec2 b) { return a * exp2(b); }&#10;vec3 md_ldexp(vec3 a, vec3 b) { return a * exp2(b); }&#10;vec4 md_ldexp(vec4 a, vec4 b) { return a * exp2(b); }&#10;float md_int(float a) { return trunc(a); }&#10;vec2 md_int(vec2 a) { return trunc(a); }&#10;vec3 md_int(vec3 a) { return trunc(a); }&#10;float md_sat(float a) { return clamp(a, 0.0, 1.0); }&#10;vec2 md_sat(vec2 a) { return clamp(a, 0.0, 1.0); }&#10;vec3 md_sat(vec3 a) { return clamp(a, 0.0, 1.0); }&#10;vec4 md_sat(vec4 a) { return clamp(a, 0.0, 1.0); }&#10;float md_log10(float a) { return log(max(a, 1e-30)) / 2.302585; }&#10;vec3 md_log10(vec3 a) { return log(max(a, vec3(1e-30))) / 2.302585; }&#10;void md_clip(float a) {}&#10;void md_clip(vec3 a) {}&#10;float md_or(float a, float b) { return float(a != 0.0 || b != 0.0); }&#10;float md_and(float a, float b) { return float(a != 0.0 &amp;&amp; b != 0.0); }&#10;float md_cfloat(float a) { return a; }&#10;float md_cfloat(vec2 a) { return a.x; }&#10;float md_cfloat(vec3 a) { return a.x; }&#10;float md_cfloat(vec4 a) { return a.x; }&#10;float md_cfloat(bool a) { return float(a); }&#10;vec2 md_cvec2(float a) { return vec2(a); }&#10;vec2 md_cvec2(vec2 a) { return a; }&#10;vec2 md_cvec2(vec3 a) { return a.xy; }&#10;vec2 md_cvec2(vec4 a) { return a.xy; }&#10;vec3 md_cvec3(float a) { return vec3(a); }&#10;vec3 md_cvec3(vec2 a) { return vec3(a, 0.0); }&#10;vec3 md_cvec3(vec3 a) { return a; }&#10;vec3 md_cvec3(vec4 a) { return a.xyz; }&#10;vec4 md_cvec4(float a) { return vec4(a); }&#10;vec4 md_cvec4(vec2 a) { return vec4(a, 0.0, 0.0); }&#10;vec4 md_cvec4(vec3 a) { return vec4(a, 0.0); }&#10;vec4 md_cvec4(vec4 a) { return a; }&#10;float md_lum(vec3 c) { return dot(c, vec3(0.32, 0.49, 0.29)); }&#10;float md_lum(float c) { return c; }&#10;&#10;// the pictures a preset reads: Buffer A (the picture), Buffer B (its blur), noise made here, and a pattern for unknown ones&#10;vec3 md_blur1(vec2 uv); vec3 md_blur2(vec2 uv); vec3 md_blur3(vec2 uv);&#10;vec2 md_R0() { return iResolution.xy; }&#10;vec2 md_bclamp(vec2 g) { return vec2(g.x, max(g.y, 1.5 / md_R.y)); }   // Buffer B's bottom row is the state, not picture&#10;vec4 md_noise2(vec2 uv, float size, bool point, float seed) {&#10;    vec2 p = uv * size;&#10;    if (point) return md_hash4(vec3(mod(floor(p), size), seed));&#10;    vec2 i = floor(p), f = fract(p);&#10;    f = f * f * (3.0 - 2.0 * f);&#10;    vec4 a = md_hash4(vec3(mod(i, size), seed)), b = md_hash4(vec3(mod(i + vec2(1.0, 0.0), size), seed));&#10;    vec4 c = md_hash4(vec3(mod(i + vec2(0.0, 1.0), size), seed)), d = md_hash4(vec3(mod(i + 1.0, size), seed));&#10;    return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);&#10;}&#10;vec4 md_noise3(vec3 uvw, float size) {&#10;    vec3 p = uvw * size, i = floor(p), f = fract(p);&#10;    f = f * f * (3.0 - 2.0 * f);&#10;    vec4 r = vec4(0.0);&#10;    for (int k = 0; k &lt; 8; k++) {&#10;        vec3 o = vec3(float(k &amp; 1), float((k &gt;&gt; 1) &amp; 1), float((k &gt;&gt; 2) &amp; 1));&#10;        vec3 w = mix(1.0 - f, f, o);&#10;        r += md_hash4(mod(i + o, size) + 17.0) * w.x * w.y * w.z;&#10;    }&#10;    return r;&#10;}&#10;vec4 md_pattern(vec2 uv, float id) {   // what stands in for a picture MNodes does not have&#10;    vec4 n = md_noise2(uv, 8.0, false, id) * 0.5 + md_noise2(uv, 32.0, false, id + 1.0) * 0.3 + md_noise2(uv, 128.0, false, id + 2.0) * 0.2;&#10;    float l = dot(n.rgb, vec3(0.333));&#10;    return vec4(mix(vec3(l), n.rgb, 0.45), 1.0);   // soft colours, as most MilkDrop pictures are&#10;}&#10;vec4 md_tex2D(int s, vec2 uv) {&#10;    if (s == 0) return md_tA( fract(vec2(uv.x, 1.0 - uv.y)));&#10;    if (s == 1) { vec2 g = fract(vec2(uv.x, 1.0 - uv.y)); return md_tA( (floor(g * md_R) + 0.5) / md_R); }&#10;    if (s &gt;= 2 &amp;&amp; s &lt;= 4) return vec4(s == 2 ? md_blur1(uv) : s == 3 ? md_blur2(uv) : md_blur3(uv), 1.0);&#10;    if (s &gt;= 10 &amp;&amp; s &lt;= 17) { float z = (s == 13 || s == 17) ? 32.0 : 256.0; return md_noise2(fract(uv), z, s &gt;= 14, float(s - (s &gt;= 14 ? 4 : 0))); }&#10;    if (s == 20 || s == 21) return md_noise3(vec3(fract(uv), 0.0), 32.0);&#10;    // a picture MNodes does not have: MD_STANDIN 0 the picture itself, 1 a soft pattern, 2 grey&#10;    if (s == MD_PIC1) return textureLod(iImage0, fract(vec2(uv.x, 1.0 - uv.y)), 0.0);&#10;    if (s == MD_PIC2) return textureLod(iImage1, fract(vec2(uv.x, 1.0 - uv.y)), 0.0);&#10;    if (MD_STANDIN == 0) return md_tA( fract(vec2(uv.x, 1.0 - uv.y)));&#10;    if (MD_STANDIN == 2) return vec4(0.5);&#10;    return md_pattern(uv, float(s));&#10;}&#10;vec4 md_tex2D(int s, float u) { return md_tex2D(s, vec2(u)); }&#10;vec4 md_tex2D(int s, vec3 u) { return md_tex2D(s, u.xy); }&#10;vec4 md_tex2D(int s, vec4 u) { return md_tex2D(s, u.xy); }&#10;vec4 md_tex2Dlod(int s, vec4 u) { return md_tex2D(s, u.xy); }&#10;vec4 md_tex3D(int s, vec3 uvw) { return s == 20 || s == 21 ? md_noise3(uvw, 32.0) : md_tex2D(s, uvw.xy); }&#10;vec3 md_pixel(vec2 uv) { return md_tex2D(0, uv).rgb; }&#10;vec3 md_blur1(vec2 uv) { return md_tB( md_bclamp(clamp(vec2(uv.x, 1.0 - uv.y), 0.0, 1.0))).rgb; }&#10;vec3 md_blur2(vec2 uv) {&#10;    vec2 g = vec2(uv.x, 1.0 - uv.y), d = 4.0 / md_R;&#10;    vec3 c = vec3(0.0);&#10;    c += md_tB( md_bclamp(clamp(g + vec2(d.x, d.y), 0.0, 1.0))).rgb;&#10;    c += md_tB( md_bclamp(clamp(g + vec2(-d.x, d.y), 0.0, 1.0))).rgb;&#10;    c += md_tB( md_bclamp(clamp(g + vec2(d.x, -d.y), 0.0, 1.0))).rgb;&#10;    c += md_tB( md_bclamp(clamp(g + vec2(-d.x, -d.y), 0.0, 1.0))).rgb;&#10;    return c * 0.25;&#10;}&#10;vec3 md_blur3(vec2 uv) {&#10;    vec2 g = vec2(uv.x, 1.0 - uv.y), d = 9.0 / md_R;&#10;    vec3 c = vec3(0.0);&#10;    for (int k = 0; k &lt; 8; k++) {&#10;        float a = float(k) * 0.7854;&#10;        c += md_tB( md_bclamp(clamp(g + vec2(cos(a), sin(a)) * d, 0.0, 1.0))).rgb;&#10;    }&#10;    return c * 0.125;&#10;}&#10;vec3 md_blurOf(vec2 fc) {   // Buffer B: Buffer A softened over a few pixels (MilkDrop's blur1)&#10;    vec2 g = fc / md_R0(), d = 1.6 / md_R0();&#10;    vec3 c = md_tA( g).rgb * 0.2;&#10;    c += (md_tA( g + vec2(d.x, 0.0)).rgb + md_tA( g - vec2(d.x, 0.0)).rgb +&#10;          md_tA( g + vec2(0.0, d.y)).rgb + md_tA( g - vec2(0.0, d.y)).rgb) * 0.12;&#10;    c += (md_tA( g + d * 1.7).rgb + md_tA( g - d * 1.7).rgb +&#10;          md_tA( g + vec2(d.x, -d.y) * 1.7).rgb + md_tA( g + vec2(-d.x, d.y) * 1.7).rgb) * 0.08;&#10;    return c;&#10;}&#10;&#10;// MilkDrop3's get_fft(pos): the spectrum at pos (0 low .. 1 high)&#10;float md_fft(float pos) { return md_tC(vec2(clamp(pos, 0.0, 1.0) * 0.7 + 0.001, 0.25)).x; }&#10;// rot_s1 .. rot_rand4: rotations (and a small move in the 4th row) that differ per preset; speed 0 still, 5 new every frame&#10;mat4x3 md_rot(float k, int speed) {&#10;    float sp = speed == 0 ? 0.0 : speed == 1 ? 0.02 : speed == 2 ? 0.1 : speed == 3 ? 0.4 : speed == 4 ? 1.2 : 0.0;&#10;    vec4 r = md_hash4(vec3(k, P1 * 977.0, speed == 5 ? float(iFrame) : 0.0));&#10;    vec3 a = (r.xyz * 6.28318) + iTime * sp * (0.5 + r.yzx);&#10;    vec3 c = cos(a), s = sin(a);&#10;    mat3 rx = mat3(1.0, 0.0, 0.0, 0.0, c.x, s.x, 0.0, -s.x, c.x), ry = mat3(c.y, 0.0, -s.y, 0.0, 1.0, 0.0, s.y, 0.0, c.y), rz = mat3(c.z, s.z, 0.0, -s.z, c.z, 0.0, 0.0, 0.0, 1.0);&#10;    mat3 m = rz * ry * rx;&#10;    return mat4x3(m[0], m[1], m[2], (md_hash4(vec3(k, 5.0, 1.0)).xyz - 0.5) * 0.5);&#10;}&#10;&#10;// the sound on In A: bass, mids and highs from the spectrum&#10;vec3 md_levels() {&#10;    vec3 l = vec3(0.0);&#10;    for (int i = 0; i &lt; 6; i++) l.x += md_tC( vec2(0.002 + float(i) * 0.004, 0.25)).x;&#10;    for (int i = 0; i &lt; 8; i++) l.y += md_tC( vec2(0.03 + float(i) * 0.015, 0.25)).x;&#10;    for (int i = 0; i &lt; 8; i++) l.z += md_tC( vec2(0.16 + float(i) * 0.04, 0.25)).x;&#10;    return l / vec3(6.0, 8.0, 8.0);&#10;}&#10;float md_wave(float s, int spectrum) {&#10;    if (spectrum == 1) return md_tC( vec2(s * 0.5, 0.25)).x;&#10;    float w = md_tC( vec2(s, 0.75)).x;&#10;    if (bass + mid + treb &lt; 0.0001) return 0.0;&#10;    return w - 0.5;&#10;}&#10;&#10;void md_common() {&#10;    md_R = iResolution.xy;&#10;    md_frame = float(iFrame);&#10;    time = iTime; fps = 1.0 / clamp(iTimeDelta, 0.001, 0.1); frame = float(iFrame); progress = fract(iTime / 60.0);&#10;    texsize = vec4(md_R, 1.0 / md_R);&#10;    aspect = md_R.x &gt; md_R.y ? vec4(md_R.y / md_R.x, 1.0, md_R.x / md_R.y, 1.0) : vec4(1.0, md_R.x / md_R.y, 1.0, md_R.y / md_R.x);&#10;    rand_frame = md_hash4(vec3(float(iFrame), 1.0, 2.0));&#10;    rand_preset = md_hash4(vec3(P1 * 1000.0, 3.0, 4.0));&#10;    roam_cos = 0.5 + 0.5 * cos(iTime * vec4(1.0, 1.3, 1.7, 2.3));&#10;    roam_sin = 0.5 + 0.5 * sin(iTime * vec4(1.0, 1.3, 1.7, 2.3));&#10;    slow_roam_cos = 0.5 + 0.5 * cos(iTime * vec4(0.005, 0.008, 0.013, 0.022) * 20.0);&#10;    slow_roam_sin = 0.5 + 0.5 * sin(iTime * vec4(0.005, 0.008, 0.013, 0.022) * 20.0);&#10;}&#10;&#10;// MilkDrop's movement of the picture: zoom, rotate, stretch, warp, move&#10;vec2 md_motion(vec2 uvo, float x, float y, float rad, float zoom, float zoomexp, float rot, float warp, float cx, float cy,&#10;               float dx, float dy, float sx, float sy, float wspeed, float wscale) {&#10;    vec2 asp = vec2(md_R.y / md_R.x, 1.0);   // the picture is wider than tall&#10;    vec2 p = (vec2(x, y) - 0.5) * 2.0;&#10;    float z2 = pow(max(zoom, 1e-4), pow(max(zoomexp, 1e-4), rad * 2.0 - 1.0));&#10;    vec2 u = p * 0.5 / z2 + 0.5;&#10;    u = (u - vec2(cx, cy)) / vec2(sx, sy) + vec2(cx, cy);&#10;    float wt = iTime * wspeed, ws = 1.0 / max(wscale, 0.001);&#10;    vec4 f = vec4(11.68 + 4.0 * cos(wt * 1.413 + 10.0), 8.77 + 3.0 * cos(wt * 1.113 + 7.0), 10.54 + 3.0 * cos(wt * 1.233 + 3.0), 11.49 + 4.0 * cos(wt * 0.933 + 5.0));&#10;    u.x += warp * 0.0035 * sin(wt * 0.333 + ws * (p.x * f.x - p.y * f.w));&#10;    u.y += warp * 0.0035 * cos(wt * 0.375 - ws * (p.x * f.z + p.y * f.y));&#10;    u.x += warp * 0.0035 * cos(wt * 0.753 - ws * (p.x * f.y - p.y * f.z));&#10;    u.y += warp * 0.0035 * sin(wt * 0.825 + ws * (p.x * f.x + p.y * f.w));&#10;    vec2 r = u - vec2(cx, cy);&#10;    r.x /= asp.x;&#10;    float c = cos(rot), s = sin(rot);&#10;    r = vec2(r.x * c - r.y * s, r.x * s + r.y * c);&#10;    r.x *= asp.x;&#10;    u = r + vec2(cx, cy);&#10;    u -= vec2(dx, dy);&#10;    return u;&#10;}&#10;&#10;float md_seg(vec2 p, vec2 a, vec2 b) { vec2 pa = p - a, ba = b - a; return length(pa - ba * clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0)); }&#10;&#10;// a custom shape: a polygon with a colour in the middle, another at the edge, and a border&#10;vec3 md_shape(vec3 col, vec2 fc, vec2 c, float rad, float ang, float sides, vec4 c1, vec4 c2, vec4 bc, float additive, float thick,&#10;              float textured, float tzoom, float tang) {&#10;    vec2 P = c * md_R;&#10;    vec2 q = fc - P;&#10;    float R = rad * md_R.y * 1.41;&#10;    float a = atan(q.y, q.x) - ang;&#10;    float seg = 6.28318 / sides;&#10;    float k = cos(seg * 0.5) / cos(mod(a, seg) - seg * 0.5);&#10;    float edge = R * k;&#10;    float d = length(q);&#10;    if (d &gt; edge + 3.0) return col;&#10;    float t = clamp(d / max(edge, 1e-3), 0.0, 1.0);&#10;    vec4 fill = mix(c1, c2, t);&#10;    float inside = clamp(edge - d + 0.5, 0.0, 1.0);&#10;    if (textured &gt; 0.5) {&#10;        vec2 tq = q / max(R, 1.0) * 0.5 / max(tzoom, 0.01);&#10;        float cs = cos(tang), sn = sin(tang);&#10;        tq = vec2(tq.x * cs - tq.y * sn, tq.x * sn + tq.y * cs);&#10;        vec3 tc = md_tex2D(0, vec2(0.5 + tq.x * md_R.y / md_R.x, 0.5 - tq.y)).rgb;&#10;        fill.rgb *= tc;&#10;    }&#10;    if (additive &gt; 0.5) col += fill.rgb * fill.a * inside;&#10;    else col = mix(col, fill.rgb, fill.a * inside);&#10;    float b = clamp((thick &gt; 0.5 ? 2.5 : 1.2) - abs(d - edge), 0.0, 1.0) * bc.a;&#10;    col = mix(col, bc.rgb, b);&#10;    return col;&#10;}&#10;&#10;// MilkDrop's own wave (nWaveMode, taken modulo 8 as MilkDrop does): 0/1 a ring, 2/3/5 dots of left against right,&#10;// 4 a line across, 6 a line at an angle, 7 two lines; drawn per pixel, so the shapes are close to MilkDrop's, not the same&#10;vec3 md_mainWave(vec3 col, vec2 fc, float mode, vec4 wc, vec2 wpos, float scale, float additive, float brighten, float thick, float param) {&#10;    if (wc.a &lt; 0.01) return col;&#10;    int m = int(mod(floor(mode + 0.5), 8.0));&#10;    vec2 P = vec2(wpos.x, wpos.y) * md_R;&#10;    float px = md_R.y * 0.5;   // MilkDrop's -1..1 is the height&#10;    float d = 1e9;&#10;    float a = clamp(wc.a, 0.0, 1.0);&#10;    float pr = param;&#10;    if ((m &lt;= 1 || m == 4) &amp;&amp; (pr &lt; -1.0 || pr &gt; 1.0)) { pr = pr * 0.5 + 0.5; pr = abs(pr - floor(pr)) * 2.0 - 1.0; }&#10;    if (m &lt;= 1) {&#10;        vec2 q = fc - P;&#10;        float s = fract((atan(q.y, q.x) - iTime * 0.2) / 6.28318);&#10;        float r = (m == 0 ? 0.5 + 0.4 * md_wave(s, 0) * 2.0 * scale : 0.53 + 0.43 * md_wave(s, 0) * 2.0 * scale) + pr;&#10;        d = abs(length(q) - r * px);&#10;        if (m == 1) a *= 1.25;&#10;    } else if (m == 2 || m == 3 || m == 5) {&#10;        float cr = cos(iTime * 0.3), sr = sin(iTime * 0.3);&#10;        for (int i = 0; i &lt; 48; i++) {&#10;            float s = float(i) / 48.0;&#10;            float l = md_wave(s, 0) * 2.0 * scale, r = md_wave(fract(s + 0.0625), 0) * 2.0 * scale;&#10;            vec2 v = vec2(r, l);&#10;            if (m == 5) { vec2 v0 = vec2(r * l + l * r, r * r - l * l); v = vec2(v0.x * cr - v0.y * sr, v0.x * sr + v0.y * cr); }&#10;            d = min(d, length(fc - (P + v * px)) * 0.6);&#10;        }&#10;        a *= m == 3 ? 0.4 * clamp(treb * treb, 0.0, 4.0) : 0.4;&#10;    } else if (m == 4) {&#10;        float s = clamp(fc.x / md_R.x, 0.0, 1.0);&#10;        d = abs(fc.y - (P.y + md_wave(s, 0) * 2.0 * scale * 0.47 * px));&#10;    } else {&#10;        float ang = 1.57 * pr;&#10;        vec2 dir = vec2(cos(ang), sin(ang)), nrm = vec2(-dir.y, dir.x);&#10;        vec2 c0 = md_R * 0.5 + nrm * (wpos.x * 2.0 - 1.0) * px;&#10;        vec2 q = fc - c0;&#10;        float t = dot(q, dir), off = dot(q, nrm);&#10;        float s = clamp(t / md_R.x + 0.5, 0.0, 1.0);&#10;        float w = md_wave(s, 0) * 2.0 * scale * 0.25 * px;&#10;        if (m == 6) d = abs(off - w);&#10;        else {&#10;            float sep = pow(wpos.y * 0.5 + 0.5, 2.0) * px;&#10;            d = min(abs(off - (w + sep)), abs(off - (md_wave(fract(s + 0.3), 0) * 2.0 * scale * 0.25 * px - sep)));&#10;        }&#10;    }&#10;    vec3 c = wc.rgb;&#10;    if (brighten &gt; 0.5) c /= max(max(c.r, max(c.g, c.b)), 1e-3);&#10;    float cov = clamp((thick &gt; 0.5 ? 2.0 : 1.2) - d, 0.0, 1.0) * clamp(a, 0.0, 1.0);&#10;    return additive &gt; 0.5 ? col + c * cov : mix(col, c, cov);&#10;}&#10;&#10;vec3 md_borders(vec3 col, vec2 uv, float os, vec4 oc, float is_, vec4 ic) {&#10;    float e = min(min(uv.x, 1.0 - uv.x) * md_R.x / md_R.y, min(uv.y, 1.0 - uv.y));&#10;    if (e &lt; os * 0.5) col = mix(col, oc.rgb, oc.a);&#10;    else if (e &lt; (os + is_) * 0.5) col = mix(col, ic.rgb, ic.a);&#10;    return col;&#10;}&#10;&#10;// the colour MilkDrop hands a comp shader in hue_shader: four corners slowly changing colour&#10;vec3 md_hue(vec2 uv) {&#10;    vec3 c[4];&#10;    for (int i = 0; i &lt; 4; i++) {&#10;        float fi = float(i);&#10;        c[i] = 0.6 + 0.3 * sin(iTime * vec3(0.429, 0.371, 0.513) * (1.0 + 0.13 * fi) + fi * 1.7 + vec3(0.0, 2.1, 4.2));&#10;        c[i] /= max(c[i].r, max(c[i].g, c[i].b));&#10;    }&#10;    return mix(mix(c[0], c[1], uv.x), mix(c[2], c[3], uv.x), uv.y);&#10;}&#10;&#10;vec3 md_defaultComp(vec2 uv, float ezoom, float ealpha, float eorient, float gamma, float brighten, float darken, float solarize, float invert) {&#10;    vec3 c = md_tex2D(0, uv).rgb;&#10;    if (ealpha &gt; 0.001) {&#10;        vec2 e = (uv - 0.5) / max(ezoom, 0.01) + 0.5;&#10;        float o = floor(eorient + 0.5);&#10;        if (o == 1.0 || o == 3.0) e.x = 1.0 - e.x;&#10;        if (o == 2.0 || o == 3.0) e.y = 1.0 - e.y;&#10;        c = mix(c, md_tex2D(0, e).rgb, ealpha);&#10;    }&#10;    c *= gamma;&#10;    if (brighten &gt; 0.5) c = sqrt(max(c, 0.0));&#10;    if (darken &gt; 0.5) c = c * c;&#10;    if (solarize &gt; 0.5) c = c * (1.0 - c) * 4.0;&#10;    if (invert &gt; 0.5) c = 1.0 - c;&#10;    return c;&#10;}&#10;`;&#10;&#10;&#10;&#10;" inputs="5" outputs="6" live="1" tick="2"/>
        </node>
        <node id="11" type="visual.shadercode" title="Preset file" expanded="0" x="-1500.0" y="2400.0" w="420.0" h="300.0">
          <state file="" textsize="9.0" out="0.0" code="" live="1"/>
        </node>
        <node id="12" type="widget.textinput" title="Shader code" expanded="0" x="-1500.0" y="3000.0" w="1312.0" h="300.0">
          <state text="" placeholder="Paste your shader code here (Shadertoy mainImage or ISF), then Use code" emitOnChange="0" multiline="1" showSendButton="1" sendLabel="Use code" textSize="13" fontFamily="3" visible="0" backgroundColour="F0141220" borderColour="FF8A3FFF" borderWidth="1" buttonColour="FF8A3FFF"/>
        </node>
        <node id="13" type="keyboard.key" title="Left key" expanded="0" x="-1500.0" y="3500.0" w="260.0" h="160.0">
          <state key="13" keyName="Left"/>
        </node>
        <node id="14" type="keyboard.key" title="Right key" expanded="0" x="-1500.0" y="3750.0" w="260.0" h="160.0">
          <state key="14" keyName="Right"/>
        </node>
        <node id="15" type="audio.crossover_mono" title="Sound bands" expanded="0" x="-700.0" y="2100.0" w="320.0" h="200.0">
          <state lowX="200" highX="4000" slope="1"/>
        </node>
        <node id="16" type="audio.envelope_follower" title="Level" expanded="0" x="-300.0" y="2000.0" w="180.0" h="150.0">
          <state attack="5" release="150" threshold="0" gain="1"/>
        </node>
        <node id="17" type="audio.envelope_follower" title="Bass" expanded="0" x="-300.0" y="2200.0" w="180.0" h="150.0">
          <state attack="5" release="150" threshold="0" gain="1"/>
        </node>
        <node id="18" type="audio.envelope_follower" title="Mid" expanded="0" x="-300.0" y="2400.0" w="180.0" h="150.0">
          <state attack="5" release="150" threshold="0" gain="1"/>
        </node>
        <node id="19" type="audio.envelope_follower" title="High" expanded="0" x="-300.0" y="2600.0" w="180.0" h="150.0">
          <state attack="5" release="150" threshold="0" gain="1"/>
        </node>
        <node id="20" type="audio.toData" title="Level value" expanded="0" x="-60.0" y="2000.0" w="160.0" h="100.0">
          <state rateHz="60"/>
        </node>
        <node id="21" type="audio.toData" title="Bass value" expanded="0" x="-60.0" y="2200.0" w="160.0" h="100.0">
          <state rateHz="60"/>
        </node>
        <node id="22" type="audio.toData" title="Mid value" expanded="0" x="-60.0" y="2400.0" w="160.0" h="100.0">
          <state rateHz="60"/>
        </node>
        <node id="23" type="audio.toData" title="High value" expanded="0" x="-60.0" y="2600.0" w="160.0" h="100.0">
          <state rateHz="60"/>
        </node>
        <node id="24" type="audio.gainStereo" title="Listen volume" expanded="0" x="-300.0" y="1750.0" w="220.0" h="160.0">
          <state unit="1" gainDb="0"/>
        </node>
        <node id="8" type="audio.player" title="Sound Player" expanded="0" x="-700.0" y="1750.0" w="420.0" h="200.0">
          <state loop="1" volume="0.0" volumeDb="0.0" playAgain="0"/>
        </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"/>
        <e fn="5" fp="0" tn="1" tp="0"/>
        <e fn="5" fp="0" tn="6" tp="0"/>
        <e fn="5" fp="1" tn="6" tp="1"/>
        <e fn="7" fp="2" tn="1" tp="119"/>
        <e fn="7" fp="1" tn="1" tp="120"/>
        <e fn="7" fp="7" tn="1" tp="121"/>
        <e fn="2" fp="22" tn="8" tp="10"/>
        <e fn="2" fp="23" tn="8" tp="11"/>
        <e fn="2" fp="24" tn="8" tp="16"/>
        <e fn="2" fp="25" tn="8" tp="12"/>
        <e fn="2" fp="26" tn="24" tp="10"/>
        <e fn="8" fp="0" tn="1" tp="0"/>
        <e fn="8" fp="0" tn="24" tp="0"/>
        <e fn="8" fp="1" tn="24" tp="1"/>
        <e fn="24" fp="2" tn="6" tp="0"/>
        <e fn="24" fp="3" tn="6" tp="1"/>
        <e fn="2" fp="27" tn="10" tp="4"/>
        <e fn="10" fp="23" tn="2" tp="3"/>
        <e fn="10" fp="20" tn="9" tp="6"/>
        <e fn="10" fp="22" tn="11" tp="1"/>
        <e fn="11" fp="0" tn="10" tp="2"/>
        <e fn="11" fp="0" tn="2" tp="4"/>
        <e fn="12" fp="3" tn="2" tp="5"/>
        <e fn="10" fp="25" tn="12" tp="2"/>
        <e fn="13" fp="0" tn="2" tp="6"/>
        <e fn="14" fp="0" tn="2" tp="7"/>
        <e fn="5" fp="0" tn="9" tp="0"/>
        <e fn="8" fp="0" tn="9" tp="0"/>
        <e fn="5" fp="0" tn="15" tp="0"/>
        <e fn="8" fp="0" tn="15" tp="0"/>
        <e fn="5" fp="0" tn="16" tp="0"/>
        <e fn="8" fp="0" tn="16" tp="0"/>
        <e fn="15" fp="1" tn="17" tp="0"/>
        <e fn="15" fp="2" tn="18" tp="0"/>
        <e fn="15" fp="3" tn="19" tp="0"/>
        <e fn="16" fp="100" tn="20" tp="0"/>
        <e fn="17" fp="100" tn="21" tp="0"/>
        <e fn="18" fp="100" tn="22" tp="0"/>
        <e fn="19" fp="100" tn="23" tp="0"/>
        <e fn="20" fp="1" tn="1" tp="146"/>
        <e fn="21" fp="1" tn="1" tp="147"/>
        <e fn="22" fp="1" tn="1" tp="148"/>
        <e fn="23" fp="1" tn="1" tp="149"/>
      </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="9" x="0.0" y="0.0" w="1920.0" h="1080.0" z="1" auto="0" locked="1"/>
        <entry nodeId="1" x="0.0" y="0.0" w="1920.0" h="1080.0" z="2" auto="0" locked="1"/>
        <entry nodeId="12" x="184.0" y="8.0" w="940.0" h="300.0" z="3" auto="0" locked="1"/>
      </panel>
      <audioPreview loop="0" autoplay="1" gain="1.0"/>
    </marionietoworld.MNodes_State>
  </state>
</MNPreset>
