‹ pakt11pakt13 ›

pakt12

See /software/p5js/pakt-februari/pakt12/ for a JavaScript version and /software/supercollider/februari-pakt/pakt12/ 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 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.3, 0.3, 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);
    }
    
    let index = app.time * 60.0;
    let n = (index / 60.0 * 0.125).sin() * 150.0 + 200.0;
    let mut builder = geom::path::Builder::new();
    for i in 0..n as u32 {
        let ii = index + i as f32;
        if i == 0 {
            builder = builder.move_to(pt2(0.5 / n as f32, 0.5) * win.wh());
        } else if i % 3 == 1 {
            let v = vec2(
                i as f32 / n as f32,
                ((ii + 3.0) * ((index + 1.0) * 0.014).sin() * 0.02).sin() * (ii * 0.015).sin() * 0.225 + 0.25,
            );
            builder = builder.line_to(v * win.wh());
        } else if i % 3 == 2 {
            let v = vec2(
                i as f32 / n as f32,
                ((ii + 2.0) * ((index + 2.0) * 0.012).sin() * 0.02).sin() * (ii * 0.020).sin() * 0.225 + 0.50,
            );
            builder = builder.line_to(v * win.wh());
        } else {
            let v = vec2(
                i as f32 / n as f32,
                ((ii + 1.0) * ((index + 3.0) * 0.010).sin() * 0.02).sin() * (ii * 0.025).sin() * 0.225 + 0.75,
            );
            builder = builder.line_to(v * win.wh());
        }
        
    }
    builder = builder.line_to(vec2(1.0 - (0.5 / n as f32), 0.5) * win.wh());
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0)).translate(vec3(win.w(), win.h(), 0.0) * -0.5)
    .path().fill().color(rgba(1.0, 1.0, 1.0, 0.7)).events(path.iter());
    
    draw.to_frame(app, &frame).unwrap();
}