‹ pakt24pakt26 ›

pakt25

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

use nannou::prelude::*;

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 n = ((index * 0.0006).sin() * 15.0 + 20.0) as i32;
    
    if frame.nth() == 0 {
        draw.background().color(BLACK);
    } else {
        draw.rect().wh(win.wh()).color(rgba(0.0, 0.0, 0.0, 0.02));
    }
    
    let mut builder = geom::path::Builder::new();
    builder = builder.move_to(pt2(0.0, win.h() * 0.5));
    for i in 0..n {
        let t = i as f32 / (n - 1) as f32;
        builder = builder.quadratic_bezier_to(
            pt2(
                t - (0.5 / n as f32),
                (index * (index * 0.006).sin() * 0.02 + t).sin() * 0.5 + 0.5,
            ) * win.wh(),
            pt2(
                t,
                (index * (index * 0.002).sin() * 0.02 + t).cos() * 0.5 + 0.5,
            ) * win.wh(),
        );
    }
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0)).translate(vec3(win.w(), win.h(), 0.0) * -0.5)
    .path().stroke().stroke_weight(0.5).color(WHITE).events(path.iter());
    
    draw.to_frame(app, &frame).unwrap();
}