‹ pakt14 pakt16 ›

pakt15

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

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

const N: u16 = 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();
  frame.clear(BLACK);

  let index = app.time * 60.0;
  let speed = 0.005;
  for i in 0..=N {
    let i = i as f32;
    let mut builder = nannou::geom::path::Builder::new().with_svg();
    builder.move_to(lyon::math::point(((index * 0.1) + (i * 0.3)).sin() * 0.3 * win.w(), 0.0));
    builder.line_to(
      lyon::math::point(
        (((index + i) * 0.0144).sin() * 0.03 + 0.26) * win.w(),
        (((index + i) * 0.0126).cos() * 0.03 + 0.26) * win.h(),
      ),
    );
    builder.line_to(
      lyon::math::point(
        (((index + i) * 0.0244).sin() * 0.02 + 0.07) * win.w(),
        (((index + i) * 0.0226).cos() * 0.02 + 0.07) * win.h(),
      ),
    );
    builder.close();
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0))
      .rotate((i / N as f32 * PI * 2.0 + index * (index * speed).sin() * 0.0001) * i)
      .path()
      .stroke()
      .color(rgba(1.0, ((index + i) * 0.1).sin() * 0.5 + 0.5, 1.0, 0.5))
      .weight(1.0)
      .events(path.iter());
  }

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