‹ pakt22pakt24 ›

pakt23

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

use nannou::prelude::*;

const N: usize = 250;

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

fn view(app: &App, frame: Frame) {
    let draw = app.draw();
    let win = app.window_rect();
    
    let index = app.time * 60.0;
    
    let rx = (index * 0.0024).sin();
    let ry = (index * 0.0022 + 1.0).sin();
    let tx = (index * 0.0016 + 2.0).sin() + rx;
    let ty = (index * 0.0018 + 3.0).sin() + ry;
    
    if frame.nth() == 0 {
        draw.background().color(BLACK);
    } else {
        draw.rect().wh(win.wh()).color(rgba(1.0, 1.0, 1.0, 0.02));
    }
    
    let mut p = pt2(0.0, 0.0);
    for i in 50..N {
        let t = i as f32 / N as f32;
        let x = t * PI * 2.0 * rx * tx;
        let y = t * PI * 2.0 * ry * ty;
        if i == 50 {
            p = pt2(x.cos(), y.sin()) * win.wh() * 0.495 * t;
        } else {
            let c = (t * PI * 2.0).sin() * 0.5 + 0.5;
            let mut builder = geom::path::Builder::new();
            builder = builder.move_to(p);
            p = pt2(x.sin(), y.cos()) * win.wh() * 0.495 * t;
            builder = builder.line_to(p);
            p = pt2(x.cos(), y.sin()) * win.wh() * 0.495 * t;
            builder = builder.line_to(p);
            let path = builder.build();
            draw.scale_axes(vec3(1.0, -1.0, 1.0))
            .path().stroke().color(rgba(c, 0.0, 0.0, c)).events(path.iter());
        }
    }
    
    draw.to_frame(app, &frame).unwrap();
}