/* In this example, the user can draw a rectangle by selecting one corner and then dragging the mouse to the opposite corner. */ int x,y; // This function is executed only once, at the very beginning void setup() { size(500,400); background(255); fill(128, 128, 255); } // This function is repeatedly call in an implicit loop. // A single call is responsible for drawing a single frame. void draw() { } void mousePressed() { x = mouseX; y = mouseY; } void mouseDragged() { background(255); noFill(); int w = abs(mouseX-x); int h = abs(mouseY-y); rect(min(x,mouseX), min(y,mouseY), w, h); } void mouseReleased() { background(255); fill(128,128,255); int w = abs(mouseX-x); int h = abs(mouseY-y); rect(min(x,mouseX), min(y,mouseY), w, h); }