# Moved PImage from one side to the screen to another in loop

**URL:** <https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194>\
**Category:** Coding Questions\
**Created:** [January 19, 2021, 9:41am UTC](https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194 "2021-01-19T09:41:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mchangxe](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mchangxe](https://discourse.processing.org/u/mchangxe)\
**Post date:** [January 19, 2021, 9:41am UTC](https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194/1 "2021-01-19T09:41:58Z")

</div>

Hi guys,

i want to move an image across the screen from right to the left. However, one complication is that when part of the image moves beyond the left side of the screen, i want it to show up on the right side of the screen. The final result should be a image moving in a continuous loop across the screen.

Currently what i am doing is check if the image’s x coordinate is smaller than 0, and then manually setting it back to the width of the screen so that it pops back to the right side of the screen. However, this looks quite weird as the image just disappears on the left and pops up on the right.

Any help would be greatly appreciated, thanks in advance.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 19, 2021, 9:48am UTC](https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194/2 "2021-01-19T09:48:11Z")

</div>

> [@mchangxe](#):
>
> image’s x coordinate is smaller than 0

must be smaller than 0-img.width()-1 or so, then the image is entirely disapeared before reappearing.

(because image(…) uses the upper left corner of the image normally for x,y)

**reappearing**

reappearing: set x to width + 2

(you can give the image position x,y negative values (\<0) or very high values (\>width) without a problem)

---

<div class="post-metadata">

**Author:** ![mchangxe](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mchangxe](https://discourse.processing.org/u/mchangxe)\
**Post date:** [January 19, 2021, 10:15am UTC](https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194/3 "2021-01-19T10:15:03Z")

</div>

hi, thanks for your reply. This is indeed how I’ve done things right now. but i want to try to achieve the effect of having half of the image on the left and half on the right. Would that be efficient and possible?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 19, 2021, 10:17am UTC](https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194/4 "2021-01-19T10:17:40Z")

</div>

I see

Sure possible

You need the 2nd image (on the right) as soon as x\< 0 &&x \> 0-img.width

Use if(…) image () for the 2nd image

**Code Example**

(not tested)

```auto
image(.... ,x,y) ; // normal image that you have now
if(x< 0 && x > 0 - img.width ) { // image starts leaving screen on the left
     float x1; 
     x1 = width - abs(0-x); // show image additionally on the right
     image(.... ,x1,y) ; // for the 2nd image
}

x--;

```

---

<div class="post-metadata">

**Author:** ![mchangxe](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mchangxe](https://discourse.processing.org/u/mchangxe)\
**Post date:** [January 20, 2021, 2:52am UTC](https://discourse.processing.org/t/moved-pimage-from-one-side-to-the-screen-to-another-in-loop/27194/5 "2021-01-20T02:52:53Z")

</div>

thank you sir, let me try this
