‹ pakt28

pakt29

See /f0blog/pact-februari/

//pakt29
//almost ok - no wrapping at top of screen
int cols, rows, index;
float oy;
float[] dash;
void setup() {
  size(640, 480, JAVA2D);
  frameRate(60);
  colorMode(HSB, 255);
  smooth();
  strokeWeight(20);
  cols= 20;
  rows= 20;
  index= 0;
  oy= 0.025*height;
  dash= new float[rows];
}
void draw() {
  background(0);
  for (int x= 0; x<cols; x++) {
    float t= float(x)/cols;
    float 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 (int y= 0; y<rows; y++) {
      dash[y]= sin((index+y)*(sin((index*0.1+(x*0.35))*0.01)*0.015))*10.0+(sin((index+x)*0.003)*40.0+70.0);
    }
    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.
 */
void dashline(float x0, float y0, float x1, float y1, float[ ] spacing)
{
  float distance = dist(x0, y0, x1, y1);
  float [ ] xSpacing = new float[spacing.length];
  float [ ] ySpacing = new float[spacing.length];
  float drawn = 0.0;  // amount of distance drawn
  if (distance > 0)
  {
    int i;
    boolean 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
    }
  }
}