‹ pakt28  

pakt29

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

use nannou::lyon::tessellation::LineCap;
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 cols = 20.0;
  let rows = 20;
  let index = app.time * 60.0;

  let oy = 0.025 * win.h();
  for x in 0..cols as u16 {
    let x = x as f32;
    let t = x / cols;
    let xx = t * win.w() + (0.5 / cols * win.w());
    let col = hsv(
      ((t * PI).sin() * 0.25 + (index * 0.0004 + (x * 0.02))) % 1.0,
      (t * PI).sin() * 0.4 + 0.4,
      (t * PI).sin() * 0.4 + 0.4,
    );
    let mut dashes = Vec::with_capacity(rows);
    for y in 0..rows as u16 {
      let d = ((index + y as f32)
        * (((index * 0.1 + (x * 0.35)) * 0.01).sin() * 0.015).sin())
      .sin()
        * 10.0
        + (((index + x) * 0.003).sin() * 40.0 + 70.0);
      dashes.push(d);
    }

    let off = index % (dashes[0] + dashes[1]);
    let mut yy = win.h() - oy;
    let mut i = 0 as usize;
    while yy > (win.h() * -0.5) {
      let d = dashes[i % rows];
      if i % 2 == 0 {
        let start = (yy + off).max(oy).min(win.h() - oy);
        let end = (yy - d + off).max(oy).min(win.h() - oy);
        draw.scale_axes(vec3(1.0, -1.0, 1.0))
          .translate(vec3(win.w(), win.h(), 0.0) * -0.5)
          .line()
          .points(pt2(xx, start), pt2(xx, end))
          .color(col)
          .weight(20.0)
          .caps(LineCap::Round);
      }
      yy -= d;
      i += 1;
    }
  }

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