ASCII Wave

của MusicBar, visualizer

Phổ nhạc vẽ bằng ký tự ASCII phát sáng như màn hình terminal, chỗ nhạc mạnh dày đặc @ với #, chỗ nhẹ chỉ lấm tấm dấu chấm, có con trỏ nhấp nháy chạy dọc như đang gõ phím.

20 lượt tải Tải file, 4.4 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 3ab2d1a99c3522766f8455b3e5c3b6db7425dbd4c7e419bf7523916533280812

//! name: ASCII Wave
//! author: MusicBar
//! kind: visualizer
//! description: The spectrum typed out as ASCII art in glowing phosphor characters, from faint dots up to dense at-signs where the sound is strongest, with a blinking block cursor sweeping along.

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

// One dot of a 5 x 7 character. g picks the character on the density ramp
// (1 . 2 : 3 - 4 = 5 + 6 * 7 # 8 @, 9 the solid cursor block); c is the column 0-4, r the row 0-6 from the top.
// Rows 0-3 are packed in one number and rows 4-6 in another, bit = row * 5 + column.
float glyph(float g, float c, float r)
{
    float top = g < 1.5 ? 0.0 : (g < 2.5 ? 6336.0 : (g < 3.5 ? 1015808.0 : (g < 4.5 ? 31744.0 : (g < 5.5 ? 1020032.0 : (g < 6.5 ? 480384.0 : (g < 7.5 ? 359754.0 : (g < 8.5 ? 718382.0 : 1048575.0)))))));
    float bot = g < 1.5 ? 6336.0 : (g < 2.5 ? 198.0 : (g < 3.5 ? 0.0 : (g < 4.5 ? 31.0 : (g < 5.5 ? 132.0 : (g < 6.5 ? 149.0 : (g < 7.5 ? 10591.0 : (g < 8.5 ? 30781.0 : 32767.0)))))));
    float n = r < 3.5 ? top : bot;
    float bit = (r < 3.5 ? r : r - 4.0) * 5.0 + c;
    return step(0.5, frac(n / exp2(bit + 1.0))) * step(0.5, g) * step(-0.5, c) * step(c, 4.5) * step(-0.5, r) * step(r, 6.5);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{
    // The character grid: 5 x 7 characters in 6 x 8 cells of whole-pixel dots, so they stay crisp;
    // rows are counted from the screen edge, the characters stand upright on screen.
    float d = max(1.0, floor(size.y / 40.0 + 0.5));            // one dot, in pixels
    float ch = 8.0 * d, cw = 6.0 * d;
    float rows = floor(size.y / ch);
    float cols = floor(size.x / cw);
    float x = uv.x * size.x;
    float e = rise(uv) * size.y;                               // pixels from the screen edge
    float col = floor(x / cw);
    float rEdge = floor(e / ch);
    float fy = frac(e / ch) * 8.0;
    fy = bottomEdge > 0.5 ? 8.0 - fy : fy;
    float2 dotAt = float2(floor(frac(x / cw) * 6.0), floor(fy));

    // Each column's height in characters, mirrored so the bass sits in the middle.
    float v = spectrum(abs((col + 0.5) / cols - 0.5) * 2.0) * (1.0 + 0.25 * beat);
    float H = pow(v, 1.3) * rows * 1.5;

    // Density: solid only deep in a tall column, thinning through the ramp toward the top.
    float I = saturate((H - rEdge) / 3.0);
    float g = ceil(I * 8.0) * step(rEdge, rows - 0.5);

    // The cursor sweeps along like someone typing, sitting on top of its column and blinking.
    float cc = floor(frac(time * 0.06) * cols);
    float behind = cc - col;
    float atCursor = step(abs(behind), 0.5) * step(abs(rEdge - min(floor(H), rows - 1.0)), 0.5);
    float blink = max(step(0.5, frac(time * 1.6)), step(0.3, beat));
    g = lerp(g, 9.0, atCursor * blink);
    float trail = exp(-max(behind, 0.0) / 9.0) * step(-0.5, behind);   // freshly typed characters glow brighter

    // The dot itself, and its four neighbors for the phosphor bleeding around the strokes.
    float lit = glyph(g, dotAt.x, dotAt.y);
    float bleed = glyph(g, dotAt.x - 1.0, dotAt.y) + glyph(g, dotAt.x + 1.0, dotAt.y) + glyph(g, dotAt.x, dotAt.y - 1.0) + glyph(g, dotAt.x, dotAt.y + 1.0);

    // Color: second color for the faint top characters into the main color deep down, accent for the cursor.
    float3 c = lerp(colorB.rgb, colorA.rgb, smoothstep(0.2, 0.9, I));
    c = lerp(c, lerp(colorC.rgb, float3(1, 1, 1), 0.15), saturate(trail * 0.6 + atCursor * blink));
    float bright = (0.5 + 0.5 * I) * (1.0 + 0.5 * trail + 0.25 * beat);

    float3 acc = float3(0, 0, 0);
    float cover = 0;

    // Phosphor: a soft bloom over each character, the bleed around lit dots, then the dots with a hot core.
    float2 cq = (float2(frac(x / cw) * 6.0, fy) - float2(2.5, 3.5)) / float2(3.2, 4.2);
    layer(acc, cover, c, exp(-dot(cq, cq) * 1.6) * step(0.5, g) * (0.1 + 0.2 * I + 0.15 * trail + 0.25 * atCursor * blink));
    layer(acc, cover, c, (1.0 - lit) * saturate(bleed * 0.5) * (0.22 + 0.2 * I) * (1.0 + trail));
    layer(acc, cover, c * bright, lit * (0.85 + 0.15 * I));
    float2 dq = frac(float2(x / d, fy)) - 0.5;
    layer(acc, cover, float3(1, 1, 1), lit * step(1.5, d) * smoothstep(0.5, 0.15, length(dq)) * saturate(I * 0.5 + trail * 0.5 + atCursor * blink) * 0.55);

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