int SPACER = 10; int NUM_CIRCLES = 30; int CIRCLE_RADIUS = NUM_CIRCLES * SPACER / 2; int c1_x, c1_y, c2_x, c2_y; boolean PAUSE = false; int dx = 1; void setup() { textFont(loadFont("FreeSans-12.vlw"), 12); size(600,300); smooth(); noFill(); initStartingPositions(); } void mousePressed() { if (mouseButton == LEFT) { handleLeft(); } else if (mouseButton == RIGHT) { handleRight(); } else { togglePause(); } } void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { handleLeft(); } else if (keyCode == RIGHT) { handleRight(); } } else if (key == ' ') { togglePause(); } } void handleLeft() { dx = 1; if (PAUSE) redraw(); } void handleRight() { dx = -1; if (PAUSE) redraw(); } void togglePause() { PAUSE = !PAUSE; if (PAUSE) { noLoop(); drawMessage(); } else { loop(); } } void initStartingPositions() { c1_x = CIRCLE_RADIUS; c1_y = height/2; c2_x = width - CIRCLE_RADIUS; c2_y = c1_y; PAUSE = false; } void draw() { background(0); stroke(#FF0000, 155); drawCircle(c1_x, c1_y); stroke(#00AA00, 155); drawCircle(c2_x, c2_y); // Just have to bounds check circle 1 if (c1_x - CIRCLE_RADIUS < 0) { dx = 1; } else if (c1_x + CIRCLE_RADIUS > width) { dx = -1; } c1_x += dx; c2_x -= dx; if (PAUSE) { drawMessage(); } } void drawCircle(int orig_x, int orig_y) { for (int i=0;i