‹ pakt21pakt23 ›

pakt22

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

//missing a little bit of alpha background
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 cols = 10;
    let rows = 14;
    
    draw.background().color(rgba(0.1, 0.0, 0.0, 0.1));  //does not work as expected - no alpha
    
    let theta = (index * 0.0004).sin() * 0.1 + ((index * 0.004).sin() * (index * 0.00004).sin() * 6.0);
    let rc = ((index * 0.051).sin() * 0.01 + 1.0) / cols as f32;
    let rr = ((index * 0.062).cos() * 0.01 + 1.0) / rows as f32;
    for x in 0..cols {
        let cols = cols as f32;
        let x = x as f32;
        let rw = (x / cols * PI * (index * 0.0032).sin() + theta).sin() * cols * 5.0;
        for y in 0..rows {
            let rows = rows as f32;
            let y = y as f32;
            let rh = (y / rows * PI * (index * 0.0034).cos() + theta).cos() * rows * 5.0;
            let d;
            let r;
            if y as u32 % 2 == 0 {
                d = rw * 0.5;
                r = rw * 2.0;
            } else {
                d = rh * 0.5;
                r = rh * 2.0;
            }
            draw.scale_axes(vec3(1.0, -1.0, 1.0)).translate(vec3(win.w(), win.h(), 0.0) * -0.5)
            .color_blend(BLEND_SUBTRACT).ellipse().x_y(rc * x * win.w() + d, rr * y * win.h() + d).w_h(r, r)
            .color(RED);
        }
        
    }
    
    draw.to_frame(app, &frame).unwrap();
}