use nox_gfx::canvas::{Canvas, Paint, Stroke}; use nox_gfx::color::{hex, rgba}; use nox_gfx::geom::{pt, Rect, IDENTITY}; use nox_gfx::path::Path; use std::time::Instant; fn time(name: &str, n: usize, mut f: impl FnMut()) { f(); let t0 = Instant::now(); for _ in 0..n { f(); } let el = t0.elapsed().as_secs_f64() * 1000.0 / n as f64; println!("{:<28} {:>8.3} ms", name, el); } fn main() { let mut c = Canvas::new(1100, 680); let full = c.full(); time("clear", 200, || c.clear(hex(0x101018))); let mut bg = Path::new(); bg.rrect(full, 14.0); time("fullscreen rrect vgrad", 200, || { c.fill(&bg, &IDENTITY, &Paint::vgrad(full, hex(0x141420), hex(0x0a0a10))) }); let mut glow = Path::new(); glow.circle(pt(210.0, 90.0), 320.0); time("radial glow r=320", 200, || { c.fill(&glow, &IDENTITY, &Paint::glow(pt(210.0, 90.0), 320.0, rgba(124, 92, 255, 80), rgba(124, 92, 255, 0))) }); let hero = Rect::xywh(256.0, 40.0, 808.0, 232.0); let mut heropath = Path::new(); heropath.rrect(hero, 16.0); time("card rrect fill", 200, || { c.fill(&heropath, &IDENTITY, &Paint::vgrad(hero, hex(0x241f45), hex(0x141726))) }); time("shadow blur=26 (hero)", 100, || { c.shadow(&heropath, &IDENTITY, 26.0, rgba(0, 0, 8, 176), pt(0.0, 14.0)) }); c.push_clip(Rect::xywh(0.0, 0.0, 2.0, 2.0)); time(" shadow mask only (clipped)", 100, || { c.shadow(&heropath, &IDENTITY, 26.0, rgba(0, 0, 8, 176), pt(0.0, 14.0)) }); c.pop_clip(); let small = Rect::xywh(14.0, 120.0, 196.0, 38.0); let mut smallp = Path::new(); smallp.rrect(small, 10.0); time("shadow blur=10 (nav)", 100, || { c.shadow(&smallp, &IDENTITY, 10.0, rgba(124, 92, 255, 140), pt(0.0, 3.0)) }); time("blurred_layer rail s=18", 50, || { let _ = c.blurred_layer(Rect::xywh(0.0, 0.0, 224.0, 680.0), 18.0); }); time("stroke 1px card outline", 200, || { c.stroke(&heropath, &IDENTITY, &Paint::Solid(rgba(255, 255, 255, 22)), &Stroke::new(1.0)) }); let mut wave = Path::new(); wave.move_to(pt(270.0, 620.0)); for i in 0..=60 { let t = i as f32 / 60.0; wave.line_to(pt(270.0 + t * 620.0, 600.0 - (t * 9.0).sin() * 26.0 - t * 18.0)); } time("stroke wave 2.5px round", 200, || { c.stroke(&wave, &IDENTITY, &Paint::Solid(rgba(53, 208, 255, 255)), &Stroke::round(2.5)) }); time("to_rgba", 100, || { let _ = c.to_rgba(); }); }