Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

how do you put a counter on any array?

$
0
0
i am a grad student and new to processing
i am working on a piece with an array of video clips
i want the array to be accessed consecutively until the array has been completed at which point it would begin at zero
again
at the moment the mouse press sets it back to the beginning
i am not sure how to fix this
can anyone help?
please find my code below
thanks


import processing.video.*;

int maxmyMovies=5
;  //total # movies
int myMoviesIndex=0;  //initial movie to be displayed

Movie[] myMovies = new Movie[maxmyMovies] ; //declare array of movies

boolean someoneIsThere = false;


void setup( ){
 
  size(1280, 720);
   for (int i=0; i<myMovies.length; i++) {
    myMovies[i] = new Movie(this, "trans"+i+".mov");  //loading movies into the array
  }
  myMovies[myMoviesIndex].loop(); //play the first movie
}
void draw() {
  image(myMovies[myMoviesIndex], 0, 0, 1280, 720);   //display one movie
 
  if (myMovies[myMoviesIndex].time() >= myMovies[myMoviesIndex].duration()) {
    // the current movie is done
   
    if (someoneIsThere) {
      nextMovie();
      someoneIsThere = false;
    }
    else {
      myMovies[myMoviesIndex].stop(); // stop the current movie
      myMoviesIndex = 0;
      myMovies[myMoviesIndex].loop();
    }
  }
 
 
  fill(255);
  text(myMovies[myMoviesIndex].time(), 30, 30);
  text(myMovies[myMoviesIndex].duration(), 30, 60);
}


void movieEvent(Movie myMovies) {
  myMovies.read();  //read new frames from movie
}


void mousePressed() {
  someoneIsThere = true;
}

void nextMovie() {
  myMovies[myMoviesIndex].stop(); // stop the current movie
  myMoviesIndex=(myMoviesIndex+1) % myMovies.length;  //increment movie by one and return to zero once size of array is reached
  myMovies[myMoviesIndex].play(); // play the next movie
}



Viewing all articles
Browse latest Browse all 1768

Trending Articles