use sketchlib::nannou; use sketchlib::nannou::color::Alpha; use sketchlib::nannou::glam::Vec3Swizzles; use sketchlib::prelude::*; const PHI_MINUS_ONE_TIMES_PI: f32 = 1.94161103873; fn main() { nannou::app(model) .size(1260, 1260) .update(update) .simple_window(view) .run(); } struct Point { pos: Vec3, } struct Model { points: Vec, } fn model(_app: &App) -> Model { let mut points = vec![]; let mut theta = 0.0; for r in 0..512 { let r = 50.0 * (r as f32).sqrt(); points.push(Point { pos: (r * theta.cos(), r * theta.sin(), 0.0).into(), }); theta += PHI_MINUS_ONE_TIMES_PI; } Model { points } } fn update(app: &App, model: &mut Model, _update: Update) { let dt = delta_t(app) as f32; let t = absolute_t(app) as f32; model.points.par_iter_mut().enumerate().for_each(|(i, b)| { let i = i as f32; b.pos.x += (t * PI + i).cos() * 35.0 * dt; b.pos.y += (t * PI + i).sin() * 35.0 * dt; }); } fn view(app: &App, model: &Model, frame: Frame) { // let t = app.duration.since_start.as_secs_f64(); const BG_COL: Srgb = BLACK; let draw = app.draw(); if frame.nth() == 0 { draw.background().color(BG_COL); } else { let window_rect = app.window_rect(); draw.rect() .xy(window_rect.xy()) .wh(window_rect.wh()) .color(Alpha { color: BG_COL, alpha: 0.02, }); } // let draw = draw.scale(0.01); for (i, point) in model.points.iter().enumerate() { let trans_flag = *sketchlib::palettes::NON_BINARY_FLAG; draw.ellipse() .color(trans_flag[i % trans_flag.len()]) .radius(10.0) .xy(point.pos.xy()); } draw.to_frame(app, &frame).unwrap(); dump_frame(app, &frame).unwrap(); }