/* Sketch that uses conditional to determine whether a mouse press lies within a circle. If so, the circle is recolored. Otherwise, the mouse press is ignored. Author: Michael Goldwasser */ float cx, cy, r; // parameters for circle center (x,y) and radius void setup() { size(500, 400); cx = 0.5*width; cy = 0.5*height; r = 0.25*min(width,height); fill(random(255), random(255), random(255)); ellipse(cx, cy, 2*r, 2*r); } void draw() { // nothing to do here (but function must be given) } void mousePressed() { // compute square of distance from mouse press to circle center if (dist(mouseX, mouseY, cx, cy) <= r) { // click is within circle fill(random(255), random(255), random(255)); ellipse(cx, cy, 2*r, 2*r); } }