‹ pakt17pakt19 ›

pakt18

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

use nannou::prelude::*;

const N: u16 = 50;

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 spread = (index * 0.002).sin() * 50.0 + ((index * 0.003).sin() * 40.0);
    
    draw.background().color(BLACK);
    
    for i in 1..N {
        let i = i as f32;
        
        let a = ((i * spread + index) * (index * 0.0025 + (index * 0.0050).sin()).sin() * 0.005).sin() * 0.45 + 0.5;
        let b = ((i * spread + index) * (index * 0.0024 + (index * 0.0051).sin()).sin() * 0.005).sin() * 0.45 + 0.5;
        let c = ((i * spread + index) * (index * 0.0023 + (index * 0.0052).sin()).sin() * 0.005).sin() * 0.45 + 0.5;
        let d = ((i * spread + index) * (index * 0.0022 + (index * 0.0053).sin()).sin() * 0.005).sin() * 0.45 + 0.5;
        
        let p1 = vec2(a, b) * win.wh();
        let p2 = vec2(c, d) * win.wh();
        let p3 = vec2(b, a) * win.wh();
        let p4 = vec2(d, c) * win.wh();
        
        draw.scale_axes(vec3(1.0, -1.0, 1.0)).translate(vec3(win.w(), win.h(), 0.0) * -0.5)
        .line().points(p1, p2).color(rgba(1.0, 1.0, 1.0, (i / N as f32 * PI).sin()));
        draw.scale_axes(vec3(1.0, -1.0, 1.0)).translate(vec3(win.w(), win.h(), 0.0) * -0.5)
        .line().points(p3, p4).color(rgba(1.0, 1.0, 1.0, (i / N as f32 * PI).sin()));
    }
    
    draw.to_frame(app, &frame).unwrap();
}