‹ pakt23pakt25 ›

pakt24

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

use nannou::prelude::*;

const N: usize = 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();
    
    let index = app.time * 60.0;
    
    let rx = (index * 0.0012).sin();
    let ry = (index * 0.0022 + 1.0).sin();
    let tx = (index * 0.0032 + 2.0).sin() + rx;
    let ty = (index * 0.0042 + 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 builder = geom::path::Builder::new();
    builder = builder.move_to(
        pt2(
            (-1.0 / N as f32 * 2.0 * PI + rx + tx).cos(),
            (-1.0 / N as f32 * 2.0 * PI + ry + ty).sin(),
        ) * 0.49 * win.wh()
    );
    for i in 0..N {
        let t = i as f32 / N as f32 * 2.0 * PI;
        let x = t + rx + tx;
        let y = t + ry + ty;
        builder = builder.quadratic_bezier_to(
            pt2(x.sin(), y.cos()) * 0.49 * win.wh(),
            pt2(x.cos(), y.sin()) * 0.49 * win.wh(),
        );
    }
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0))
    .path().stroke().stroke_weight(0.75).color(BLACK).events(path.iter());
    
    draw.to_frame(app, &frame).unwrap();
}