‹ pakt02pakt04 ›

pakt03

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

use nannou::prelude::*;

const N: u16 = 50;

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 spreadx = (index * 0.005).sin();
    let spready = (index * 0.011).sin();
    let phaseshift = (index * 0.001).sin() * PI * 2.0;
    let wx = win.w() * 0.4 * ((index * 0.004).sin() * 0.45 + 0.55);
    let hy = win.h() * 0.4 * ((index * 0.004).sin() * 0.45 + 0.55);
    
    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.7, 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);
    }
    
    for i in 0..N {
        let i = i as f32;
        let r = (i / N as f32 * 30.0 + 1.0) * 2.0;
        
        let mut p = 0.0;
        let x = ((index + (i * spreadx)) * 0.05 + p).sin() * wx;
        let y = ((index + (i * spready)) * 0.05 + p).cos() * hy;
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .ellipse().x_y(x, y).w_h(r, r).color(rgba(1.0, 1.0, 1.0, 0.5));
        
        p += phaseshift;
        let x = ((index + (i * spreadx)) * 0.05 + p).sin() * wx;
        let y = ((index + (i * spready)) * 0.05 + p).cos() * hy;
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .ellipse().x_y(x, y).w_h(r, r).color(rgba(0.0, 0.0, 1.0, 0.5));
        
        /*
        p += phaseshift;
        let x = ((index + (i * spreadx)) * 0.05 + p).sin() * wx;
        let y = ((index + (i * spready)) * 0.05 + p).cos() * hy;
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .ellipse().x_y(x, y).w_h(r, r).color(rgba(0.0, 1.0, 0.0, 0.5));
        
        p += phaseshift;
        let x = ((index + (i * spreadx)) * 0.05 + p).sin() * wx;
        let y = ((index + (i * spready)) * 0.05 + p).cos() * hy;
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .ellipse().x_y(x, y).w_h(r, r).color(rgba(1.0, 0.0, 0.0, 0.5));
        
        p += phaseshift;
        let x = ((index + (i * spreadx)) * 0.05 + p).sin() * wx;
        let y = ((index + (i * spready)) * 0.05 + p).cos() * hy;
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .ellipse().x_y(x, y).w_h(r, r).color(rgba(0.0, 0.0, 0.0, 0.5));
        */
    }
    
    draw.to_frame(app, &frame).unwrap();
}