‹ pakt19pakt21 ›

pakt20

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

use nannou::prelude::*;

const N: u16 = 150;

fn main() {
  nannou::sketch(view).size(640, 480).run();
}

fn view(app: &App, frame: Frame) {
  let draw = app.draw();
  let win = app.window_rect();

  if frame.nth() == 0 {
    frame.clear(BLACK);
  }

  let index = app.time * 60.0;
  let spread = (index * 0.002).sin();

  for i in 0..N {
    let i = i as f32;
    let tx = (0.012 * (index + (i * spread))).sin();
    let ty = (0.014 * (index + (i * spread))).sin();
    let tz = (0.016 * (index + (i * spread))).sin() * 0.5 + 0.5;

    let p = pt2(
      (tx + (index * 0.001).sin()).sin() * (tx.sin() * 0.001 + 1.0),
      (ty + (index * 0.001 * i).cos()).sin() * (ty.cos() * 0.001 + 1.0),
    ) * win.wh()
      * 0.46;
    let q = pt2(
      (ty + (index * 0.001).sin()).cos() * (tx.sin() * 0.001 + 1.0),
      (tx + (index * 0.001 * i).cos()).sin() * (ty.cos() * 0.001 + 1.0),
    ) * win.wh()
      * 0.36;

    draw.scale_axes(vec3(1.0, -1.0, 1.0))
      .line()
      .points(p, q)
      .color(rgba(tz, tz * 0.9, tz, 0.05));
  }

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