# Proper wraparound

**URL:** <https://discourse.processing.org/t/proper-wraparound/8702>\
**Category:** Coding Questions\
**Created:** [February 24, 2019, 10:48pm UTC](https://discourse.processing.org/t/proper-wraparound/8702 "2019-02-24T22:48:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordCacops](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lordcacops/32/2280_2.png) [@LordCacops](https://discourse.processing.org/u/LordCacops)\
**Post date:** [February 24, 2019, 10:48pm UTC](https://discourse.processing.org/t/proper-wraparound/8702/1 "2019-02-24T22:48:00Z")

</div>

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?

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

```

Thank you.  
Cacops

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 25, 2019, 1:15am UTC](https://discourse.processing.org/t/proper-wraparound/8702/2 "2019-02-25T01:15:59Z")

</div>

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.

```auto
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; } 
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [February 26, 2019, 5:11pm UTC](https://discourse.processing.org/t/proper-wraparound/8702/3 "2019-02-26T17:11:26Z")

</div>

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?
