use nannou::prelude::*; fn main() { nannou::app(model).update(update).simple_window(view).run(); } struct Model {} fn model(_app: &App) -> Model { Model {} } fn update(_app: &App, _model: &mut Model, _update: Update) {} const fn color(red: u8, green: u8, blue: u8) -> Rgb { Rgb { red, green, blue, standard: std::marker::PhantomData::, } } const BG: Rgb = color(0, 5, 5); const BALL: Rgb = color(255, 255, 255); const COLORS: &[Rgb] = &[ color(125, 22, 22), color(107, 19, 16), color(69, 15, 16), color(72, 0, 50), color(223, 0, 84), color(255, 139, 106), color(255, 214, 194), ]; const fn sm_color(i: i32, j: i32) -> Rgb { if i == 0 && j == 0 { BG } else { BALL } } const fn bg_color(i: i32, j: i32) -> Rgb { if i == 0 && j == 0 { return BALL; } let x = i * i * i * j + j * j + 3 + i + j + i * j; COLORS[x.abs() as usize % COLORS.len()] } fn view(app: &App, _model: &Model, frame: Frame) { let draw = app.draw(); let t = frame.nth() as f32 / 60.0; draw.background().color(BG); for i in -4..=4 { for j in -4..=4 { let speed = map_range((i + j).abs() as f32, 0.0, 8.0, 0.1, 2.0); let dis = (t * speed).sin() * 10.0; let circ_offset = vec2( (t + (i * i) as f32).sin() * dis, (t + (j * i) as f32).cos() * dis, ); let x = i as f32 * 100.0 * (t * 0.7).sin(); let y = j as f32 * 100.0 * (t * 0.7).cos(); draw.ellipse() .w_h(40.0, 40.0) .x_y(x + circ_offset.x, y + circ_offset.y) .color(bg_color(i, j)); draw.ellipse() .w_h(10.0, 10.0) .x_y(x, y) .color(sm_color(i, j)); } } draw.to_frame(app, &frame).unwrap(); record(app, &frame); } use once_cell::sync::Lazy; static RECORDING: Lazy = Lazy::new(|| { let args: Vec = std::env::args().collect(); args.len() > 1 && args[1] == "-record" }); fn record(app: &App, frame: &Frame) { if !*RECORDING { return; } // save frame let path = app .project_path() .expect("failed to locate `project_path`") // Capture all frames to a directory called `//nannou/simple_capture`. .join("recordings") .join(app.exe_name().unwrap()) // Name each file after the number of the frame. .join(format!("{:03}", frame.nth())) // The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others. .with_extension("png"); println!("frame: {} {:.3}", frame.nth(), frame.nth() as f32 / 60.0); app.main_window().capture_frame(path); }