‹ pakt03 pakt05 ›

pakt04

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

use nannou::prelude::*;

const N: u16 = 90;

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 spreadx = (index * 0.005).sin() * 5.0;
  let spready = (index * 0.006).cos() * 5.0;
  let wx = (index * 0.0125).sin() * 0.4 + 0.6;
  let hy = (index * 0.01).cos() * 0.4 + 0.6;

  let rad = win.h();
  for angle in 0..360 {
    let angle = angle as f32;
    let mut points = Vec::with_capacity(3);
    points.push((pt2(0.0, 0.0), rgb(0.5, 0.7, 0.5)));

    let vx = angle.to_radians().cos();
    let vy = angle.to_radians().sin();
    points.push((pt2(vx, vy) * rad, rgb(0.0, 0.0, 0.0)));

    let next_vx = (angle + 1.0).to_radians().cos();
    let next_vy = (angle + 1.0).to_radians().sin();
    points.push((pt2(next_vx, next_vy) * rad, rgb(0.0, 0.0, 0.0)));

    draw.polygon().points_colored(points);
  }

  let points = (0..N + ((index * 0.00876).sin() * 50.0) as u16).map(|i| {
    let i = i as f32;
    pt2(
      ((index + (i * spreadx)) * 0.05).sin() * ((index + i) * 0.01).sin() * wx,
      ((index + (i * spready)) * 0.04).sin() * ((index + i) * 0.02).sin() * hy,
    ) * win.wh()
      * 0.49
  });
  draw.scale_axes(vec3(1.0, -1.0, 1.0))
    .polyline()
    .weight(3.0)
    .points(points)
    .color(rgba(1.0, 1.0, 1.0, 0.8));

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