I only checked left and upper border of the outer rect,
you need to do this also for x at the right border and y, lower border
Chrisir
float xo;
float yo;
void setup () {
size(800, 600);
smooth();
noStroke();
rectMode(CENTER);
xo=width/2-50;
yo=height/2;
}
void draw() {
background(0);
fill(255);
rect(width/2, height/2,
300, 300 );
translate (xo, yo);
fill(255, 0, 0);
rect( 0, 0, 100, 100 );
}
void mouseDragged() {
xo = xo + (mouseX - pmouseX);
yo = yo + (mouseY - pmouseY);
// you need to do the following also for x at the right border and y, lower border
if (xo < width/2-150+50) {
xo = width/2-150+50;
}
if (yo < height/2-150+50) {
yo = height/2-150+50;
}
}
//
For me that is left and above but not right and not below why?
and can i take a picture instead of the rectangle?
float xo;
float yo;
void setup () {
fullScreen();
smooth();
noStroke();
rectMode(CENTER);
xo=width/2-50;
yo=height/2;
}
void draw() {
background(0);
fill(255);
rect(width/2, height/2, displayWidth, displayHeight );
translate (xo, yo);
fill(255, 0, 0);
rect( 0, 0, 100, 100 );
}
void mouseDragged() {
xo = xo + (mouseX - pmouseX);
yo = yo + (mouseY - pmouseY);
// you need to do the following also for x at the right border and y, lower border
if (xo < width/2-640+50) {
xo = width/2-640+50;
}
if (yo < height/2-400+50) {
yo = height/2-400+50;
}
}