Circuit
by MusicBar, progress bar
A circuit board powers up to the playhead, data pulses racing along its gold traces between the chips and the LEDs blinking on every beat, while the board ahead sits dark.
How it installs, its SHA-256 and its code
Click Apply: MusicBar downloads it, checks its SHA-256 and puts it on the taskbar, or just puts it on if it already has it. Needs MusicBar 1.8 or newer.
SHA-256 af023a1de90de9702c4338f73f22958f1a87f927090f068c9c914ca7139920af
//! name: Circuit
//! author: MusicBar
//! kind: progress
//! description: A circuit board powers up to the playhead, data pulses racing along its gold traces between the chips and the LEDs blinking on every beat, while the board ahead sits dark.
float hash1(float n) { return frac(sin(n * 127.1 + 311.7) * 43758.5453); }
// Lays a color over what is there (premultiplied light, and how much of the pixel it covers).
void layer(inout float3 acc, inout float cover, float3 rgb, float a)
{
a = saturate(a);
acc = rgb * a + acc * (1.0 - a);
cover = a + cover * (1.0 - a);
}
float sdBox(float2 p, float2 b) { float2 d = abs(p) - b; return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0); }
// Chip g: its half width (some are wide quad packs, some narrow).
float chipW(float g, float u) { return u * (0.34 + 0.16 * step(0.5, hash1(g * 4.7 + 1.3))); }
float4 main(float2 uv : TEXCOORD) : COLOR
{
float u = size.y;
float2 px = float2(uv.x * size.x, rise(uv) * size.y);
float head = progress * size.x;
float3 acc = float3(0, 0, 0);
float cover = 0;
float P = 3.4 * u, cy = 0.5 * u, hh = 0.24 * u, pinL = 0.07 * u;
float on = smoothstep(head + 0.04 * u, head - 0.04 * u, px.x); // 1 where the board has power
float3 gold = float3(0.95, 0.72, 0.32), dull = float3(0.42, 0.27, 0.13);
// The traces between chip g and chip g+1: four leave the right pins, fan out at 45 degrees to their lanes,
// run along, and fan back in to the next chip's left pins.
float g = floor(px.x / P - 0.5);
float xa = (g + 0.5) * P + chipW(g, u) + pinL;
float xb = (g + 1.5) * P - chipW(g + 1.0, u) - pinL;
float bendA = xa + u * (0.06 + 0.25 * hash1(g * 2.3));
float bendB = xb - u * (0.06 + 0.25 * hash1(g * 5.9 + 2.0));
float spread = u * lerp(0.2, 0.245, hash1(g * 8.1));
float4 band = float4(spectrum(0.04), spectrum(0.2), spectrum(0.45), spectrum(0.75)); // one band per lane
float dT = 1e4, pulse = 0.0, halo = 0.0;
[unroll] for (int i = 0; i < 4; i++)
{
float fi = i;
float pinY = cy + (fi - 1.5) * 0.11 * u;
float lane = cy + (fi - 1.5) * spread;
float dy = abs(lane - pinY);
float rl = saturate((px.x - bendA) / max(dy, 0.001));
float rr = saturate((bendB - px.x) / max(dy, 0.001));
float diag = step(0.001, rl) * step(rl, 0.999) + step(0.001, rr) * step(rr, 0.999);
float ty = lerp(pinY + (lane - pinY) * rl, pinY + (lane - pinY) * rr, step(0.5 * (xa + xb), px.x));
float d = abs(px.y - ty) * lerp(1.0, 0.7071, saturate(diag));
// A data pulse racing right along this trace, with a fading tail.
float ph = frac((px.x / u - time * 3.0) / (1.3 + 0.9 * hash1(g * 3.3 + fi)) + hash1(g * 7.7 + fi * 1.9));
float pz = pow(ph, 10.0) * smoothstep(1.0, 0.97, ph) * (0.35 + 1.3 * band[i]);
halo += exp(-d / (0.05 * u)) * pz;
pulse = d < dT ? pz : pulse;
dT = min(dT, d);
}
float inGap = step(xa - pinL, px.x) * step(px.x, xb + pinL);
float tw = 0.022 * u;
float trace = smoothstep(tw + 0.5, tw - 0.5, dT) * inGap;
// Soft glow around powered traces, much brighter where a pulse is passing; at the power front the
// current arrives white-hot, and it surges on the beat.
float front = exp(-max(head - px.x, 0.0) / (0.5 * u)) * smoothstep(head + 0.06 * u, head - 0.02 * u, px.x) * (0.7 + 0.6 * beat);
layer(acc, cover, colorA.rgb, (exp(-dT / (0.06 * u)) * (0.12 + 0.6 * front) * on + halo * on * 0.8) * inGap);
float3 tc = lerp(dull, gold * (0.8 + 0.25 * level), on);
tc = lerp(tc, lerp(colorA.rgb, float3(1, 1, 1), 0.5), saturate(pulse * on * 1.3));
tc = lerp(tc, float3(1, 1, 1), saturate(front * on * 0.8));
layer(acc, cover, tc, trace * lerp(0.5, 1.0, on));
// Stitching vias between the lanes: a plated ring around a drilled hole.
float hLed = hash1(g * 3.7 + 0.4);
float ledX = lerp(bendA + 0.6 * u, bendB - 0.6 * u, hLed);
float vc = floor(px.x / (0.5 * u));
float vh = hash1(vc * 9.1 + 4.0);
float2 vp = float2((vc + 0.5) * 0.5 * u, cy + (floor(vh * 3.0) - 1.0) * spread);
float vOk = step(bendA + 0.3 * u, vp.x) * step(vp.x, bendB - 0.3 * u) * step(0.3, hash1(vc * 2.7)) * step(0.3 * u, abs(vp.x - ledX));
float vd = length(px - vp);
float ring = smoothstep(0.05 * u + 0.5, 0.05 * u - 0.5, vd) * smoothstep(0.02 * u - 0.5, 0.02 * u + 0.5, vd);
layer(acc, cover, colorA.rgb, exp(-vd / (0.05 * u)) * vOk * on * (0.15 + 0.5 * beat));
layer(acc, cover, lerp(dull, gold, on), ring * vOk * lerp(0.5, 1.0, on));
// One small capacitor soldered onto a lane in each gap: a tan body between two tinned ends.
float cj = floor(hash1(g * 2.9) * 4.0);
float2 cq = px - float2(lerp(bendA + 0.45 * u, bendB - 0.45 * u, frac(hLed + 0.5)), cy + (cj - 1.5) * spread);
float capD = sdBox(cq, float2(0.1 * u, 0.045 * u)) - 0.01 * u;
float3 capC = lerp(float3(0.62, 0.48, 0.32), float3(0.8, 0.82, 0.85), step(0.06 * u, abs(cq.x)));
capC *= 0.75 + 0.35 * saturate(cq.y / (0.05 * u) + 0.5);
layer(acc, cover, capC * lerp(0.55, 1.0, on), smoothstep(0.5, -0.5, capD) * inGap);
// One LED per gap: dark when the board is off, blinking on the beat once it has power.
float2 lq = px - float2(ledX, cy);
float lit = on * saturate(0.35 + 0.65 * beat + 0.3 * step(0.5, frac(time * 1.3 + hash1(g * 1.1))) * (1.0 - beat));
float ledD = sdBox(lq, float2(0.075 * u, 0.05 * u)) - 0.012 * u;
layer(acc, cover, colorC.rgb, exp(-length(lq) / (u * (0.1 + 0.12 * beat))) * lit);
float3 ledC = lerp(float3(0.8, 0.8, 0.78) * 0.45, colorC.rgb * 0.3, smoothstep(0.045 * u, 0.035 * u, abs(lq.x)));
ledC = lerp(ledC, lerp(colorC.rgb, float3(1, 1, 1), 0.5), lit * smoothstep(0.06 * u, 0.01 * u, length(lq * float2(0.8, 1.1))));
layer(acc, cover, ledC, smoothstep(0.5, -0.5, ledD));
// The chips: a black package with pins on all four sides, a pin-one dimple, and a white silkscreen outline.
float c = floor(px.x / P);
float hw = chipW(c, u);
float2 q = px - float2((c + 0.5) * P, cy);
float silk = abs(sdBox(q, float2(hw + pinL + 0.05 * u, hh + 0.11 * u))) - (0.01 * u + 0.3);
layer(acc, cover, float3(0.92, 0.94, 0.9), smoothstep(0.5, -0.5, silk) * lerp(0.3, 0.6, on));
float pIdx = clamp(floor(q.y / (0.11 * u) + 2.0), 0.0, 3.0);
float dPin = sdBox(float2(abs(q.x) - hw - pinL * 0.5, q.y - (pIdx - 1.5) * 0.11 * u), float2(pinL * 0.5, 0.024 * u));
float nTB = floor((2.0 * hw - 0.1 * u) / (0.1 * u)) + 1.0;
float tIdx = clamp(floor(q.x / (0.1 * u) + nTB * 0.5), 0.0, nTB - 1.0);
dPin = min(dPin, sdBox(float2(q.x - (tIdx - (nTB - 1.0) * 0.5) * 0.1 * u, abs(q.y) - hh - 0.035 * u), float2(0.022 * u, 0.035 * u)));
layer(acc, cover, lerp(float3(0.45, 0.46, 0.48), float3(0.85, 0.87, 0.9), on), smoothstep(0.5, -0.5, dPin));
float body = sdBox(q, float2(hw, hh)) - 0.02 * u;
float3 chipC = float3(0.07, 0.07, 0.085) + 0.07 * saturate(q.y / hh * 0.5 + 0.5);
chipC += 0.18 * smoothstep(-0.035 * u, 0.0, body) * step(0.0, q.y); // lit top bevel
chipC *= 1.0 - 0.6 * smoothstep(0.035 * u, 0.02 * u, length(q - float2(-hw + 0.08 * u, -hh + 0.08 * u)));
layer(acc, cover, chipC, smoothstep(0.5, -0.5, body));
// A tiny status light in the chip's corner, ticking with the music once the chip has power.
float st = length(q - float2(hw - 0.08 * u, hh - 0.08 * u));
float tick = on * (0.3 + 0.7 * step(0.5, frac(time * 3.2 + hash1(c * 2.2))));
layer(acc, cover, colorB.rgb, exp(-st / (0.035 * u)) * tick * 0.8);
layer(acc, cover, lerp(colorB.rgb, float3(1, 1, 1), 0.4 * tick), smoothstep(0.022 * u + 0.4, 0.022 * u - 0.4, st) * lerp(0.3, 1.0, tick));
return paint(acc / max(cover, 0.001), cover);
}