How do I loop entire sketch ?

edited March 2015 in Questions about Code

Hello all

I'm attempting to loop my whole sketch at the end of the video I have playing in the background.

Any advice would be greatly appreciated !!

^:)^ :)>-

  PrintWriter output;

  int frames = 3; 

  PImage bg; 

  int initialTime;

 int interval = 10;

 PGraphics pg[] = new 

 PGraphics[frames];

 boolean startDraw = true;

 import processing.video.*;

 Movie myMovie;

 void setup() {

size(1000, 1000);

myMovie = new Movie(this, "MVI_5786.mov");

myMovie.loop();

 for (int i=0; i<frames; i++) {

pg[i] = createGraphics(width, height);

pg[i].beginDraw();

pg[i].smooth ();

//pg[i].background(255,0,0);

pg[i].stroke(255);

pg[i].strokeWeight(3);

pg[i].endDraw();

output = createWriter("positions.txt");

}

initialTime = millis();

}


void draw() {


int currFrame = frameCount % frames; // 0 .. 19

if (mousePressed) if (millis() - initialTime > interval) {

 pg[currFrame].beginDraw();

 pg[currFrame].line(mouseX, mouseY, pmouseX, pmouseY);

pg[currFrame].endDraw();

}

{


 if(mousePressed) {

  point(mouseX, mouseY);

  output.println(startDraw + ", " + mouseX + "," + mouseY + "," + millis()); // Write the coordinate to the file

  startDraw = false;

  } 

 } 
  initialTime = millis();

  image(myMovie, 0, 0);

  image(pg[currFrame], 0, 0);



 println(millis());

 if (millis() > 10000 && millis() < 12000) {

clearDrawings();

 }

 if (millis() > 16000 && millis() < 18000) {

 clearDrawings();
 }
 if (millis() > 20000 && millis() < 23000) {

 clearDrawings();

}
}

void movieEvent(Movie m) {

m.read();

}
void clearDrawings() {

for (int i=0; i<frames; i++) {

pg[i].beginDraw();

pg[i].clear();

//pg[i].background(255,0,0);

pg[i].endDraw();

}
}
void mouseReleased() {

startDraw = true;

 }

 void keyPressed() {

 output.flush(); // Writes the remaining data to the file

 output.close(); // Finishes the file

 exit(); // Stops the program

 } 
Tagged:

Answers

  • You might want to fix your indentation. In the Processing editor, just press ctrl+T. As of now your code is pretty hard to read.

    But all you need to do is reset any variables that determine the state of your sketch. Maybe move some of your initialization into a separate reset() function and just call that from setup() and again whenever you want to reset your sketch.

Sign In or Register to comment.