www.pudn.com > screensaver.rar > DoImages.c


#include "DoImages.h" 
#include "genlib.h" 
#include "graphics.h" 
#include "extgraph.h" 
#include "random.h" 
#include "commonlib.h" 
 
void GenerateRandomOrder (int * pOrder); 
void DrawCenteredPhoto (string strName); 
bool ShowAnimation (string strName); 
void DrawBlock (double dblOrgX, double dblOrgY, double dblBlockWidth, double dblBlockHeight, int intBlockIndex); 
 
void DoImages (void) 
{ 
	string arrPicNames[6]; 
	int intIndex; 
 
	arrPicNames[0] = "BlueFlower"; 
	arrPicNames[1] = "Bridge"; 
	arrPicNames[2] = "Building"; 
	arrPicNames[3] = "Campus"; 
	arrPicNames[4] = "PointLobos"; 
	arrPicNames[5] = "Tiger"; 
 
	intIndex = 0; 
	while ( (!MouseButtonIsDown()) 
		 && (ShowAnimation(arrPicNames[intIndex])) ) 
	{ 
		Wait(1000); 
		intIndex = (intIndex + 1) % 6; 
	} 
} 
 
void GenerateRandomOrder (int * pOrder) 
{ 
	int * arrOrder; 
	bool arrCheck[20]; 
	int i, j; 
 
	arrOrder = pOrder; 
 
	for (i = 0; i < 20; i ++) 
	{ 
		arrCheck[i] = FALSE; 
	} 
 
	for (i = 0; i < 20; i ++) 
	{ 
		j = RandomInteger(0, 19); 
		while (arrCheck[j]) 
		{ 
			j = RandomInteger(0, 19); 
		} 
 
		arrOrder[i] = j; 
		arrCheck[j] = TRUE; 
	} 
} 
 
void DrawCenteredPhoto (string strName) 
{ 
	double dblPicWidth, dblPicHeight, dblWinWidth, dblWinHeight; 
 
	dblPicWidth = GetPictureWidth(strName); 
	dblPicHeight = GetPictureHeight(strName); 
	dblWinWidth = GetWindowWidth(); 
	dblWinHeight = GetWindowHeight(); 
 
	MovePen( (dblWinWidth - dblPicWidth) / 2, 
			 (dblWinHeight - dblPicHeight) / 2); 
 
	DrawNamedPicture(strName); 
} 
 
bool ShowAnimation (string strName) 
{ 
	int arrOrder[20]; 
	int i, j; 
	double dblBlockWidth, dblBlockHeight; 
	double dblPicWidth, dblPicHeight, dblWinWidth, dblWinHeight; 
	double dblOrgX, dblOrgY; 
 
	dblPicWidth = GetPictureWidth(strName); 
	dblPicHeight = GetPictureHeight(strName); 
	dblWinWidth = GetWindowWidth(); 
	dblWinHeight = GetWindowHeight(); 
 
	dblBlockWidth = dblPicWidth / 5; 
	dblBlockHeight = dblPicHeight / 5; 
 
	dblOrgX = (dblWinWidth - dblPicWidth) / 2; 
	dblOrgY = (dblWinHeight - dblPicHeight) / 2; 
 
	GenerateRandomOrder(arrOrder); 
 
	CleanScreen(); 
 
	DrawCenteredPhoto(strName); 
	UpdateDisplay(); 
 
	for(i = 0; i < 20; i ++) 
	{ 
		DrawCenteredPhoto(strName); 
		for(j = i + 1; j < 20; j ++) 
		{ 
			DrawBlock(dblOrgX, dblOrgY, dblBlockWidth, dblBlockHeight, arrOrder[j]); 
		} 
		UpdateDisplay(); 
		if (MouseButtonIsDown()) 
		{ 
			return FALSE; 
		} 
 
		Wait(100); 
	} 
	return TRUE; 
} 
 
void DrawBlock (double dblOrgX, double dblOrgY, double dblBlockWidth,  
				double dblBlockHeight, int intBlockIndex) 
{ 
	int intRelX, intRelY; 
	double dblAbsX, dblAbsY; 
 
	intRelX = intBlockIndex % 5; 
	intRelY = (int) (intBlockIndex / 5); 
	 
	dblAbsX = dblOrgX + dblBlockWidth * intRelX; 
	dblAbsY = dblOrgY + dblBlockHeight * intRelY; 
 
	DrawFilledRectangle(dblAbsX, dblAbsY, dblBlockWidth, dblBlockHeight, "Black"); 
}