‹ pakt28

pakt29


pact29wrap, 01:00, 1.84MB

Built with p5.js and SuperCollider. See /f0blog/pact-februari/

//pakt29
//almost ok - no wrapping at top of screen
let cols, rows, index;
let oy;
let dash= [];
function setup() {
  let div= select('#sketch');
  let cnv= createCanvas(div.width, div.height);
  cnv.parent('sketch');
  colorMode(HSB, 255);
  strokeWeight(20);
  cols= 20;
  rows= 20;
  index= 0;
  oy= 0.025*height;
  dash= [];
}
function draw() {
  background(0);
  for(let x= 0; x<cols; x++) {
    let t= x/cols;
    let xx= t*width+(0.5/cols*width);
    stroke(color(((sin(t*PI)*0.25+(index*0.0004+(x*0.02)))*255)%255, map(sin(t*PI), -1, 1, 0, 127), map(sin(t*PI), -1, 1, 0, 255)));
    for(let y= 0; y<rows; y++) {
      dash[y]= sin((index+y)*(sin((index*0.1+(x*0.35))*0.01)*0.015))*10+(sin((index+x)*0.003)*40+70);
    }
    dashline(xx, oy, xx, height-oy, dash);
  }
  index++;
}
//dashed line routine by J David Eisenberg
/*
* Draw a dashed line with given set of dashes and gap lengths.
* x0 starting x-coordinate of line.
* y0 starting y-coordinate of line.
* x1 ending x-coordinate of line.
* y1 ending y-coordinate of line.
* spacing array giving lengths of dashes and gaps in pixels;
*  an array with values {5, 3, 9, 4} will draw a line with a
*  5-pixel dash, 3-pixel gap, 9-pixel dash, and 4-pixel gap.
*  if the array has an odd number of entries, the values are
*  recycled, so an array of {5, 3, 2} will draw a line with a
*  5-pixel dash, 3-pixel gap, 2-pixel dash, 5-pixel gap,
*  3-pixel dash, and 2-pixel gap, then repeat.
*/
function dashline(x0, y0, x1, y1, spacing)
{
  let distance = dist(x0, y0, x1, y1);
  let xSpacing = [];
  let ySpacing = [];
  let drawn = 0.0;  // amount of distance drawn
  if (distance > 0)
  {
    let i;
    let drawLine = true; // alternate between dashes and gaps
    /*
    Figure out x and y distances for each of the spacing values
    I decided to trade memory for time; I'd rather allocate
    a few dozen bytes than have to do a calculation every time
    I draw.
    */
    for (i = 0; i < spacing.length; i++)
    {
      xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance);
      ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance);
    }
    i = 0;
    while (drawn < distance)
    {
      if (drawLine)
      {
        line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]);
      }
      x0 += xSpacing[i];
      y0 += ySpacing[i];
      /* Add distance "drawn" by this line or gap */
      drawn = drawn + mag(xSpacing[i], ySpacing[i]);
      i = (i + 1) % spacing.length;  // cycle through array
      drawLine = !drawLine;  // switch between dash and gap
    }
  }
}
Ndef(\wrap).play
(
Ndef(\wrap, {var n= 29; Splay.ar({|i|
  var w= i+LFSaw.ar(i+1*SinOsc.ar(0.1, i/n*2pi, 1, 0.1), 0, 2, 2);
  Saw.ar(340+LFSaw.ar(0.1, i/n, 10, 10).round(20)+i)%Saw.ar(60+w, SinOsc.ar(0.01, i/n*2pi, 2, 2.05))*0.25;
}!n)});
)
Ndef(\wrap).stop