Head Bop Crew
by MusicBar, visualizer
A row of round little critters sits along the bar with their eyes shut, bobbing their heads on every beat and singing along whenever their own slice of the spectrum gets loud.
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 ff5b36f015f2ae0fd63f34c0f725d09b48dfc8e088f29d504747c0b5a5916d3b
//! name: Head Bop Crew
//! author: MusicBar
//! kind: visualizer
//! description: A row of round little critters sits along the bar with their eyes shut, bobbing their heads on every beat and singing along whenever their own slice of the spectrum gets loud.
// A steady random number for a whole number.
float hash1(float n) { n = frac(n * 0.1031); n *= n + 33.33; n *= n + n; return frac(n); }
// Turns a point around the origin by a (radians, counterclockwise).
float2 rot(float2 p, float a) { float c = cos(a), s = sin(a); return float2(c * p.x - s * p.y, s * p.x + c * p.y); }
// Signed distance to an ellipse with radii r (close enough near the edge).
float ellipse(float2 p, float2 r) { float k0 = length(p / r); return k0 * (k0 - 1.0) / max(length(p / (r * r)), 0.0001); }
// Smooth union, so bumps and tips melt into the body.
float smin(float a, float b, float k) { float h = saturate(0.5 + 0.5 * (b - a) / k); return lerp(b, a, h) - k * h * (1.0 - h); }
// Distance to a short U-shaped curve of half width w around c (closed eyes, smiles), round at the ends.
float curve(float2 p, float2 c, float w, float bend)
{
float dx = p.x - c.x;
float dy = (p.y - c.y - bend * dx * dx) / sqrt(1.0 + 4.0 * bend * bend * dx * dx);
return length(float2(max(abs(dx) - w, 0.0), dy));
}
float sdSeg(float2 p, float2 a, float2 b) { float2 pa = p - a, ba = b - a; return length(pa - ba * saturate(dot(pa, ba) / dot(ba, ba))); }
// Anti-aliased fill of a distance d, where pw is one pixel in the same units.
float fill(float d, float pw) { return smoothstep(0.6 * pw, -0.6 * pw, d); }
// Round-body shading: a sphere normal from the ellipse, a soft key light from the upper left, a rim and a glint.
float3 shade(float2 q, float2 c, float2 r, float3 base)
{
float2 s = (q - c) / r;
float z = sqrt(saturate(1.0 - dot(s, s)));
float3 n = normalize(float3(s, z * 0.9 + 0.05));
float dif = saturate(dot(n, normalize(float3(-0.35, 0.7, 0.6))));
float spec = pow(saturate(dot(n, normalize(float3(-0.3, 0.55, 1.0)))), 26.0);
return base * (0.42 + 0.72 * dif) + lerp(base, float3(1, 1, 1), 0.5) * pow(1.0 - z, 3.0) * 0.4 + spec * 0.5;
}
// 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);
}
float4 main(float2 uv : TEXCOORD) : COLOR
{
float u = size.y;
float2 px = float2(uv.x * size.x, (1.0 - uv.y) * u); // pixels, y up the screen, so the crew always sits upright
float W = 1.2 * u, seats = floor(size.x / W); // one seat per critter, the row centered on the bar
float x0 = (size.x - seats * W) * 0.5, i = floor((px.x - x0) / W), cx = x0 + (i + 0.5) * W;
float seated = step(0.0, i) * step(i, seats - 1.0);
float kind = fmod(floor(frac((i + floor(i * 0.25)) * 0.25) * 4.0 + 0.5), 4.0); // 0 blob, 1 bird, 2 frog, 3 bunny; neighbors never match
float h = hash1(i * 1.37 + 0.5);
float sc = 0.9 + 0.1 * h;
float pw = 1.0 / (u * sc); // one pixel, in critter units
float lw = 0.012 + 0.65 * pw; // half width of the eye and mouth strokes
float isBird = step(abs(kind - 1.0), 0.5), isFrog = step(abs(kind - 2.0), 0.5), isBunny = step(2.5, kind), isBlob = step(kind, 0.5);
// Each critter listens to its own band (bass in the middle of the bar) and sings when it is loud.
float band = spectrum(abs(cx / size.x - 0.5) * 1.7);
float sing = smoothstep(0.3, 0.6, band) * (0.75 + 0.25 * abs(wave(frac(i * 0.37))));
// The bop: every beat squashes the body and drops the face (the nod); in between they sway, eyes shut.
float nod = beat;
float sway = (0.06 + 0.06 * level) * sin(time * 2.3 + i * 1.9);
float2 p0 = (px - float2(cx, 0.0)) / (u * sc);
float2 q = rot(p0 - float2(0.0, 0.03), sway) + float2(0.0, 0.03);
q = float2(q.x * (1.0 - 0.1 * nod), (q.y - 0.03) / (1.0 - 0.17 * nod) + 0.03);
float2 qm = float2(abs(q.x), q.y);
float2 f = q + float2(0.0, 0.08 * nod);
// Bodies: blob (a gumdrop with a curl on top), bird (a ball), frog (wide, with eye bumps), bunny (long ears).
float2 bc = kind < 0.5 ? float2(0.0, 0.31) : (kind < 1.5 ? float2(0.0, 0.35) : (kind < 2.5 ? float2(0.0, 0.27) : float2(0.0, 0.3)));
float2 br = kind < 0.5 ? float2(0.4, 0.3) : (kind < 1.5 ? float2(0.34, 0.33) : (kind < 2.5 ? float2(0.45, 0.26) : float2(0.32, 0.29)));
float dBody = ellipse(q - bc, br);
dBody = lerp(dBody, smin(dBody, length(q - float2(0.05 + 0.03 * nod, 0.64)) - 0.045, 0.12), isBlob);
dBody = lerp(dBody, smin(dBody, length(qm - float2(0.2, 0.5)) - 0.13, 0.06), isFrog);
float flop = 0.45 * nod + 0.06 * sin(time * 3.1 + i); // the bunny's ears flop outward on the nod
float2 e = rot(qm - float2(0.1, 0.5), 0.22 + flop);
float dEar = ellipse(e - float2(0.0, 0.16), float2(0.075, 0.17));
float2 w = rot(qm - float2(0.27, 0.33), 0.7 - 1.3 * nod); // the bird flaps on the nod
float dWing = ellipse(w - float2(0.08, 0.0), float2(0.11, 0.05));
float dTuft = min(ellipse(rot(q - float2(0.0, 0.64), 0.25 * sin(time * 4.0 + i) - 0.3 * nod) - float2(0.0, 0.07), float2(0.028, 0.075)),
ellipse(rot(qm - float2(0.02, 0.63), 0.6 + 0.4 * nod) - float2(0.0, 0.06), float2(0.024, 0.06)));
float dFeet = ellipse(qm - float2(0.13, 0.03), float2(0.085, 0.04));
float dAll = min(min(dBody, dFeet), min(lerp(9.0, min(dTuft, dWing), isBird), lerp(9.0, dEar, isBunny)));
float3 base = kind < 0.5 ? colorA.rgb : (kind < 1.5 ? colorC.rgb : (kind < 2.5 ? colorB.rgb : float3(0.97, 0.94, 0.9)));
float3 ink = float3(0.14, 0.06, 0.1);
float3 acc = float3(0, 0, 0);
float cover = 0;
// A soft shadow on the edge, a self-lit glow that swells while singing, and a dark outline for light taskbars.
layer(acc, cover, float3(0, 0, 0), smoothstep(0.05, -0.05, ellipse(p0 - float2(0.0, 0.02), float2(0.42, 0.045))) * 0.35);
layer(acc, cover, base, exp(-max(dAll, 0.0) / 0.09) * (0.14 + 0.3 * sing + 0.15 * nod));
layer(acc, cover, base * 0.2, fill(dAll - 1.5 * pw, pw));
// Behind the body: feet, the bunny's ears with pink insides, the bird's tuft.
layer(acc, cover, lerp(base * 0.7, float3(1.0, 0.6, 0.22), isBird), fill(dFeet, pw));
float3 earCol = lerp(shade(e, float2(0.0, 0.16), float2(0.075, 0.17), base), lerp(colorA.rgb, float3(1.0, 0.62, 0.72), 0.55), fill(ellipse(e - float2(0.0, 0.15), float2(0.035, 0.12)), pw));
layer(acc, cover, earCol, fill(dEar, pw) * isBunny);
layer(acc, cover, base * 0.85, fill(dTuft, pw) * isBird);
// The body, with a paler belly on all but the blob.
float3 col = shade(q, bc, br, base);
float belly = smoothstep(0.03, -0.03, ellipse(q - float2(0.0, bc.y - br.y * 0.45), br * float2(0.58, 0.5)));
col = lerp(col, lerp(col, float3(1, 1, 1), 0.45), belly * (1.0 - isBlob) * 0.8);
layer(acc, cover, col, fill(dBody, pw));
layer(acc, cover, shade(w, float2(0.08, 0.0), float2(0.11, 0.05), base * 0.8), fill(dWing, pw) * isBird);
// Closed eyes (little U curves) with rosy cheeks under them.
float2 E = kind < 0.5 ? float2(0.13, 0.37) : (kind < 1.5 ? float2(0.12, 0.45) : (kind < 2.5 ? float2(0.2, 0.52) : float2(0.11, 0.38)));
float mY = kind < 0.5 ? 0.25 : (kind < 1.5 ? 0.34 : (kind < 2.5 ? 0.31 : 0.25));
float mW = lerp(0.045, 0.12, isFrog);
float2 fm = float2(abs(f.x), f.y);
layer(acc, cover, lerp(float3(1.0, 0.42, 0.52), colorA.rgb, 0.25), smoothstep(0.04, -0.01, ellipse(fm - float2(E.x + 0.07, E.y - 0.09), float2(0.06, 0.032))) * 0.6);
layer(acc, cover, ink, fill(curve(fm, E, 0.055, 7.0) - lw, pw));
// The mouth: a calm smile, opening into a singing O with a tongue when the band is loud.
float ow = smoothstep(0.1, 0.3, sing);
float2 mr = float2(mW * 0.85 + 0.025, 0.014 + 0.085 * sing);
float2 mq = f - float2(0.0, mY - mr.y * 0.55);
float dMouth = ellipse(mq, mr);
float3 mouthCol = lerp(float3(0.32, 0.03, 0.08), float3(1.0, 0.45, 0.52), fill(ellipse(mq + float2(0.0, mr.y * 0.75), mr * float2(0.7, 0.6)), pw));
layer(acc, cover, ink, fill(curve(f, float2(0.0, mY), mW, 7.0) - lw, pw) * (1.0 - ow) * (1.0 - isBird));
layer(acc, cover, ink, fill(dMouth - lw * 0.8, pw) * ow * (1.0 - isBird));
layer(acc, cover, mouthCol, fill(dMouth, pw) * ow * (1.0 - isBird));
layer(acc, cover, float3(1.0, 0.55, 0.65), fill(ellipse(f - float2(0.0, mY + 0.055), float2(0.026, 0.017)), pw) * isBunny);
// The bird's beak: two halves that part when it sings.
float by = 0.35, lift = 0.012 * sing, drop = 0.06 * sing;
float dUp = max(abs(f.x) * 0.7 + (f.y - by - lift) - 0.045, by + lift - f.y);
float dLo = max(abs(f.x) * 0.85 + (by - drop - f.y) - 0.04, f.y - by + drop);
layer(acc, cover, float3(0.35, 0.04, 0.06), fill(ellipse(f - float2(0.0, by + (lift - drop) * 0.5), float2(0.045, (lift + drop) * 0.5 + 0.004)), pw) * isBird);
layer(acc, cover, float3(1.0, 0.58, 0.18) * (0.8 + 0.4 * saturate((f.y - by + 0.05) / 0.1)), fill(min(dUp, dLo), pw) * isBird);
// The blob wears headphones: a band over the top and glowing cups that pulse on the beat.
float dBand = max(abs(length(q - float2(0.0, 0.3)) - 0.44) - 0.026, 0.36 - q.y);
float dCup = ellipse(qm - float2(0.42, 0.31), float2(0.07, 0.115));
layer(acc, cover, float3(0.16, 0.16, 0.2) + 0.25 * smoothstep(0.0, 0.03, q.y - 0.6), fill(dBand, pw) * isBlob);
layer(acc, cover, colorC.rgb, exp(-max(dCup, 0.0) / 0.05) * (0.3 + 0.6 * nod) * isBlob);
layer(acc, cover, shade(qm, float2(0.42, 0.31), float2(0.07, 0.115), colorC.rgb) + 0.3 * nod, fill(dCup, pw) * isBlob);
// Singers send a little music note floating up beside them.
float side = step(0.5, frac(i * 0.5)) * 2.0 - 1.0;
float ph = frac(time * 0.6 + h * 5.0);
float2 nq = (float2(p0.x * side, p0.y) - float2(0.3 + 0.14 * ph, 0.5 + 0.38 * ph)) / 0.6;
float note = ellipse(rot(nq - float2(-0.035, -0.07), 0.45), float2(0.075, 0.052));
note = min(note, min(sdSeg(nq, float2(0.032, -0.065), float2(0.032, 0.15)) - 0.016, sdSeg(nq, float2(0.032, 0.15), float2(0.1, 0.07)) - 0.018));
float na = smoothstep(0.15, 0.5, sing) * smoothstep(0.0, 0.12, ph) * smoothstep(1.0, 0.7, ph);
layer(acc, cover, colorC.rgb, exp(-max(note, 0.0) / 0.08) * na * 0.6);
layer(acc, cover, lerp(colorC.rgb, float3(1, 1, 1), 0.45), fill(note * 0.6, pw) * na);
return paint(acc / max(cover, 0.001), cover * seated);
}