problem with random() function
in
Contributed Library Questions
•
1 year ago
Hi there,
I am working on a project in which I want to play 3 video files
randomly (each video file on each movement).
I dont know how to use Random() function.
If I use random() function , then it only repeat a 1 video at a time... but I want different video play at every time.
Can any one help me to understand how to deal with random() function...???
Regards...
By the way.. this is the sketch....
Any help must be appreciated...import processing.opengl.*;import codeanticode.glgraphics.*;import codeanticode.gsvideo.*;
GSCapture cam;GSMovie[] movie=new GSMovie[3];GLTexture[] tex=new GLTexture[3];int index;GSMovie mv;PImage prevFrame;int counter=0;void setup() {size(640, 480, GLConstants.GLGRAPHICS);
cam = new GSCapture(this, 640, 480);cam.start();
// Use texture tex as the destination for the camera pixels.tex[0] = new GLTexture(this);tex[1] = new GLTexture(this);tex[2] = new GLTexture(this);
movie[0]=new GSMovie(this, "smoke.mov");movie[1]=new GSMovie(this, "Drift.mov");movie[2]=new GSMovie(this, "Galardo.mov");
for (int i=0;i<movie.length;i++) {movie[i].setPixelDest(tex[i]);}
prevFrame = createImage(cam.width, cam.height, RGB);for(int i=movie.length-1;i>0;i--){int j=int(random(i+1));//swapmv=movie[i];movie[i]=movie[j];movie[j]=mv;}}
void captureEvent(GSCapture cam) {cam.read();}void movieEvent(GSMovie movie) {
movie.read();}
void draw() {background(255);image(cam, 0, 0);
MovieonMovementDisplay();
for (int i=0;i<tex.length;i++) {if (tex[i].putPixelsIntoTexture()) {image(tex[i], 0, 0);}}}void MovieonMovementDisplay() {if (cam.available()) {prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height);prevFrame.updatePixels();cam.read();}
loadPixels();cam.loadPixels();prevFrame.loadPixels();
float totalMotion=0;
for (int i = 0; i < cam.pixels.length; i ++ ) {color current = cam.pixels[i];
color previous= prevFrame.pixels[i];
float r1 = red(current);float g1 = green(current);float b1 = blue(current);float r2 = red(previous);float g2 = green(previous);float b2 = blue(previous);
float diff = dist(r1, g1, b1, r2, g2, b2);totalMotion += diff;}float avgMotion = totalMotion / cam.pixels.length;
println(avgMotion+"----AvgMotion");println("---------");
for (int i=0;i<movie.length;i++) {println(movie[i].time());}int index=constrain(movie.length,0,2);float time=movie[index].time();
if((avgMotion>30)&&(avgMotion<80)){movie[index].play();}if(movie[index].isPlaying()){if(time==movie[index].time()){movie[int(random(0,movie.length))].jump(0);}}}
Thank you...
1