float x,y,w,h; float ox, oy, ow, oh; void setup(){ size(1000,600); rectMode(RADIUS); colorMode(HSB,360,100,100); x = width / 2; y = height / 2; w = width / 20; h = height / 5; ox = width / 2; oy = height / 2; ow = width / 2 - 120; oh = height / 2 - 120; } void draw(){ background(0); noStroke(); fill(30,20,90); rect(ox,oy,ow,oh); fill(240,30,60); rect(x,y,w,h); } void mouseDragged(){ if( ox - ow <= mouseX - w && mouseX + w <= ox + ow ) { x = mouseX; } if( oy - oh <= mouseY - h && mouseY + h <= oy + oh ) { y = mouseY; } if( mouseX - w < ox - ow ) { x = ox - ow + w; } else if( ox + ow < mouseX + w ) { x = ox + ow - w; } if( mouseY - h < oy - oh ) { y = oy - oh + h; } else if( oy + oh < mouseY + h ) { y = oy + oh - h; } }