pakt01
See /software/p5js/pakt-februari/pakt01/ for a JavaScript version and /software/supercollider/februari-pakt/pakt01/ for accompanying sound code.
use nannou::lyon;
use nannou::prelude::*;
const N: u16 = 75;
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 index = app.time * 60.0;
let yellow = (index * 0.0005).sin() * 0.3 + 0.65;
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, yellow)));
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 xx = (i * 0.2).cos() * win.w() * 0.25;
let yy = (i * 0.15).sin() * win.h() * 0.25;
let start = (index * ((i + 1.0) * 0.00006)).cos() * 2.0 * PI;
let end = (index * ((i * 1.0) * 0.00008)).sin() * 2.0 * PI;
let size = (index * 0.01 + i).sin() * 50.0 + 58.0;
let col = rgba(
xx / win.w() + 0.5,
yy / win.h() + 0.5,
yellow,
(end / 2.0 * PI).max(0.0).min(1.0),
);
let mut builder = nannou::geom::path::Builder::new().with_svg();
let ox = end.sin() * size;
let oy = end.cos() * size;
builder.move_to(lyon::math::point(xx + ox, yy - oy));
builder.arc(
lyon::math::point(xx, yy),
lyon::math::vector(size, size),
lyon::math::Angle::radians(end),
lyon::math::Angle::radians(start),
);
let path = builder.build();
draw.scale_axes(vec3(1.0, -1.0, 1.0))
.path()
.stroke()
.color(col)
.weight(i / 8.0 + 4.0)
.events(path.iter());
}
draw.to_frame(app, &frame).unwrap();
}