Revolution-FX

Fade In/Fade Out

This tutorial describes how to create nice transistional effects by fading in and out. This tutorial demonstrates changing the contrast to achieve this effect. To change the contrast the function Change_Contrast() is used. Here's the prototype:

void Change_Contrast(char contrast);


Looking at the prototype contrast is the numerical value of the LCD's contrast. Now let's look at some code for fading in/out.

char fade_counter;
 
for (fade_counter = 167; fade_counter >= 130; fade_counter--) {		// Fading out
	Change_Contrast(fade_counter);
	Sleep(40);	// Delay
}

for (fade_counter = 130; fade_counter <= 167; fade_counter++) {		// Fading in
	Change_Contrast(fade_counter);
	Sleep(40);	// Delay
}
 	

The code should be easy to understand. We are using a for loop to increment and decrease contrast. You may be wandering what are special about the values 130 and 167. 130 is when the LCD's contrast is zero. 167 is the normal contrast for the LCD. Well, I think that pretty much covers it. Here's a example of fading in/out put into practice:

#include "fxlib.h"
#include "revolution.h"

int AddIn_main(int isAppli, unsigned short OptionNum)
{
	int fade_counter;

	Bdisp_AllClr_DDVRAM();
	PrintMini(1, 1, (unsigned char *)"Fading out", MINI_OVER);
	Bdisp_PutDisp_DD();
	for (fade_counter = 167; fade_counter >= 130; fade_counter--) { // Fading out
		Change_Contrast(fade_counter);
		Sleep(90);	// Delay
	}
	
	PrintMini(1, 1, (unsigned char *)"Fading in ", MINI_OVER);
	Bdisp_PutDisp_DD();
	for (fade_counter = 130; fade_counter <= 167; fade_counter++) { // Fading in
		Change_Contrast(fade_counter);
		Sleep(90);	// Delay
	}
	
	while(IsKeyDown(KEY_CTRL_EXIT) != 1){
	}
	
	Reset_Calc();
	return 1;
}
 
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section

#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
	return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section
  


SourceForge.net LogoContact Us | ©2007 Revolution-FX Development Team