rustimal 0.2.3

A minimal, GPU-rendered terminal for Windows that runs Git Bash, with animated split panes and a glass look
//! The app icon, rendered procedurally. Shared with build.rs, which embeds it
//! into the executable, so keep this file dependency-free.

/// Render the icon as straight-alpha RGBA, `size` x `size`.
pub fn render(size: u32) -> Vec<u8> {
    const SS: u32 = 4; // supersampling per axis
    let mut rgba = vec![0u8; (size * size * 4) as usize];
    let s = 64.0 / size as f32; // work in a 64x64 design space
    for y in 0..size {
        for x in 0..size {
            let mut acc = [0.0f32; 4];
            for sy in 0..SS {
                for sx in 0..SS {
                    let px = (x as f32 + (sx as f32 + 0.5) / SS as f32) * s;
                    let py = (y as f32 + (sy as f32 + 0.5) / SS as f32) * s;
                    let c = sample(px, py);
                    // Accumulate premultiplied.
                    acc[0] += c[0] * c[3];
                    acc[1] += c[1] * c[3];
                    acc[2] += c[2] * c[3];
                    acc[3] += c[3];
                }
            }
            let n = (SS * SS) as f32;
            let a = acc[3] / n;
            let i = ((y * size + x) * 4) as usize;
            if a > 0.0 {
                rgba[i] = (acc[0] / acc[3] * 255.0).round() as u8;
                rgba[i + 1] = (acc[1] / acc[3] * 255.0).round() as u8;
                rgba[i + 2] = (acc[2] / acc[3] * 255.0).round() as u8;
            }
            rgba[i + 3] = (a * 255.0).round() as u8;
        }
    }
    rgba
}

/// Color at a point in 64x64 design space.
fn sample(px: f32, py: f32) -> [f32; 4] {
    // Rounded square.
    let r = 14.0;
    let qx = (px - 32.0).abs() - (32.0 - r);
    let qy = (py - 32.0).abs() - (32.0 - r);
    let d = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt() + qx.max(qy).min(0.0) - r;
    if d > 0.0 {
        return [0.0; 4];
    }
    // Background: deep slate with a soft vertical gradient.
    let t = py / 64.0;
    let top = [0.110, 0.137, 0.165];
    let bottom = [0.047, 0.055, 0.067];
    let mut c =
        [top[0] + (bottom[0] - top[0]) * t, top[1] + (bottom[1] - top[1]) * t, top[2] + (bottom[2] - top[2]) * t];
    // Hairline inner border.
    if d > -1.5 {
        c = [c[0] + 0.06, c[1] + 0.07, c[2] + 0.08];
    }
    // Prompt chevron and cursor bar in the accent color.
    let seg = |ax: f32, ay: f32, bx: f32, by: f32| {
        let (vx, vy) = (bx - ax, by - ay);
        let k = (((px - ax) * vx + (py - ay) * vy) / (vx * vx + vy * vy)).clamp(0.0, 1.0);
        ((px - ax - vx * k).powi(2) + (py - ay - vy * k).powi(2)).sqrt()
    };
    let chevron = seg(17.0, 21.0, 29.0, 32.0).min(seg(29.0, 32.0, 17.0, 43.0));
    let bar = seg(34.0, 43.0, 46.0, 43.0);
    let accent = [0.322, 0.714, 0.800];
    if chevron < 3.6 || bar < 3.6 {
        c = accent;
    }
    [c[0], c[1], c[2], 1.0]
}