int x1, x2, y1, y2; int boxWidth=250; int boxHeight=250; int boxX=100; int boxY=100; int r=150; int g=140; int b=180; void setup(){ size(500,500); } void draw() { // Setup the background. fill(0,0,250,10); rect(0,0,width,height); // Setup the motion. x1 = int(random(6)-3); x2 = int(random(6)-3); y1 = int(random(6)-3); y2 = int(random(6)-3); // Changing colour assignment. r += int(random(4)-2); g += int(random(4)-2); b += int(random(4)-2); // Draw the box. fill(r,g,b); rect(boxX,boxY,boxWidth,boxHeight); } void mouseDragged() { // Check if the left mouse button is pressed and do the following. if (mousePressed && (mouseButton == LEFT)) { boxX = mouseX - (boxWidth/2); boxY = mouseY - (boxHeight/2); boxWidth += x2; boxHeight += y2; } // Check if the right mouse button is pressed and do the following. else if (mousePressed && (mouseButton == RIGHT)) { boxX += x1; boxY += y1; boxWidth = mouseX; boxHeight = mouseY; } }