‹ pakt23pakt25 ›

pakt24

See /software/p5js/pakt-februari/pakt24/ for a JavaScript version and /software/supercollider/februari-pakt/pakt24/ for accompanying sound code.

use nannou::lyon;
use nannou::prelude::*;

const N: usize = 80;

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 rx = (index * 0.0012).sin();
  let ry = (index * 0.0022 + 1.0).sin();
  let tx = (index * 0.0032 + 2.0).sin() + rx;
  let ty = (index * 0.0042 + 3.0).sin() + ry;

  if frame.nth() == 0 {
    frame.clear(BLACK);
  } else {
    draw.rect().wh(win.wh()).color(rgba(1.0, 1.0, 1.0, 0.02));
  }

  let mut builder = nannou::geom::path::Builder::new().with_svg();
  builder.move_to(
    lyon::math::point(
      (-1.0 / N as f32 * 2.0 * PI + rx + tx).cos() * win.w(),
      (-1.0 / N as f32 * 2.0 * PI + ry + ty).sin() * win.h(),
    ) * 0.49
  );
  for i in 0..N {
    let t = i as f32 / N as f32 * 2.0 * PI;
    let x = t + rx + tx;
    let y = t + ry + ty;
    builder.quadratic_bezier_to(
      lyon::math::point(x.sin() * win.w(), y.cos() * win.h()) * 0.49,
      lyon::math::point(x.cos() * win.w(), y.sin() * win.h()) * 0.49,
    );
  }
  let path = builder.build();
  draw.scale_axes(vec3(1.0, -1.0, 1.0))
    .path()
    .stroke()
    .stroke_weight(0.75)
    .color(BLACK)
    .events(path.iter());

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