How can I create an infinite loop?

Hi guys, I'm new here and I have a question.My question is;

I have created a for loop which is draw images side by side and I've tried to create sliding effect by decreasing x position of the image and I need to create a loop which the first images slide to left(image is out of the canvas) I need to redraw it on right side of the screen.I'm sorry for my bad English I'm not a native speaker and thanks for your advices :)

Here is my code:

for(var plainPosX = 0; plainPosX<=width;plainPosX +=100){
    image(plain,plainPosX + slide,430);
//slide takes negative value so it decreases plainPosX and it seems like image is sliding.


  • interesting

  • Answer ✓

    The draw() function is the infinite loop you want already! Here's an example:

    String http = "http://";
    PImage img; 
    int x;
    void setup() {
      size( 400, 400 );
      img = loadImage( http + "" );
      x = width/2;
      imageMode( CENTER );
    void draw() {
      image( img, x,         height/2 );
      image( img, x + width, height/2 );
      if ( x < -width/2 ) {
        x += width;
Sign In or Register to comment.