Cassette Run

của MusicBar, thanh tiến trình

Cuộn băng cassette chạy tới chỗ đang phát, hai trục băng quay sau ô kính, phía sau là dải băng từ nâu bóng tuột ra rối thành từng vòng, uốn lượn theo nhạc, nhạc càng to trục quay càng nhanh.

2 lượt tải Tải file, 9.1 KB
Cách cài, mã SHA-256 và mã nguồn

Bấm Áp dụng: MusicBar tự tải về, kiểm tra mã SHA-256 rồi mặc lên taskbar; có rồi thì mặc luôn. Cần MusicBar 1.8 trở lên.

SHA-256 f3676ba87a887e6f719f59d9d246f4b2e239b1b6a52d40caac0e8df1af610222

//! name: Cassette Run
//! author: MusicBar
//! kind: progress
//! description: A cassette rides to the playhead with its reels turning behind the window, spilling a shiny brown ribbon of tape that loops and ripples with the music, and the reels spin faster when it gets loud.

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 a rounded box (half size b, corner r).
float boxD(float2 p, float2 b, float r) { float2 d = abs(p) - b + r; return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r; }

// 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);
}

// The spilled tape: it leaves the cassette at t = 0 and runs back along the bar, curling into a loop
// wherever the loop radius beats the forward step; loops hang down in some stretches and up in others.
// The loops slide slowly away from the cassette, and each beat whips a bump back along the tape.
float2 tapeAt(float t, float2 o, float H, float S, float lv)
{
    float k = t - time * 1.1;
    float n = saturate(0.5 + 0.55 * sin(k * 0.53 + 1.7) * sin(k * 0.29 + 0.4) + 0.2 * sin(k * 1.3));
    float R = H * (0.07 + 0.2 * n) * (0.75 + 0.45 * lv) * smoothstep(0.0, 3.5, t);
    float flip = clamp(sin(k * 0.11 + 0.6) * 3.0, -1.0, 1.0);
    float whip = H * 0.16 * beat * exp(-pow((t - (1.0 - beat) * 26.0) / 3.5, 2.0));
    float yb = lerp(o.y, H * (0.46 + 0.07 * sin(k * 0.21 + time * 0.7)), smoothstep(0.0, 4.0, t)) + whip;
    return float2(o.x - S * t - R * sin(k), yb + R * 0.75 * cos(k) * flip);
}

// A hub's six teeth turning at angle a (blur widens them into a smear).
float teeth(float2 q, float a, float blur)
{
    float f = abs(frac((atan2(q.y, q.x) + a) * 0.95493) - 0.5);
    return smoothstep(0.2 + blur, 0.12 - blur * 0.3, f) * step(0.034, length(q));
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float H = size.y;
    float2 px = float2(uv.x * size.x, (1.0 - uv.y) * H);     // pixels, y up the screen so the cassette never flips
    float head = progress * size.x;
    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // The cassette's frame (in cassette heights, y up), bobbing and tipping on the beat.
    float Hc = 0.84 * H;
    float2 cen = float2(head, 0.5 * H + 0.05 * H * beat);
    float ang = 0.035 * sin(time * 1.9) + 0.07 * beat;
    float2 c = rot(px - cen, -ang) / Hc;
    float2 exitP = cen + rot(float2(-0.43, -0.46) * Hc, ang);

    // Ahead: the song still to come, a sparse row of dim dots.
    float dk = frac(px.x / (0.32 * H)) - 0.5;
    float dots = smoothstep(0.04 * H + 0.5, 0.04 * H - 0.5, length(float2(dk * 0.32 * H, px.y - 0.45 * H)));
    layer(acc, cover, lerp(colorB.rgb, float3(1, 1, 1), 0.45), dots * 0.4 * step(head + 0.85 * Hc, px.x));

    // Behind: the tape. The waveform ripples it; the nearest point on the curve is found along a short window.
    float S = 0.1 * H;
    float rip = wave(abs(frac(px.x / (14.0 * H)) * 2.0 - 1.0)) * H * 0.07 * (0.3 + 0.9 * level);
    float2 p = float2(px.x, px.y - rip);
    float t0 = (exitP.x - p.x) / S;
    float best = 1e5;
    float bt = 0;
    float2 prev = tapeAt(max(t0 - 4.0, 0.0), exitP, H, S, level);
    [loop] for (int i = 1; i <= 20; i++)
    {
        float ti = max(t0 - 4.0 + i * 0.4, 0.0);
        float2 cur = tapeAt(ti, exitP, H, S, level);
        float2 pa = p - prev, ba = cur - prev;
        float h = saturate(dot(pa, ba) / max(dot(ba, ba), 0.0001));
        float d = length(pa - ba * h);
        float nearer = step(d, best);
        bt = lerp(bt, max(ti - 0.4 * (1.0 - h), 0.0), nearer);
        best = min(best, d);
        prev = cur;
    }

    // The ribbon twists as it lies: narrow when edge on, wide and glossy when it faces up.
    float k = bt - time * 1.1;
    float tw = 0.8 * k + 1.8 * sin(k * 0.31);
    float face = cos(tw);
    float hw = H * 0.05 * (0.25 + 0.75 * abs(face));
    float dT = best - hw;
    float across = saturate(best / max(hw, 0.5));
    float3 brown = lerp(float3(0.17, 0.08, 0.04), float3(0.52, 0.3, 0.15), 0.35 + 0.65 * abs(face)) * (1.0 - 0.35 * across * across);
    float spec = pow(saturate(sin(tw + 0.9)), 18.0) * (1.0 + 0.8 * beat);
    float3 tapeC = brown + lerp(float3(1.0, 0.86, 0.66), colorC.rgb, 0.3) * spec * (1.0 - across * 0.6) + 0.12 * (1.0 - across) * abs(face);
    layer(acc, cover, float3(0.05, 0.02, 0.01), smoothstep(0.08 * H, 0.0, dT) * 0.25);
    layer(acc, cover, float3(0.1, 0.05, 0.02), smoothstep(1.3, 0.3, dT - 0.6) * 0.8);
    layer(acc, cover, tapeC, smoothstep(0.5, -0.5, dT));

    // A soft shadow and a palette halo around the cassette, the halo flaring on the beat.
    float dShell = boxD(c, float2(0.79, 0.5), 0.08);
    layer(acc, cover, float3(0, 0, 0), smoothstep(0.1, -0.05, boxD(c + float2(-0.05, 0.07), float2(0.79, 0.5), 0.08)) * 0.35);
    layer(acc, cover, colorA.rgb, exp(-max(dShell, 0.0) / 0.12) * (0.22 + 0.4 * beat) * step(0.0, dShell));

    // The shell: palette plastic, lit from above, a bright bevel and a dark outline so it reads on any taskbar.
    float3 shell = colorA.rgb * (0.62 + 0.3 * c.y) + 0.04;
    shell += float3(1, 1, 1) * 0.3 * smoothstep(-0.05, -0.01, dShell) * step(0.0, c.y);
    shell = lerp(shell, colorA.rgb * 0.18, smoothstep(-1.2, 0.0, dShell * Hc));
    layer(acc, cover, shell, smoothstep(0.5, -0.5, dShell * Hc));

    // The bottom guard: a trapezoid with the tape running across its edge, guide holes and capstan slots.
    float hwid = lerp(0.57, 0.47, saturate((c.y + 0.5) / 0.23));
    float dTrap = max(abs(c.x) - hwid, c.y + 0.27);
    float3 guard = colorA.rgb * 0.3 + 0.04 + float3(1, 1, 1) * 0.25 * smoothstep(0.03, 0.0, abs(c.y + 0.275));
    layer(acc, cover, guard, smoothstep(0.5, -0.5, dTrap * Hc) * step(dShell, 0.0));
    float holes = min(length(float2(abs(c.x) - 0.34, c.y + 0.38)) - 0.045, boxD(float2(abs(c.x) - 0.15, c.y + 0.39), float2(0.03, 0.035), 0.008));
    layer(acc, cover, float3(0.03, 0.03, 0.04), smoothstep(0.5, -0.5, holes * Hc));
    layer(acc, cover, float3(0.36, 0.2, 0.1), smoothstep(0.5, -0.5, (abs(c.y + 0.465) - 0.016) * Hc) * step(abs(c.x), 0.43));
    float screws = length(float2(abs(c.x) - 0.72, abs(c.y + 0.0) - 0.425)) - 0.032;
    screws = min(screws, length(c - float2(0.0, -0.37)) - 0.032);
    layer(acc, cover, float3(0.75, 0.75, 0.78) * (0.7 + 0.5 * saturate((c.y + 0.5) * 2.0 - 0.2)), smoothstep(0.5, -0.5, screws * Hc));

    // The label: cream paper, two writing lines, and two palette stripes under the window.
    float dLab = boxD(c - float2(0.0, 0.13), float2(0.68, 0.3), 0.04);
    float3 paper = float3(0.95, 0.92, 0.84) * (0.9 + 0.1 * c.y);
    paper = lerp(paper, float3(0.62, 0.6, 0.58), smoothstep(0.5, -0.5, (abs(abs(c.y - 0.36) - 0.035) - 0.006) * Hc) * step(abs(c.x), 0.6));
    paper = lerp(paper, colorB.rgb, smoothstep(0.5, -0.5, (abs(c.y + 0.085) - 0.05) * Hc));
    paper = lerp(paper, colorC.rgb, smoothstep(0.5, -0.5, (abs(c.y + 0.012) - 0.018) * Hc));
    layer(acc, cover, paper, smoothstep(0.5, -0.5, dLab * Hc));

    // The window: smoky glass showing both tape packs (left empties, right fills as the song plays).
    float2 wq = c - float2(0.0, 0.13);
    float dWin = boxD(wq, float2(0.47, 0.115), 0.11);
    float spinA = time * 2.2 + 0.4 * beat;                    // quiet: an easy turn
    float spinB = time * 7.5 + 0.8 * beat;                    // loud: a blur
    float fast = smoothstep(0.3, 0.85, level);
    float2 hl = wq + float2(0.3, 0.0);
    float2 hr = wq - float2(0.3, 0.0);
    float rl = lerp(0.11, 0.3, 1.0 - progress);
    float rr = lerp(0.11, 0.3, progress);
    float packL = smoothstep(0.5, -0.5, (length(hl) - rl) * Hc);
    float packR = smoothstep(0.5, -0.5, (length(hr) - rr) * Hc);
    float2 hq = c.x < 0.0 ? hl : hr;
    float rings = 0.85 + 0.15 * sin(length(hq) * 160.0);
    float mark = lerp(teeth(hq, spinA, 0.0), teeth(hq, spinB, 0.25), fast) * 0.25;
    float3 glassC = lerp(float3(0.05, 0.05, 0.07), float3(0.42, 0.24, 0.12) * rings * (1.0 - mark), saturate(packL + packR));
    glassC += float3(1, 1, 1) * 0.16 * smoothstep(0.06, 0.0, abs(wq.x + wq.y * 1.3 - 0.12));
    layer(acc, cover, float3(0.02, 0.02, 0.03), smoothstep(0.5, -0.5, (dWin - 0.02) * Hc));
    layer(acc, cover, glassC, smoothstep(0.5, -0.5, dWin * Hc));

    // The hubs: white rings with six teeth turning inside, faster and smeared when the song is loud.
    float hr0 = length(hq);
    float tooth = lerp(teeth(hq, spinA, 0.0), lerp(teeth(hq, spinB, 0.25), 0.55, 0.3), fast);
    float hub = smoothstep(0.5, -0.5, (hr0 - 0.1) * Hc) * (smoothstep(-0.5, 0.5, (hr0 - 0.066) * Hc) + tooth * smoothstep(0.5, -0.5, (hr0 - 0.068) * Hc));
    float3 hubC = float3(0.93, 0.92, 0.9) * (0.75 + 0.25 * saturate(hq.y * 8.0 + 0.5));
    layer(acc, cover, float3(0.06, 0.05, 0.05), smoothstep(0.5, -0.5, (hr0 - 0.112) * Hc) * 0.8);
    layer(acc, cover, hubC, hub);

    // A glint sweeps the shell on the beat.
    float glint = smoothstep(0.1, 0.0, abs(c.x - c.y * 0.6 + 1.0 - 2.2 * (1.0 - beat))) * beat;
    layer(acc, cover, float3(1, 1, 1), glint * 0.35 * step(dShell, 0.0));

    return paint(acc / max(cover, 0.001), cover);
}