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 & HelpSyntax Questions › Fading images in
Page Index Toggle Pages: 1
Fading images in? (Read 972 times)
Fading images in?
Nov 28th, 2009, 7:22pm
 
I'm setting up a gallery which slowly composites image on top of one another with a low opacity, so they layer over time.

I was wondering if there was a way to fade images in slowly rather than just have them appear suddenly? Sorry, I'm new at processing so any help would be appreciated.

My (awkward) code:

int maxImages = 10; // Total # of images
int imageIndex = 0; // Initial image to be displayed is the first
int fader = 25; //intializing the opacity start
float a = 10; //initiliazing opacity variable a
float aspeed = 2; //rate of change for a
PImage[] images = new PImage[maxImages]; // The image array

Timer timer;
void setup() {
size(600,600);
// Loading the images into the array
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( "animal" + i + ".jpg");
//starts the count
timer = new Timer(2000);
timer.start();
}
}


void draw() {
if (timer.isFinished()) {
tint (255, a);
image(images[imageIndex],0,0);
// increment image index by one each cycle
// use modulo "%" to return to 0 once the size
//of the array is reached
imageIndex = (imageIndex + 1) % images.length;

timer.start();
//changes a over time
a = a + aspeed;
// Remember, || means "or."
if ((a > 22) || (a < 10)) {
// If a goes over 22, multiply speed by -1 to turn it around.
aspeed = aspeed * -1;
 }
}
}

class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
// Starting the timer
void start() {
savedTime = millis();
}
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
}
Re: Fading images in?
Reply #1 - Nov 29th, 2009, 1:16am
 
you can use tint http://processing.org/reference/tint_.html to change the transparency of the images to fade them in
Page Index Toggle Pages: 1