‹ pakt15pakt17 ›

pakt16

See /software/p5js/pakt-februari/pakt16/ for a JavaScript version and /software/supercollider/februari-pakt/pakt16/ 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 radius1 = (index * 0.013).sin() * 0.3 + 0.1;
  let radius2 = (index * 0.021).sin() * 0.2 + 0.25;
  let radius3 = (index * 0.012).sin() * 0.1 + 0.4;
  let ex1 = (index * 0.0052).sin() * 3.0 + 3.0;
  let ex2 = (index * 0.0061).sin() * 6.0 + 6.0;
  let ex3 = (index * 0.0053).sin() * 2.0 + 2.0;
  let n = (index * 0.001).sin() * 40.0 + 50.0;

  for i in 0..n as u16 {
    let i = i as f32;
    let t = (i / n) * PI * 2.0;
    let mut builder = nannou::geom::path::Builder::new().with_svg();
    builder.move_to(lyon::math::point((t + ex1).sin() * win.w(), (t + ex1).cos() * win.h()) * radius1);
    builder.quadratic_bezier_to(
      lyon::math::point((t + ex2).sin() * win.w(), (t + ex2).cos() * win.h()) * radius2,
      lyon::math::point((t + ex3).sin() * win.w(), (t + ex3).cos() * win.h()) * radius3,
    );
    let a = ((index + (i * (index * 0.008 + (i * (index * 0.013).sin() * 0.01)).sin() * 2.0))
      * 0.1)
      .sin()
      * 0.5
      + 0.5;
    let path = builder.build();
    draw.scale_axes(vec3(1.0, -1.0, 1.0))
      .path()
      .stroke()
      .color(rgba(1.0, 1.0, 1.0, a))
      .weight(1.0)
      .events(path.iter());
  }

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