> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.dZQhYMb4SZe/rev.20
 * 
 * authors: 
 *   GoToLoop

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



/**
 * Wave Trios (v1.40)
 * by  GoToLoop (2014/Jun)
 * for Costi6
 *
 * forum.Processing.org/two/discussion/5615/
 * coding-noob-needs-help-how-do-i-draw-an-expanding-circle-
 * that-triggers-with-a-mouse-click
 *
 * studio.ProcessingTogether.com/sp/pad/export/ro.9lTJ6qSlmCidk/latest
 */

static final boolean ONLINE = 1/2 == 1/2.;

static final short DIAM = 050, GROWTH = 6;
static final short FPS  = 60, QUALITY = 0;
static final color BG = #BAE5FF;

import java.util.List;
final List<WaveTrio> trios = new ArrayList();

void setup() {
  size(600, 600);

  frameRate(FPS);
  smooth(QUALITY);
  ellipseMode(CENTER);

  noFill();
  stroke(Wave.OUTLINE);
  strokeWeight(Wave.WEIGHT);
}

void draw() {
  background(BG);

  for (int len = trios.size(), i = len; i-- != 0; )
    if (trios.get(i).script()) {
      trios.set(i, trios.get(--len));
      trios.remove(len);
    }

  if (!ONLINE)  frame.setTitle("Wave Trios: #" + nf(trios.size(), 2)
    + "\t\tFrame Rate: #" + round(frameRate));
}

void mousePressed() {
  trios.add(new WaveTrio(mouseX, mouseY, DIAM, ceil(random(1, GROWTH))));
}

class WaveTrio {
  final List<Wave> waves =
    ONLINE? new ArrayList() : new ArrayList(3);

  WaveTrio(int x, int y, int d, int e) {
    for (int i = 0; i != 3; waves.add(new Wave(x, y, d << i++, e)));
  }

  boolean script() {
    for (int i = waves.size(); i-- != 0; )
      if (waves.get(i).script())  waves.remove(i);

    return waves.size() == 0;
  }
}

class Wave {
  static final color OUTLINE = #10A0FA;
  static final float WEIGHT  = 2.0, LIMIT = 1.3;

  final short x, y; // coords. (x & y)
  short d;          // diameter
  final short e;    // expansion

  Wave(int xx, int yy, int dd, int ee) {
    x = (short) xx;
    y = (short) yy;
    d = (short) dd;
    e = (short) ee;
  }

  boolean script() {
    update();
    display();
    return gotTooBig();
  }

  void update() {
    d += e;
  }

  void display() {
    ellipse(x, y, d, d);
  }

  boolean gotTooBig() {
    return d > width*LIMIT;
  }
}