pakt00
See /software/p5js/pakt-februari/pakt00/ for a JavaScript version and /software/supercollider/februari-pakt/pakt00/ for accompanying sound code.
use nannou::lyon;
use nannou::prelude::*;
const N: u16 = 120;
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(1.0, 1.0, 0.8)));
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 = nannou::geom::path::Builder::new().with_svg();
for i in 0..N {
let i = i as f32;
let start = ((index + i) * 0.006 + i).sin() * PI;
let end = ((index + i) * 0.0123 + i).sin() * PI * 2.0;
if start < end {
let r = (index * 0.01 + i).sin() * 70.0 + 75.0;
let x = start.sin() * r;
let y = start.cos() * r;
builder.move_to(lyon::math::point(x, y));
builder.arc(
lyon::math::point(0.0, 0.0),
lyon::math::vector(r, r),
lyon::math::Angle::radians(start - end),
lyon::math::Angle::radians(0.0),
);
} else {
let r = (index * 0.01 + i).sin() * 50.0 + 55.0;
let ox = (i * 0.21).sin() * win.w() * 0.25;
let oy = (i * 0.2).cos() * win.h() * 0.25;
let x = start.sin() * r;
let y = start.cos() * r;
builder.line_to(lyon::math::point(x + ox, y + oy));
builder.arc(
lyon::math::point(ox, oy),
lyon::math::vector(r, r),
lyon::math::Angle::radians(end - start),
lyon::math::Angle::radians(0.0),
);
}
builder.move_to(lyon::math::point(0.0, 0.0));
}
builder.close();
let path = builder.build();
draw.scale_axes(vec3(1.0, -1.0, 1.0))
.path()
.stroke()
.color(rgb(1.0, 1.0, 0.8))
.events(path.iter());
draw.to_frame(app, &frame).unwrap();
}