‹ pakt12pakt14 ›

pakt13

See /software/p5js/pakt-februari/pakt13/ for a JavaScript version and /software/supercollider/februari-pakt/pakt13/ 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();
    frame.clear(BLACK);

    let rad = win.h();
    for angle in 0..360 {
        let angle = angle as f32;
        let mut points = Vec::with_capacity(3);
        points.push((pt2(0.0, 0.0), rgb(0.5, 0.6, 0.5)));

        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 rows = 11.0;
    let cols = 11.0;
    let mut builder = geom::path::Builder::new();
    for y in 0..=rows as u32 {
        let y = y as f32;
        for x in 0..=cols as u32 {
            let x = x as f32;
            let xx = x / rows * win.w() * 0.5 - 2.0;
            let yy = y / cols * win.h() * 0.5 - 2.0;
            let v = vec2(
                xx + (x * y + index).sin()
                    * (((index + x) * 0.0015).sin() + ((index + y) * 0.0062).sin() * 10.0),
                yy + (x * y + index).cos()
                    * (((index + y) * 0.0325).sin() + ((index + y) * 0.0072).sin() * 10.0),
            );
            builder = builder.polygon(&[
                pt2(v.x - xx, v.y - yy),
                pt2(v.x + xx, v.y - yy),
                pt2(v.x + xx, v.y + yy),
                pt2(v.x - xx, v.y + yy),
            ]);
        }
    }
    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(WHITE)
        .events(path.iter());

    draw.to_frame(app, &frame).unwrap();
}