pakt01 ›

pakt00

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

use nannou::prelude::*;

const N: u16 = 120;

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 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(1.0, 1.0, 0.8)));
        
        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);
    }
    
    let index = app.time * 60.0;
    let mut builder = geom::path::Builder::new();
    for i in 0..N {
        let i = i as f32;
        let start= ((index + i) * 0.006 + i).sin() * PI;
        let end= ((index + i) * 0.0123 + i).sin() * PI * 2.0;
        
        if start < end {
            let r = (index * 0.01 + i).sin() * 70.0 + 75.0;
            let x = start.sin() * r;
            let y = start.cos() * r;
            builder = builder.move_to(pt2(x, y)).arc(pt2(0.0, 0.0), vec2(r, r), start-end, 0.0);
        } else {
            let r = (index * 0.01 + i).sin() * 50.0 + 55.0;
            let ox = (i * 0.21).sin() * win.w() * 0.25;
            let oy = (i * 0.2).cos() * win.h() * 0.25;
            let x = start.sin() * r;
            let y = start.cos() * r;
            builder = builder.line_to(pt2(x + ox, y + oy)).arc(pt2(ox, oy), vec2(r, r), end-start, 0.0);
        }
        builder = builder.move_to(pt2(0.0, 0.0));
    }
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0)).path().stroke().color(rgb(1.0, 1.0, 0.8)).events(path.iter());
    
    draw.to_frame(app, &frame).unwrap();
}