‹ pakt15pakt17 ›

pakt16

See /software/p5js/pakt-februari/pakt16/ for a JavaScript version and /software/supercollider/februari-pakt/pakt16/ 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 radius1 = (index * 0.013).sin() * 0.3 + 0.1;
    let radius2 = (index * 0.021).sin() * 0.2 + 0.25;
    let radius3 = (index * 0.012).sin() * 0.1 + 0.4;
    let ex1 = (index * 0.0052).sin() * 3.0 + 3.0;
    let ex2 = (index * 0.0061).sin() * 6.0 + 6.0;
    let ex3 = (index * 0.0053).sin() * 2.0 + 2.0;
    let n = (index * 0.001).sin() * 40.0 + 50.0;
    
    draw.background().color(BLACK);
    
    for i in 0..n as u16 {
        let i = i as f32;
        let t = (i / n) * PI * 2.0;
        let mut builder = geom::path::Builder::new();
        builder = builder.move_to(pt2((t + ex1).sin(), (t + ex1).cos()) * radius1 * win.wh());
        builder = builder.quadratic_bezier_to(
            vec2((t + ex2).sin(), (t + ex2).cos()) * radius2 * win.wh(),
            vec2((t + ex3).sin(), (t + ex3).cos()) * radius3 * win.wh(),
        );
        let a = ((index + (i * (index * 0.008 + (i * (index * 0.013).sin() * 0.01)).sin() * 2.0)) * 0.1).sin() * 0.5 + 0.5;
        let path = builder.build();
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .path().stroke().color(rgba(1.0, 1.0, 1.0, a)).weight(1.0).events(path.iter());
    }
    
    draw.to_frame(app, &frame).unwrap();
}