‹ pakt14pakt16 ›

pakt15

See /software/p5js/pakt-februari/pakt15/ for a JavaScript version and /software/supercollider/februari-pakt/pakt15/ for accompanying sound code.

use nannou::prelude::*;

const N: u16 = 80;

fn main() {
    nannou::sketch(view).size(640, 480).run();
}

fn view(app: &App, frame: Frame) {
    let draw = app.draw();
    let win = app.window_rect();
    
    draw.background().color(BLACK);
    
    let index = app.time * 60.0;
    let speed = 0.005;
    for i in 0..=N {
        let i = i as f32;
        let mut builder = geom::path::Builder::new();
        builder = builder.move_to(pt2(
            ((index * 0.1) + (i * 0.3)).sin() * 0.3,
            0.0,
        ) * win.wh());
        builder = builder.line_to(pt2(
            ((index + i) * 0.0144).sin() * 0.03 + 0.26,
            ((index + i) * 0.0126).cos() * 0.03 + 0.26,
        ) * win.wh());
        builder = builder.line_to(pt2(
            ((index + i) * 0.0244).sin() * 0.02 + 0.07,
            ((index + i) * 0.0226).cos() * 0.02 + 0.07,
        ) * win.wh());
        let path = builder.build();
        draw.scale_axes(vec3(1.0, -1.0, 1.0)).rotate((i / N as f32 * PI * 2.0 + index * (index * speed).sin() * 0.0001) * i)
        .path().stroke().color(rgba(1.0, ((index + i) * 0.1).sin() * 0.5 + 0.5, 1.0, 0.5)).weight(1.0).events(path.iter());
    }
    
    draw.to_frame(app, &frame).unwrap();
}