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


#include "commonlib.h" 
#include "random.h" 
#include "graphics.h" 
#include "extgraph.h" 
#include "time.h" 
 
#define NUM_COLORS 16 
 
string GetRandomColor (void) 
{ 
	int color; 
	 
	color = RandomInteger(1, NUM_COLORS); 
	 
	switch (color) { 
		case 1: return("Red"); 
		case 2: return("Orange"); 
		case 3: return("Gold"); 
		case 4: return("Yellow"); 
		case 5: return("Green"); 
		case 6: return("Emerald"); 
		case 7: return("Teal"); 
		case 8: return("Cyan"); 
		case 9: return("Aqua"); 
		case 10: return("Blue");		 
		case 11: return("Periwinkle"); 
		case 12: return("Purple"); 
		case 13: return("Violet");	 
		case 14: return("Magenta"); 
		case 15: return("HotPink"); 
		case 16: return("White"); 
		default: return("!ERROR!"); 
	} 
} 
 
void DefineColors (void) 
{ 
	DefineColor("Orange", 0.9, 0.5, 0); 
	DefineColor("Gold", 0.9, 0.8, 0); 
	DefineColor("Emerald", 0, 0.8, 0); 
	DefineColor("Teal", 0, 0.8, 0.7); 
	DefineColor("Aqua", 0, 0.6, 1.0); 
	DefineColor("Periwinkle", 0.5, 0, 0.7); 
	DefineColor("Purple", 0.6, 0, 0.7); 
	DefineColor("Violet", 0.6, 0, 0.6); 
	DefineColor("HotPink", 1.0, 0, 0.5); 
} 
 
void DrawFilledRectangle (double dblLeft, double dblTop, double dblWidth, double dblHeight, string strColor) 
{ 
	SetPenColor(strColor); 
	StartFilledRegion(1.0); 
	MovePen(dblLeft, dblTop); 
	DrawBox(dblWidth, dblHeight); 
	EndFilledRegion(); 
} 
 
void DrawBoxEx (double left, double top, double width, double height) 
{ 
	MovePen(left, top); 
 
	DrawLine(width, 0); 
	DrawLine(0, height); 
	DrawLine(-width, 0); 
	DrawLine(0, -height); 
} 
 
void DrawBox (double dblWidth, double dblHeight) 
{ 
	DrawLine(dblWidth, 0); 
	DrawLine(0, dblWidth); 
	DrawLine(-dblWidth, 0); 
	DrawLine(0, -dblWidth); 
} 
 
void CleanScreen (void) 
{ 
	DrawFilledRectangle(0, 0, GetWindowWidth(), GetWindowHeight(), "Black"); 
} 
 
void Wait (int intTime) 
{ 
	clock_t intClock; 
	 
	intClock = clock(); 
 
	intClock += intTime; 
 
	while(clock() < intClock) 
	{ 
		//Do nothing 
	} 
} 
 
bool InRange (double num, double l, double h) 
{ 
	return ( ( (num >= l) && (num <= h) ) || 
			 ( (num <= l) && (num >= h) ) ); 
}