FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   newby needs help with pictures integration
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: newby needs help with pictures integration  (Read 701 times)
amnesie


newby needs help with pictures integration
« on: Dec 9th, 2004, 10:19pm »

hi everybody
i'm a beginner with processing software and a few minutes using examples convinced me to use this software.
i know that it will be better for me to take time using the software to get used with it, but i've got a live show next week and wanted to use it. (i use jitter but for what i've got in mind processing looks more efficient).
i'd like to had to a patch the possibility to randomly see images from my hardrive coming in fade in and fading away within 10 seconds, i'd like this images to be displayed randomly in the screen.
in fact i need to know how to do automated fades in/out and randomly display images at random position.
thanks a lot if you could help.
 
(sorry if my english is not clear)
 
amnesie


Re: newby needs help with pictures integration
« Reply #1 on: Dec 10th, 2004, 1:02pm »

in fact, i will work with videos containing their own fades in/out
i'd like them to be displayed randomly on the screen and it works, but i haven't find how to load multiple videos and to select them randomly. the aim is that when i press a key, it reads a video randomly at random positions...
here's what i've done :
 
BVideo vid;
 
float u = random(200);
float v = random(200);
 
void setup()  
{
  size(200, 200);
  background(0);
   
  // Load and play the video in a loop
  vid = loadVideo("street.mov");
  repeat(vid);
}
 
void loop() {
  if(keyPressed) {
  if (key == DOWN) {  
  play(vid);
 
{
  fill(250, 200);
  image(vid, u, v);
}
}
}
}
 
st33d

WWW Email
Re: newby needs help with pictures integration
« Reply #2 on: Dec 10th, 2004, 1:07pm »

I like Processing for the fact I can make pictures with maths. Which is what it's great at doing because you don't get any of that mushy data type business. But I don't think fading images are that straight forward in Processing. I don't even think that Processing is even suitable as a slide show platform. Flash would probably be much easier to achieve this on. If you take a look at the reference section and see these two links you'll begin to get what I mean.
 
http://processing.org/reference/alpha_.html
 
http://processing.org/reference/blend_.html
 
Whereas in Flash you could set up an array with your pictures in and have them load into a symbol on the stage. Just give that symbol a name in the Properties inspector (the instance name field is easy to miss but it's there) and you can use a code similar to this to load random images in.
 
Code:

arrayPictures = ["assets/pic01.jpg", "assets/pic02.jpg", "assets/pic03.jpg"]
c = random(3)
_root.instanceName.loadMovie(arrayPictures[c]);

 
The instance name is a movie object. In the Flash help pages you can find methods for altering the properties or the position of the movie object or you could just alter the properties of the symbol on stage to simulate randomness. In the timeline you could achieve a fade by altering the color property to alpha and creating a tween and just fade it in and out.
 
The main advantage of using Flash over Processing for this job is that Flash can export a slideshow program and this can be run at full screen by using the following actionscript at the beginning:
 
Code:

fscommand("fullscreen", "true");

 
Whoops, didn't see you had something already in the works.
 
Try the array method I've used but in Processing.
Code:

//construct an array for the vids. I'm hoping for your sake that arrays work in all data types
BVideo[] vid = new BVideo[3]
 
float u = random(200);
float v = random(200);
 
void setup()  
{
  size(200, 200);
  background(0);
   
  // Load and play the video in a loop
  vid[0] = loadVideo("street.mov");
  vid[1] = loadVideo("park.mov");
  vid[2] = loadVideo("road.mov");
  //don't know how the next bit works, haven't used it before
  repeat(vid);
}
 
void loop() {
  int r = int(random(3))
  if(keyPressed) {
  if (key == DOWN) {  
  play(vid[r]);
 
{
  fill(250, 200);
  image(vid[r], u, v);
}
}
}
}

 
And you can post easier to read code by using code tags. Just use <code></code> but use the array brackets  "[]" instead of "<>".
« Last Edit: Dec 10th, 2004, 1:25pm by st33d »  

I could murder a pint.
amnesie


re
« Reply #3 on: Dec 10th, 2004, 11:21pm »

sorry but it doesn't seem to work, it tells me :
 
The type of this expression, "BVideo", is not an array type.
 
concerning this line :
 
vid[ 0] = loadVideo("street.mov");
« Last Edit: Dec 10th, 2004, 11:22pm by amnesie »  
st33d

WWW Email
Re: newby needs help with pictures integration
« Reply #4 on: Dec 11th, 2004, 3:53am »

My guess at a solution to this is to create a datatype around the BVideo datatype that IS capable of supporting arrays. That is create a class and stick it inside. Then again Processing may not support multiple loaded videos. I don't know (processing 68 doesn't seem to recognise BVideo so I can't test it).
Try mucking about with this code below. If you're unsuccessful you could always try to adapt it for your image fading idea. I botched it together from the animated sprite example on the cover page.
 
Code:

float u = random(200);
float v = random(200);
videoClass[] vid = new videoClass[2];
void setup(){
size(200,200);
vid[0] = new videoClass("1.mov");
vid[1] = new videoClass("2.mov");
}
void loop(){
  int r = int(random(3))
  if(keyPressed) {
  if (key == DOWN) {  
  vid[r].playVid();
 
{
  fill(250, 200);
  vid[r].display(u, v);
 
}
class videoClass{  
  BVideo i;  
  videoClass(String videoName){  
    loadVideos(videoName);  
  }  
 
  void loadVideos(String name){
 i =  loadVideo(name);;  
    }  
  void playVid(){
  play(i);
 }
  void display(float xpos, float ypos){
    image(i, xpos, ypos);  
  }  
}

 
Syntax may be a bit dodgy.
 

I could murder a pint.
amnesie


Re: newby needs help with pictures integration
« Reply #5 on: Dec 12th, 2004, 11:03pm »

thanks for your help but it doesn't seem to work...
 
i'm back to my first idea : loading images randomly (i'll see later for the fades in end out)
 
my patch is as follow, but it doesn't work, could you tell me what's the problem ?
 
 
float u = random(200);
float v = random(200);
float r = random(2);
 
size(400, 400);
BImage a;  
if (r == 0)  
a = loadImage("arch.jpg");  
if (r == 1)
a = loadImage("test.jpg");
 
image(a , u, v);  
 
Philipp

WWW Email
Re: newby needs help with pictures integration
« Reply #6 on: Dec 13th, 2004, 12:02am »

The problem here is that you declare r as a floating point variable.
Code:

if (r == 0)  
a = loadImage("arch.jpg");  
if (r == 1)
a = loadImage("test.jpg");  

...will only execute if r is exactly 0 or 1 (as opposed to e.g. 0.5). Try "int r" instead of "float r"
 
amnesie


Re: newby needs help with pictures integration
« Reply #7 on: Dec 13th, 2004, 8:29am »

but the random function doesn't accept int values...
and i don't know how to transform r from float to int...
 
moreover, it's not the only problem because when i try this, i still doesn't work :  
 
float u = random(200);  
 float v = random(200);  
 float r = 0;  
  
 size(400, 400);  
 BImage a;    
 if (r == 0)  
 a = loadImage("arch.jpg");  
  
 image(a , u, v);  
       
 
« Last Edit: Dec 13th, 2004, 10:17am by amnesie »  
fjen

WWW
Re: newby needs help with pictures integration
« Reply #8 on: Dec 14th, 2004, 12:46am »

you can convert an float to an int by writing:
int abc = int(1.234);
 
i don't think it's a good idea (at the moment) to use processing as a presentation-tool for videos. the larger the video (640*480), the worse it will run ... anyway, here is a sketch for you that does what you wanted to do (make sure to put your own movies in, or copy the two from examples->video):
 
Code:

String vFiles[] = new String[]{
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov",
  "station.mov",  "street.mov",  "station.mov",  "street.mov"
};
BVideo vPlaying;
void setup()
{
  size(200, 200);
  background(0);
  vPlaying = loadVideo(vFiles[0]);
  vPlaying.play();
}
void loop() {
  if(keyPressed) {
    if (key == DOWN) {
 vPlaying.stop();
 String randomFile = vFiles[(int)random(vFiles.length-1)];
 vPlaying = loadVideo(randomFile);
 vPlaying.play();
    }
  }
 image(vPlaying, 0, 0);
}

 
/F
 
Pages: 1 

« Previous topic | Next topic »