drandrewthomas_codesnippets/processingjs/pjsrandomgraphpde.txt
/*************************************************/
/* This program is free software: you can        */
/* redistribute it and/or modify it under the    */
/* terms of the GNU General Public License       */
/* as published by the Free Software Foundation, */
/* either version 3 of the License, or (at your  */
/* option) any later version.                    */
/*                                               */
/* This program is distributed in the hope that  */
/* it will be useful, but WITHOUT ANY            */
/* WARRANTY; without even the implied            */
/* warranty of MERCHANTABILITY or FITNESS        */
/* FOR A PARTICULAR PURPOSE.  See the            */
/* GNU General Public License for more details.  */
/*                                               */
/* See http://www.gnu.org/licenses/ for full     */
/* details of licenses.                          */
/*************************************************/

int numSamples=0;
int samples[]=new int[105];
float xInc=0;
float yInc=0;
int yMin=0;
int yMax=100;
int pos=0;

void setup()
{
  frameRate(10);
  makeData();
}

void makeData()
{
  int c;
  numSamples=int(random(98)+2);
  for(c=0;c<numSamples;c++)
    samples[c]=int(random(100));
  xInc=float(width-50)/float(numSamples-1);
  yInc=float(height-50)/float((yMax-yMin));
}

void mouseReleased()
{
  makeData();
}

void draw()
{
  int c,x0,y0,x1,y1;
  background(255,255,255);
  stroke(0,0,0);
  strokeWeight(1);
  line(25,height-25,width-25,height-25);
  line(25,25,25,height-25);
  x0=25;
  y0=(height-25)-int(float(samples[0]-yMin)*yInc);
  for(c=1;c<numSamples;c++)
  {
    x1=25+int(float(c)*xInc);
    y1=(height-25)-int(float(samples[c]-yMin)*yInc);
    if(c<=pos) stroke(255,0,0);
    else stroke(150,150,150);
    line(x0,y0,x1,y1);
    x0=x1;
    y0=y1;
  }
  x1=25+int(float(pos)*xInc);
  y1=(height-25)-int(float(samples[pos]-yMin)*yInc);
  stroke(0,0,255);
  strokeWeight(2);
  fill(0,255,0);
  ellipse(x1,y1,10,10);
  pos++;
  if(pos>=numSamples) pos=0;
}

