‹ pakt13pakt15 ›

pakt14

See /software/p5js/pakt-februari/pakt14/ for a JavaScript version and /software/supercollider/februari-pakt/pakt14/ 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 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.5, 0.6)));
        
        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 ii = i as f32;
        let spreadx = ((ii + index) * 0.011).sin() * ((ii + index) * 0.013).sin();
        let spready = ((ii + index) * 0.012).sin() * ((ii + index) * 0.014).sin();
        let spread = spreadx * spready * 0.25 + ((index + ii) * 0.001).cos();
        
        let mut yy = ((ii + index) * 0.012 + spready).sin();
        let mut hh = yy * (index * 0.013).cos();
        let mut xx = ((ii + index) * 0.014 + spreadx).cos();
        let mut ww = xx * (index * 0.015).sin();
        yy *= win.h() * spread + (win.h() * 0.5);
        xx *= win.h() * spread + (win.h() * 0.5);
        hh *= win.h() * spread + (win.h() * 0.5);
        ww *= win.h() * spread + (win.h() * 0.5);
        if i == 0 {
            builder = builder.move_to(pt2(xx, yy));
        } else if i % 5 == 1 {
            builder = builder.quadratic_bezier_to(pt2(xx, yy), pt2(ww, hh));
        } else if i % 5 == 2 {
            builder = builder.quadratic_bezier_to(pt2(yy, xx), pt2(hh, ww));
        } else if i % 5 == 3 {
            builder = builder.quadratic_bezier_to(pt2(xx, yy), pt2(hh, ww));
        } else if i % 5 == 4 {
            builder = builder.quadratic_bezier_to(pt2(yy, xx), pt2(ww, hh));
        } else {
            builder = builder.move_to(pt2(yy, xx));
        }
    }
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0))
    .path().fill().color(rgba(1.0, 1.0, 1.0, 0.85)).events(path.iter());
    
    draw.to_frame(app, &frame).unwrap();
}