pakt11
See /software/p5js/pakt-februari/pakt11/ for a JavaScript version and /software/supercollider/februari-pakt/pakt11/ for accompanying sound code.
use nannou::lyon;
use nannou::prelude::*;
fn main() {
nannou::app(model)
.update(update)
.simple_window(view)
.size(640, 480)
.run();
}
struct Model {
index: f32,
rows_mid: f32,
cols_mid: f32,
}
fn model(_app: &App) -> Model {
let index = 0.0;
let rows_mid = 22.0;
let cols_mid = 20.0;
Model {
index,
rows_mid,
cols_mid,
}
}
fn update(app: &App, model: &mut Model, _update: Update) {
model.index = app.time * 60.0;
}
fn view(app: &App, model: &Model, 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.6, 0.5, 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 rows = model.rows_mid + ((model.index * 0.0015).sin() * 10.0);
let cols = model.cols_mid + ((model.index * 0.0024).sin() * 10.0);
let mut builder = nannou::geom::path::Builder::new().with_svg();
builder.move_to(lyon::math::point(0.0, 0.0));
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 p = pt2(
(x / rows * win.w()) + (model.index + (x * y) * 32.0).sin(),
(y / cols * win.h()) + (model.index + (x * y) * 24.0).cos(),
);
builder.line_to(lyon::math::point(p.x, p.y));
let p = pt2(
(x / cols * win.w()) + (model.index + (x * y) * 32.0).sin(),
(y / rows * win.h()) + (model.index + (x * y) * 24.0).cos(),
);
builder.line_to(lyon::math::point(p.x, p.y));
}
}
builder.close();
let path = builder.build();
draw.scale_axes(vec3(0.96, -0.96, 1.0))
.translate(vec3(win.w() * -0.5 - 5.0, win.h() * -0.5 - 5.0, 0.0))
.path()
.fill()
.color(WHITE)
.events(path.iter());
draw.to_frame(app, &frame).unwrap();
}