drandrewthomas_codesnippets/processingjs/pjsbouncypde.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 xPos,yPos,xDir,yDir;
int halfball, ballsize;
int r,g,b,br,bg,bb,sr,sg,sb,or,og,ob,sw;

void setup()
{
  frameRate(30);
  setupBall();
}

void setupBall()
{
  ballsize=int(random(width/2)+5);
  halfball=ballsize/2;
  xPos=int(random(width-2*halfball)+halfball);
  yPos=int(random(height-2*halfball)+halfball);
  xDir=int(random(14)+1);
  yDir=int(random(14)+1);
  r=int(random(255));
  g=int(random(255));
  b=int(random(255));
  br=int(random(255));
  bg=int(random(255));
  bb=int(random(255));
  sr=int(random(255));
  sg=int(random(255));
  sb=int(random(255));
  or=int(random(255));
  og=int(random(255));
  ob=int(random(255));
  sw=int(random(halfball)+1);
}

void mouseReleased()
{
  setupBall();
}

void draw()
{
  background(br,bg,bb);
  stroke(or,og,ob);
  strokeWeight(sw*2);
  line(0,0,width,0);
  line(0,height,width,height);
  line(0,0,0,height);
  line(width,0,width,height);
  stroke(sr,sg,sb);
  strokeWeight(sw);
  fill(r,g,b);
  xPos+=xDir;
  yPos+=yDir;
  if(xPos<=halfball || xPos>=width-halfball) xDir*=-1;
  if(yPos<=halfball || yPos>=height-halfball) yDir*=-1;
  ellipse(xPos,yPos,ballsize,ballsize);
}

