pakt12
See /software/p5js/pakt-februari/pakt12/ for a JavaScript version and /software/supercollider/februari-pakt/pakt12/ 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();
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.3, 0.3, 0.3)));
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 n = (index / 60.0 * 0.125).sin() * 150.0 + 200.0;
let mut builder = nannou::geom::path::Builder::new().with_svg();
for i in 0..n as u32 {
let ii = index + i as f32;
if i == 0 {
builder.move_to(lyon::math::point((0.5 / n as f32) * win.w(), 0.5 * win.h()));
} else if i % 3 == 1 {
let v = vec2(
i as f32 / n as f32,
((ii + 3.0) * ((index + 1.0) * 0.014).sin() * 0.02).sin()
* (ii * 0.015).sin()
* 0.225
+ 0.25,
);
builder.line_to(lyon::math::point(v.x * win.w(), v.y * win.h()));
} else if i % 3 == 2 {
let v = vec2(
i as f32 / n as f32,
((ii + 2.0) * ((index + 2.0) * 0.012).sin() * 0.02).sin()
* (ii * 0.020).sin()
* 0.225
+ 0.50,
);
builder.line_to(lyon::math::point(v.x * win.w(), v.y * win.h()));
} else {
let v = vec2(
i as f32 / n as f32,
((ii + 1.0) * ((index + 3.0) * 0.010).sin() * 0.02).sin()
* (ii * 0.025).sin()
* 0.225
+ 0.75,
);
builder.line_to(lyon::math::point(v.x * win.w(), v.y * win.h()));
}
}
builder.line_to(lyon::math::point((1.0 - (0.5 / n as f32)) * win.w(), 0.5 * win.h()));
builder.close();
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()
.fill()
.color(rgba(1.0, 1.0, 1.0, 0.7))
.events(path.iter());
draw.to_frame(app, &frame).unwrap();
}