‹ pakt27pakt29 ›

pakt28

See /software/p5js/pakt-februari/pakt28/ for a JavaScript version and /software/supercollider/februari-pakt/pakt28/ 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.0015).sin() * 30.0 + 35.0;
    
    draw.background().color(BLACK);
    
    for i in 0..n as u16 {
        let t = i as f32 / n * PI * 2.0;
        let a1 = ((((index * 0.0025 + t).sin() * 0.01 + 0.01) * index).sin() * 0.5 + 0.5).sin() * PI * 2.0;
        let a2 = ((a1 * index * 0.0005 + t).sin() * 0.5 + 0.5) * PI;
        let r = win.h() * 0.475 * (1.0 - i as f32 / n);
        let col = hsva(t.sin() * ((index * 0.01).sin() * 0.2) + 0.5, (index * 0.004).sin() * 0.3 + 0.7, 1.0, 1.0);
        let mut builder = geom::path::Builder::new();
        builder = builder.move_to(pt2(a2.sin() * r, a2.cos() * r)).arc(pt2(0.0, 0.0), vec2(r, r), a1 - a2, 0.0);
        let path = builder.build();
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .path().stroke().color(col).weight((index * 0.0125 + t).sin() * 5.0 + 5.5).events(path.iter());
    }
    
    draw.to_frame(app, &frame).unwrap();
}