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.
Page Index Toggle Pages: 1
I need help... (Read 781 times)
I need help...
Aug 27th, 2007, 9:24pm
 
I'm doing a soundreactive sketch, that shows a pixelated image. The size of these pixels depends on the input value of a microphone.
What i want is, that every time the input value reaches 100, i want the image to change.
I have all of the code done, but all i need is a class that like "if(input > 100)" changes the the image when the input reaches 100, and not changes until the value exceeds 100 again..
any help?

Slm
Re: I need help...
Reply #1 - Aug 28th, 2007, 11:19am
 
use a audio library like Sonia to get the level of the input and just do that if condition yourself..

the lib has few examples, iirc it has a getLevel() example aswell.. check it out
Re: I need help...
Reply #2 - Aug 28th, 2007, 3:03pm
 
thank you, but i'm alredy using Sonia, thats not my problem.
All i need is a code that can change the change the background image everytime it is called.
Re: I need help...
Reply #3 - Aug 28th, 2007, 5:08pm
 
first, having a descriptive title helps with getting more answers.

that said, best practice would be to load the images into an array and increment an index-pointer once the level hits 100:

Code:

PImage[] myImages; // the array
int currentImage = 0; // the index, pointing to the first image at 0

void setup () {
// ...
// initialize array
myImages = new PImage[/* amount of images goes here */];
// load images
myImages[0] = loadImage( "image1.jpg" );
myImages[1] = loadImage( "image2.jpg" );
myImages[2] = loadImage( "image2.jpg" );
// ...
}

void draw () {
image( myImages[currentImage], 0, 0 );
// ...
if ( /* sonia code to check level == 100 */ )
{
currentImage++; // increment index
currentImage %= myImages.length; // make sure its >= 0 and < array.length
// read up on modulo "%"
// http://processing.org/reference/modulo.html
}
}


F
Re: I need help...
Reply #4 - Aug 28th, 2007, 10:00pm
 
thank you so much!!
Page Index Toggle Pages: 1