We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How to delay the loading between images
Page Index Toggle Pages: 1
How to delay the loading between images? (Read 467 times)
How to delay the loading between images?
May 2nd, 2006, 3:21am
 
I need to figure out a way to delay the loading between images so it is not such a constant.  A few seconds delay to reveal the image is all I really need.  I unfortunately do not have the programing experience to figure this out.

Here is the code I am working with, any help would be greatly appreciated!

import processing.opengl.*;
import pitaru.sonia_v2_9.*;

//loads images
PImage a;
int i=0, j=0, blink=0;
int Num_pics= (3);
PImage[] img = new PImage[Num_pics];
Sample mySample;
void setup()
{
 //the image is loaded into several variables to give more variation of
 //shape and to build up quicker on the screen (perhaps not needed with faster computer?)
 //the first variation of the image
 //a = loadImage("miscellaneous_space_10.jpg");

 String fileName;
 for (int s = 0; s < Num_pics; s++)
{
 fileName = "space" + (s + 1) + ".jpg";
 img[s] = loadImage(fileName);

}

 size(1024,768,OPENGL);
 noStroke();
 background(0);
 
 Sonia.start(this);
 LiveInput.start(1024);
 LiveInput.useEnvelope(true,177.2);
// mySample = new Sample();  
// mySample.repeat();
// mySample.connectLiveInput(true);
 
 rectMode(CENTER_RADIUS);
 smooth();

}
void draw()
{
 getMeterLevel(); // using the meter reading of both channels to fade the background
 getSpectrum();  //calls up the function to display the pixels/squares
 erase();
 framerate(20);
}

void getSpectrum()
{
 //calculates the dimensions of the random ellipses

    // populate the spectrum array with FFT values.
    LiveInput.getSpectrum();
    int s = (int)random(Num_pics);
    tint(LiveInput.spectrum[s]/14, LiveInput.spectrum[s]/14);
    println(LiveInput.getLevel()*5000);
    image(img[s],0,0);
    a=img[s];
   
       for ( int i = 0; i < LiveInput.spectrum.length; i++)
      {
      //randomly choses a pixel and assigns the x coordinate  
      int x = int(random(a.width));
      //randomly choses a pixel and assigns the y coordinate  
      int y = int(random(a.height));
 
      //takes the x and y coordinates and
      int loc = x + y*a.width;
 
       //reads the color of each pixel  
      float r = red(a.pixels[loc]);
      float g = green(a.pixels[loc]);
      float b = blue(a.pixels[loc]);
      //reads the audio as the opacity and size variables
      fill(r,g,b,LiveInput.spectrum[i]/170);
      ellipse(x,y,LiveInput.spectrum[i]/423,LiveInput.spectrum[i]/423);
      fill(r,g,b,LiveInput.spectrum[i]/60);
      rect(x,y,LiveInput.spectrum[i]/423,LiveInput.spectrum[i]/160);
      fill(r,g,b,LiveInput.spectrum[i]/230);
      ellipse(x,y,LiveInput.spectrum[i]/210,LiveInput.spectrum[i]/423);
      fill(r,g,b,LiveInput.spectrum[i]/110);
      rect(x,y,LiveInput.spectrum[i]/423,LiveInput.spectrum[i]/123);
     
      fill(r,g,b,random(70,90));
      rect(x,y,random(10),random(10));
      }    
     
   
}
void erase(){
 fill(255,random(20));
 //image(a,0,0);
}
void getMeterLevel(){
  // get Peak level for each channel (0 -> Left , 1 -> Right)
  // Value Range: float from 0.0 to 1.0
  float meterDataLeft = LiveInput.getLevel();
  float meterDataRight = LiveInput.getLevel();
  // draw a volume-meter for each channel.
  float left = meterDataLeft*height;
  float right = meterDataRight*height;
  blink++;
      if (blink == 30)
      {
        blink=0;
        fill(255,random(left+right)/10);
        rect(512,640,1100,1300);
      }
 
}
// Safely close the sound engine upon Browser shutdown.
public void stop(){
   Sonia.stop();
   super.stop();
}
Re: How to delay the loading between images?
Reply #1 - May 2nd, 2006, 8:20am
 
Are you wanting to display each of the images after a delay.

The loading of images into the array inside setup doesn't benefit from being slowed down any.

inside your draw loop do something like:

Code:


int counter;
int index;

draw() {

if (counter-- <=0) {
counter = 10; // reset constant or random number

if (index++ > img.length) index = 0;
}

image (img[index],0,0);

// carry on with whatever else needs doing
}



Something like that anyway.

Good luck!

P.S You can see how by accessing the arrays.length you can dispense with some of your code.
Page Index Toggle Pages: 1