> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://bard117s14.sketchpad.cc/sp/pad/view/ro.fc5NMgTGObW/rev.20
 * 
 * authors: 
 *   Paula Van Erven
 *   Sam Robotham
 *   Keith O'Hara

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



class Particle {

  float x;  // x coordinate
  float y;  // y coordinate
  float dx; // x speed
  float dy; // y speed
  float r;  // radius
  color c;  // color

  Particle() {
    x = random(width);
    y = random(height);
    dx = random(-2, 2);
    dy = random(-2, 2);
    r = random(8);
    colorMode(HSB);
    c = color(random(0, 30), 100, 100);
  }

  void step() {
    x = x + dx;
    y = y + dy;
    x = constrain(x, r, width - r);
    y = constrain(y, r, height - r);
    bounce();
  }

  void show() {
    rectMode(CENTER);
    fill(c);
    noStroke();
    ellipse(x, y, r*2, r*2);
  }

  void bounce() {
    if (x <= r || x >= width-r) {
      // left and right wall
      dx = -1 * dx;
    }
    if (y <= r || y >= height-r) {
      // top and bottom wall
      dy = -1 * dy;
    }
  }
}