How to loop the whole proces?
in
Core Library Questions
•
1 year ago
Hello,
I made this code for a interactive installation. This is the idea of the installation: the visitor comes into a empty room (only music is playing), his shadow is projected on a wall, because of a lamp. When the visitor steps on a foot tile, his shadow is captured by a webcam and projected on the wall. (the lamp is switched off, and a beamer is projecting your freezed shadow on the wall). Now a movie is playing with people who are tearing you apart. When the movie stops, the whole proces can start all over again.
Now, that's a problem for me. I made a code that works, but because this is my first code I ever made in Processing and I didn't make a very good flow chart, I don't know how I can loop the whole proces.
I hope someone of you can help me a bit where to start. Thanks anyway!
By the way, this is my code:
_________________________________________________________________________________________________
//Pre-setup
//Videos
import processing.video.*;
Movie shades;
Capture myCapture;
//Music
import ddf.minim.*;
Minim minim;
AudioPlayer introMusic;
//Images
PImage d, e;
//boolean movie
boolean movie = false;
boolean imagestarted = false;
//White rect
final int HowLongIsItWaiting1 = 3000;
final int HowLongIsItWaiting2 = 1000;
float m ;
char state='A';
//Setup
void setup() {
//workspace
size(640, 480, P2D);
//Intromusic
minim = new Minim(this);
introMusic = minim.loadFile("intro.mp3");
introMusic.loop();
//loadimages
d = loadImage("bg.jpg");
//Capture setup
myCapture = new Capture(this, width, height, 30);
//Movie shades setup
shades = new Movie(this, "film.mov");
//White rect setup
noStroke();
state='A';
m = millis();
}
//Make the Capture
void captureEvent (Capture myCapture) {
myCapture.read ();
}
//Draw
void draw() {
// Black background
fill(0);
rect(0, 0, 640, 480);
//The movie
if(movie == true) {
image (d, 0, 0);
if (imagestarted == false) {
createdImage();
image (e, 0, 0);
}
blend(shades, 0, 0, 640, 480, 0, 0, 640, 480, MULTIPLY);
}
//Intromusic stop when you press the mouse
if (mousePressed == true) {
introMusic.pause();
}
}
//Hide till mouse is pressed
//Webcam capture, save image
void captureSave() {
image(myCapture, 0, 0);
saveFrame("data/createimage.jpg");
e = loadImage("createimage.jpg");
delay (300);
myCapture.stop();
}
//Show movie shades
void movieshades() {
movie = true;
shades.play();
}
void createdImage() {
if (mousePressed == true) {
if (state=='B') {
if (millis()-m>HowLongIsItWaiting1) {
fill(255);
rect(0, 0, 640, 480);
m = millis();
state='A';
imagestarted = true;
} // if
} // if
else if (state=='A') {
if (millis()-m>HowLongIsItWaiting2) {
image (e, 0, 0);
m = millis();
state='B';
} // if
} // if
} // func
}
//Mouse is pressed
void mousePressed() {
captureSave();
movieshades();
}
//End code
I made this code for a interactive installation. This is the idea of the installation: the visitor comes into a empty room (only music is playing), his shadow is projected on a wall, because of a lamp. When the visitor steps on a foot tile, his shadow is captured by a webcam and projected on the wall. (the lamp is switched off, and a beamer is projecting your freezed shadow on the wall). Now a movie is playing with people who are tearing you apart. When the movie stops, the whole proces can start all over again.
Now, that's a problem for me. I made a code that works, but because this is my first code I ever made in Processing and I didn't make a very good flow chart, I don't know how I can loop the whole proces.
I hope someone of you can help me a bit where to start. Thanks anyway!
By the way, this is my code:
_________________________________________________________________________________________________
//Pre-setup
//Videos
import processing.video.*;
Movie shades;
Capture myCapture;
//Music
import ddf.minim.*;
Minim minim;
AudioPlayer introMusic;
//Images
PImage d, e;
//boolean movie
boolean movie = false;
boolean imagestarted = false;
//White rect
final int HowLongIsItWaiting1 = 3000;
final int HowLongIsItWaiting2 = 1000;
float m ;
char state='A';
//Setup
void setup() {
//workspace
size(640, 480, P2D);
//Intromusic
minim = new Minim(this);
introMusic = minim.loadFile("intro.mp3");
introMusic.loop();
//loadimages
d = loadImage("bg.jpg");
//Capture setup
myCapture = new Capture(this, width, height, 30);
//Movie shades setup
shades = new Movie(this, "film.mov");
//White rect setup
noStroke();
state='A';
m = millis();
}
//Make the Capture
void captureEvent (Capture myCapture) {
myCapture.read ();
}
//Draw
void draw() {
// Black background
fill(0);
rect(0, 0, 640, 480);
//The movie
if(movie == true) {
image (d, 0, 0);
if (imagestarted == false) {
createdImage();
image (e, 0, 0);
}
blend(shades, 0, 0, 640, 480, 0, 0, 640, 480, MULTIPLY);
}
//Intromusic stop when you press the mouse
if (mousePressed == true) {
introMusic.pause();
}
}
//Hide till mouse is pressed
//Webcam capture, save image
void captureSave() {
image(myCapture, 0, 0);
saveFrame("data/createimage.jpg");
e = loadImage("createimage.jpg");
delay (300);
myCapture.stop();
}
//Show movie shades
void movieshades() {
movie = true;
shades.play();
}
void createdImage() {
if (mousePressed == true) {
if (state=='B') {
if (millis()-m>HowLongIsItWaiting1) {
fill(255);
rect(0, 0, 640, 480);
m = millis();
state='A';
imagestarted = true;
} // if
} // if
else if (state=='A') {
if (millis()-m>HowLongIsItWaiting2) {
image (e, 0, 0);
m = millis();
state='B';
} // if
} // if
} // func
}
//Mouse is pressed
void mousePressed() {
captureSave();
movieshades();
}
//End code
1