Proper wraparound

Hey!

I have these colored grids, 192 pixels wide, 120 pixels tall, and they move. I want them to wraparound the horizontal dimension so that when they start going out one side, right away they start popping out of the other.

Instead what I am getting is this “shadow region” where they disappear until their entire bodies are gone on either side, and only then they start popping out through the other.

Map is 1921 pixels wide. I don’t know if that’s relevant.

Here is the function I’m using. How can I make it go from what its doing now to what I want it to do?

    if (location.x > width) {
      location.x = - 192;
    } else if (location.x < - 192) {
      location.x = width;
    }

Thank you.
Cacops

you can not wrap around one object unless you deal with it pix by pix,

but what you can do is while moving out on the right side
move in from the left side a SECOND object.

int posx, cr = 20, dir = 1;
boolean wrap;

void setup() {
 size(200,200);
}

void draw(){
  background(200,200,0);
  stroke(0,200,0);
  fill(200,0,200);
  circle(posx,height/2,2*cr);
  if ( wrap ) circle(posx-width,height/2,2*cr);
  move();
}

void move() {
 posx += dir;
 if ( posx > width-cr )                 wrap = true;
 if ( posx > width+cr )    { posx = cr; wrap = false; } 
}

1 Like

Are these grid lines, like lat/long on a map?

Do they wrap around in all four directions, or is the movement only in one or two directions?