‹ pakt06pakt08 ›

pakt07

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

use nannou::prelude::*;

const N: u16 = 30;

fn main() {
    nannou::app(model).update(update).simple_window(view).size(640, 480).run();
}
struct Model {
    theta: f32,
    speed: f32,
    spread: f32,
    points: Vec<Vector2>,
}
fn model(_app: &App) -> Model {
    let theta = 0.0;
    let speed = 0.00002;
    let spread = 1.0;
    let mut points = vec![];
    for _i in 0..N {
        points.push(pt2(0.0, 0.0));
    }
    Model { theta, speed, spread, points }
}
fn update(app: &App, model: &mut Model, _update: Update) {
    let win = app.window_rect();
    for (i, p) in model.points.iter_mut().enumerate() {
        let i = i as f32;
        let x = p.x / win.w();
        let y = p.y / win.h();
        p.x = (((model.theta + (i * 0.001)).cos() * x) - (((model.theta + (i * 0.001)).sin() * y))) * win.w() + model.spread;
        p.y = (((model.theta + (i * 0.001)).cos() * y) + (((model.theta + (i * 0.001)).sin() * x))) * win.h() + model.spread;
        model.theta += model.speed;
    }
}
fn view(app: &App, model: &Model, frame: Frame) {
    let draw = app.draw();
    draw.background().color(BLACK);
    for p in model.points.iter() {
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
        .color_blend(BLEND_SUBTRACT).ellipse().xy(*p).radius(50.0).color(RED);
    }
    
    draw.to_frame(app, &frame).unwrap();
}