‹ pakt27 pakt29 ›

pakt28

See /software/p5js/pakt-februari/pakt28/ for a JavaScript version and /software/supercollider/februari-pakt/pakt28/ 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 index = app.time * 60.0;
  let n = (index * 0.0015).sin() * 30.0 + 35.0;

  for i in 0..n as u16 {
    let t = i as f32 / n * PI * 2.0;
    let a1 = ((((index * 0.0025 + t).sin() * 0.01 + 0.01) * index).sin() * 0.5 + 0.5).sin()
      * PI
      * 2.0;
    let a2 = ((a1 * index * 0.0005 + t).sin() * 0.5 + 0.5) * PI;
    let r = win.h() * 0.475 * (1.0 - i as f32 / n);
    let col = hsva(
      t.sin() * ((index * 0.01).sin() * 0.2) + 0.5,
      (index * 0.004).sin() * 0.3 + 0.7,
      1.0,
      1.0,
    );
    let mut builder = nannou::geom::path::Builder::new().with_svg();
    builder.move_to(lyon::math::point(a2.sin() * r, a2.cos() * r));
    builder.arc(
      lyon::math::point(0.0, 0.0),
      lyon::math::vector(r, r),
      lyon::math::Angle::radians(a1 - a2),
      lyon::math::Angle::radians(0.0),
    );
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0))
      .path()
      .stroke()
      .color(col)
      .weight((index * 0.0125 + t).sin() * 5.0 + 5.5)
      .events(path.iter());
  }

  draw.to_frame(app, &frame).unwrap();
}