float x = 0; float w = 100; void setup() { size(600,50); fill(255, 0, 0); stroke(0); rect(x, 0, w, height); } void draw() { background(0); if (mousePressed) if ((mouseButton == LEFT) && (mouseX >= x) && (mouseX <= x + w)) x += mouseX - pmouseX; if (x > width - w) x = width - w; if (x < 0) x = 0; rect(x, 0, w, height); }