// Constrain // by REAS <http://reas.com> // Move the mouse across the screen to move the circle. // The program constrains the circle to its box. // Updated 20 January 2003 double mx; double my; double delay = 40.0; double eiSize = 25.0; int box = 30; public override void setup() { size(200, 200); noStroke(); smooth(); ellipseMode(CENTER_RADIUS); } public override void draw() { background(51); if(abs(mouseX - mx) > 0.1) { mx = mx + (mouseX - mx)/delay; } if(abs(mouseY - my) > 0.1) { my = my + (mouseY- my)/delay; } double distance = eiSize * 2; mx = constrain(mx, box+distance, width-box-distance); my = constrain(my, box+distance, height-box-distance); fill(76); rect(box+eiSize, box+eiSize, box*3, box*3); fill(255); ellipse(mx, my, eiSize, eiSize); }