spiral

Cargo.toml

See /f0blog/spiral/ for a JavaScript version.

use nannou::prelude::*;

fn main() {
    nannou::sketch(view).size(800, 600).run();
}

fn view(app: &App, frame: Frame) {
    let draw = app.draw();
    draw.background().color(BLACK);
    let theta = (app.time * 60.0 * 0.001).sin() * PI * 2.0 * 4.0;
    for y in 0..app.window_rect().h() as i32 {
        let y = y as f32;
        for i in 0..10 {
            let i = i as f32;
            let rot = i + 1.0 + y * 10.0;
            draw.rotate(theta * 0.001 * rot).rect().color(WHITE).w_h(2.0, 2.0)
            .x_y((y * 0.1 + theta + i * 2.0).sin() * 100.0, y);
        }
    }
    draw.to_frame(app, &frame).unwrap();
}