pakt25
See /software/p5js/pakt-februari/pakt25/ for a JavaScript version and /software/supercollider/februari-pakt/pakt25/ for accompanying sound code.
use nannou::lyon;
use nannou::prelude::*;
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 n = ((index * 0.0006).sin() * 15.0 + 20.0) as i32;
if frame.nth() == 0 {
frame.clear(BLACK);
} else {
draw.rect().wh(win.wh()).color(rgba(0.0, 0.0, 0.0, 0.02));
}
let mut builder = nannou::geom::path::Builder::new().with_svg();
builder.move_to(lyon::math::point(0.0, win.h() * 0.5));
for i in 0..n {
let t = i as f32 / (n - 1) as f32;
builder.quadratic_bezier_to(
lyon::math::point(
(t - (0.5 / n as f32)) * win.w(),
((index * (index * 0.006).sin() * 0.02 + t).sin() * 0.5 + 0.5) * win.h(),
),
lyon::math::point(
t * win.w(),
((index * (index * 0.002).sin() * 0.02 + t).cos() * 0.5 + 0.5) * win.h(),
),
);
}
let path = builder.build();
draw.scale_axes(vec3(1.0, -1.0, 1.0))
.translate(vec3(win.w(), win.h(), 0.0) * -0.5)
.path()
.stroke()
.stroke_weight(0.5)
.color(WHITE)
.events(path.iter());
draw.to_frame(app, &frame).unwrap();
}