‹ pakt04pakt06 ›

pakt05

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

use nannou::prelude::*;

const N: u16 = 100;

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.0012).sin() * 20.0;
    let speed1 = (index * 0.0013).sin() * 0.001 + 0.005;
    let speed2 = (index * 0.0014).sin() * 0.001 + 0.0005;
    let speed3 = (index * 0.0015).sin() * 0.001 + 0.014;
    let speed4 = (index * 0.0016).sin() * 0.001 + 0.012;
    
    let rad = win.h();
    for angle in 0..360 {
        let angle = angle as f32;
        let mut points = Vec::new();
        points.push((pt2(0.0, 0.0), rgb(0.5, 0.4, 0.3)));
        
        let vx = angle.to_radians().cos();
        let vy = angle.to_radians().sin();
        points.push((pt2(vx, vy) * rad, rgb(0.0, 0.0, 0.0)));
        
        let next_vx = (angle + 1.0).to_radians().cos();
        let next_vy = (angle + 1.0).to_radians().sin();
        points.push((pt2(next_vx, next_vy) * rad, rgb(0.0, 0.0, 0.0)));
        
        draw.polygon().points_colored(points);
    }
    
    for i in 0..N {
        let i = i as f32;
        let p = pt2(
            (index * i * speed1).sin() + (index * i * speed2).sin() * win.w() * 0.3 - i,
            ((index + (i * spread)) * speed3).sin() * ((index + i) * speed4).sin() * win.h() * 0.275 + i,
        );
        let q = pt2(p.x + (N as f32 - i), p.y + (i - N as f32));
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .line().points(q, p).color(rgba(1.0, 1.0, 1.0, 0.8)).weight(1.0);
    }
    
    draw.to_frame(app, &frame).unwrap();
}