int width = 800; int height = 600; int diameter = 100; int margin = (int) (1.5 * diameter); // initial count of dots int dotCount = 30; // each of the initial dots will be somewhere in the spectrum between these two colors color color1 = #9966FF; color color2 = #00FA9A; // this is the color for all dots added by mouse click color colorForNew = #CC0000; // initialize arrays to hold coordinates, colors, and timers for each dot // these are grown by one inside of mousePressed() int[] xCoords = new int[dotCount]; int[] yCoords = new int[dotCount]; color[] colors = new color[dotCount]; int[] xTimers = new int[dotCount]; int[] yTimers = new int[dotCount]; void setup() { size(width, height); frameRate(30); // setup the initial random dot coordinates, colors, and timers // the random timers create nonuniform movement for each dot for (int i = 0; i < dotCount; i++) { xCoords[i] = (int) (random(0, 1) * (width - 2 * margin) + margin); yCoords[i] = (int) (random(0, 1) * (height - 2 * margin) + margin); colors[i] = lerpColor(color1, color2, random(0,1)); xTimers[i] = int(random(100)); yTimers[i] = int(random(100)); } } void draw() { background(255); smooth(); noStroke(); for (int i = 0; i < dotCount; i++) { fill(colors[i], 128); int xWobble = (int) ((sin(xTimers[i] / 16.0)) * 50); int yWobble = (int) ((cos(yTimers[i] / 22.0)) * 50); ellipse(xCoords[i] + xWobble, yCoords[i] + yWobble, diameter, diameter); xTimers[i]++; yTimers[i]++; } } void mousePressed() { // each mouse click adds one additional dot dotCount++; // grow each array to the new size of dotCount int xCoordsNew[] = new int[dotCount]; int yCoordsNew[] = new int[dotCount]; color[] colorsNew = new color[dotCount]; int[] xTimersNew = new int[dotCount]; int[] yTimersNew = new int[dotCount]; xCoordsNew[dotCount - 1] = mouseX; yCoordsNew[dotCount - 1] = mouseY; colorsNew[dotCount - 1] = colorForNew; xTimersNew[dotCount - 1] = int(random(100)); yTimersNew[dotCount - 1] = int(random(100)); for (int i = 0; i < (dotCount - 1); i++) { xCoordsNew[i] = xCoords[i]; yCoordsNew[i] = yCoords[i]; colorsNew[i] = colors[i]; xTimersNew[i] = xTimers[i]; yTimersNew[i] = yTimers[i]; } xCoords = xCoordsNew; yCoords = yCoordsNew; colors = colorsNew; xTimers = xTimersNew; yTimers = yTimersNew; }