import java.util.List; import java.util.Iterator; import java.util.ArrayList; List ripple_list; //list to store ripples float total_ripples; //number of ripples to be created float created_ripples; //number of ripples created so far float raddist; //the distance between ripples float radstep; //the speed radius increases float radmax; //the maximum radius int center_x = 200; int center_y = 200; void setup(){ size(400, 400); ripple_list = new ArrayList(); ellipseMode(CENTER_RADIUS); noFill(); frameRate(30); initialise(); } void initialise(){ raddist = 4; //the distance between ripples radstep = 1; //the speed radius increases radmax = 100; //the maximum radius total_ripples = 16; //number of ripples to be created created_ripples = 0; //number of ripples created so far } void mouseReleased(){ center_x = mouseX; center_y = mouseY; initialise(); } void mouseDragged(){ center_x = mouseX; center_y = mouseY; initialise(); } void draw(){ //black out background background(0, 0, 0); //used to calculate the minimum radius Ripple smallest = null; //do the ripple update Iterator iter = ripple_list.iterator(); while(iter.hasNext()){ //grow the ripple Ripple ripple = (Ripple) iter.next(); ripple.rad += radstep; //draw or remove depending on sign; if(ripple.rad > radmax){ iter.remove(); } else{ ripple.drawRipple(); } //check if this is the smallest if(smallest == null || smallest.rad > ripple.rad){ smallest = ripple; } } //if the smallest ripple is far enough out, then create a new one if(created_ripples < total_ripples && (smallest == null || smallest.rad > raddist)){ ripple_list.add(new Ripple()); created_ripples++; } } class Ripple { float x = center_x; float y = center_y; float rad = 0; float intensity = 1.0/(created_ripples + 1); void drawRipple(){ stroke((intensity * 255) * (radmax - rad)/radmax, 0, 0); ellipse(x, y, rad, rad); } }