home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CLIPART
/
VPOINT.ZIP
/
AJGFUNS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-01
|
11KB
|
497 lines
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graph.h>
#include <time.h>
#include "\qc25\toolbox\getkey.h"
#include "\qc25\toolbox\sound.h"
#include "\qc25\bin\ajgfun.h"
#include "mousefun.h"
boolean regfonts2(void);
color_t c_array2[16] = {
_BLACK, _BLUE, _GREEN, _CYAN, _RED, _MAGENTA, _BROWN,
_WHITE, _GRAY, _LIGHTBLUE, _LIGHTGREEN, _LIGHTCYAN,
_LIGHTRED, _LIGHTMAGENTA, _YELLOW, _BRIGHTWHITE};
extern int r = 10, g = 20, b = 30;
boolean regfonts2(void)
/* Read header info from .FON files in current or given directory. */
{
char fondir[_MAX_PATH];
char temp[50];
short fontnum;
if( _registerfonts( "*.FON" ) <= 0 )
{
_settextcolor(12);
_outtext( "\n Please Enter the full path where *.FON files are located:\n ");
_settextcolor(1);
_outtext( ">> " );
gets( fondir );
strcat( fondir, "\\*.FON" );
fontnum = _registerfonts( fondir );
if ( fontnum <= 0 )
{
_outtext( "Error: Sorry, unable to register fonts" );
return( NOGO );
}
sprintf( temp, "\n%d Graphics character fonts read.\n", fontnum );
_settextcolor(9);
_outtext( temp );
getch();
_settextcolor(15);
return( GO );
}
}
unsigned long get_color(int *type1, int *r, int *g, int *b)
/* Returns an integer value corresponding to the next VGA color in a series */
{
int red = * r;
int green = * g;
int blue = * b;
int type = *type1;
if (type > 10)
type = 1;
/*if ((red == 62) OR (blue == 62) OR (green == 62))
{
red = green = blue = 10;
if (type == 5)
type = 1;
else ++type;
}
else
if ((red <= 0) || (blue <= 0) || (green <= 0))
red = blue = green = 62;
*/
if ( red EQ 62 )
red = 5;
if ( green EQ 62 )
green = 5;
if ( blue EQ 62 )
blue = 5;
if ( red EQ 0 )
red = 62;
if ( green EQ 0 )
green = 62;
if ( blue EQ 0 )
blue = 62;
type = rand() % 8;
switch(type)
{
case 1 :
if (red < 63)
red++;
else if (green < 63)
green++;
else if (blue < 63)
blue++;
break;
case 2 :
if (green < 63)
green++;
else if (blue < 63)
blue++;
else if (red < 63)
red++;
break;
case 3 :
if (blue < 63)
blue++;
else if (red < 63)
red++;
else if (green < 63)
green++;
case 4 :
if (blue < 63)
blue++;
else if (green < 63)
green++;
else if (red < 63)
red++;
break;
case 5 : red = (rand() % 63 );
green = rand() % 63;
blue = rand() % 63;
break;
case 6 :
if (red > 10)
red--;
else if (green > 10)
green--;
else if (blue > 10)
blue--;
break;
case 7 :
if (green > 10)
green--;
else if (blue > 10)
blue--;
else if (red > 10)
red--;
break;
case 8 :
if (blue > 10)
blue--;
else if (red > 10)
red--;
else if (green > 10)
green--;
case 9:
red = (rand() % 63 );
green = rand() % 63;
blue = rand() % 63;
break;
case 10:
red = (rand() % 63 );
green = rand() % 63;
blue = rand() % 63;
break;
}
* r = red;
* g = green;
* b = blue;
* type1 = type;
return (rgb(red, green, blue));
}
/* Simple bubble sort for short arrays of integers */
void sort(short * p, int n)
{
int i, j, temp;
for (i = n; i > 1; --i)
for (j = 1; j < i; ++j)
if (p[j] > p[j+1])
{
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
}
}
/* Takes an area of the screen defined by the received logical
coordinates and resets the color values of any non-background
pixels to a random palette color */
void remap(short x1, short y1, short x2, short y2)
{
short color = 1;
pixtype x, y;
if (vc.numcolors >= 12)
for (x = x1; x <= x2; x++)
for (y = y1; y <= y2; y++)
if (_getpixel(x, y) != 0) /// Remap all non-background pixels
{
/* _setcolor(rand() % vc.numcolors + 1); */
if ( color < vc.numcolors )
++color;
else
color = 1;
_setcolor( color );
_setpixel(x, y);
}
}
void remap2(short x1, short y1, short x2, short y2, short maptype)
{
short color = 1;
pixtype x, y;
switch (maptype)
{
case 1 : /* horzontal bars */
for (x = x1; x <= x2; x++)
for (y = y1; y <= y2; y++)
if (_getpixel(x, y) != 0) /// Remap all non-background pixels
{
if (kbhit())
return;
/* _setcolor(rand() % vc.numcolors + 1); */
if ( color < vc.numcolors )
++color;
else
color = 1;
_setcolor( color );
_setpixel(x, y);
}
break;
case 2 : /* random pixels */
for (x = x1; x <= x2; x++)
for (y = y1; y <= y2; y++)
if (_getpixel(x, y) != 0) /// Remap all non-background pixels
{if (kbhit())
return;
_setcolor(rand() % vc.numcolors + 1);
_setpixel(x, y);
}
break;
case 3 : /* moire remapping */
for (x = x1; x <= x2; x++)
for (y = y1; y <= y2; y++)
{if (kbhit())
return;
if (_getpixel(x, y) != 0) /// Remap all non-background pixels
color = ( ( x * x + y * y ) / 10 ) % vc.numcolors ;
if ( color <= 1 )
color = rand() % vc.numcolors + 1;
_setcolor ( color );
_setpixel(x, y);
}
break;
case 4 : /* vertical bars */
for (y = y1; y <= y2; y++)
for (x = x1; x <= x2; x++)
if (_getpixel(x, y) != 0) /// Remap all non-background pixels
{if (kbhit())
return;
if ( color < vc.numcolors )
++color;
else
color = 1;
_setcolor( color );
_setpixel(x, y);
}
break;
default:
break;
}
}
/* Receives a string and returns the logical x coordinate to center the
string on the CRT display depending on hardware & video configuration*/
pixtype centerx(char * text)
{
return((short)(vc.numxpixels / 2) - (_getgtextextent(text) / 2) - 1);
}
/* Returns a neatly formatted string containing the day/month/date/year
"days" number of days from the present date */
void getdate(char * temp, time_t days)
{
time_t bintime;
char * datestr;
short i;
days *= 86400; /// Number of seconds in a day
time(&bintime);
bintime += days;
datestr = ctime(&bintime);
/* The following reformats the string returned by "ctime" to eliminate
unneccessary chars */
datestr[12] = datestr[21];
datestr[13] = datestr[22];
datestr[14] = datestr[23];
datestr[15] = datestr[24];
datestr[16] = '\0';
for (i = 17; i <= 26; i++)
datestr[i] = ' ';
strcpy( temp, "The Megubucks Number for ");
strcat( temp, datestr);
}
/* Sets the origin for logical screen coordinates to the center, depending
on the video mode */
void set_center_origin(void)
{
int xcent, ycent;
struct videoconfig vc;
_getvideoconfig(&vc);
xcent = vc.numxpixels / 2 - 1;
ycent = vc.numypixels / 2 - 1;
_setlogorg(xcent, ycent);
}
/* Sets a type font for graphics mode display
Returns FALSE if the video driver is unable to set the desired combination*/
boolean set_font(short font, /// Fonts 1 thru 6 defined in "numfun.h"
short size) /// Size of type displayed, range 1..10
{
char list[20], * temp;
switch (font)
{
case COUR :
strcat( strcat( strcpy( list, "t'" ), "courier" ), "'");
break;
case HELV :
strcat( strcat( strcpy( list, "t'" ), "helv" ), "'");
break;
case MOD :
strcat( strcat( strcpy( list, "t'" ), "modern" ), "'");
break;
case ROM :
strcat( strcat( strcpy( list, "t'" ), "roman" ), "'");
break;
case TRMN :
strcat( strcat( strcpy( list, "t'" ), "tms rmn" ), "'");
break;
case SCRP :
strcat( strcat( strcpy( list, "t'" ), "script" ), "'");
break;
case HELVE :
strcat( strcat( strcpy( list, "t'" ), "helve" ), "'");
break;
case HELVF :
strcat( strcat( strcpy( list, "t'" ), "helvf" ), "'");
break;
case TRMNE :
strcat( strcat( strcpy( list, "t'" ), "trmne" ), "'");
break;
case TRMNF :
strcat( strcat( strcpy( list, "t'" ), "trmnf" ), "'");
break;
case VGAFIX :
strcat( strcat( strcpy( list, "t'" ), "vgafix" ), "'");
break;
case VGAOEM :
strcat( strcat( strcpy( list, "t'" ), "vgaoem" ), "'");
break;
case VGASYS :
strcat( strcat( strcpy( list, "t'" ), "vgasys" ), "'");
break;
default :
_outtext("Cant set that font identifier\n Press A key...");
getch();
break;
}
switch (size)
{
case 1 :
strcat( list, "h4w3b" );
break;
case 2 :
strcat( list, "h10w8b" );
break;
case 3 :
strcat( list, "h12w9b" );
break;
case 4 :
strcat( list, "h15w12b" );
break;
case 5 :
strcat( list, "h18w22b" );
break;
case 6 :
strcat( list, "h20w16b" );
break;
case 7 :
strcat( list, "h25w20b" );
break;
case 8 :
strcat( list, "h30w24b" );
break;
case 9 :
strcat( list, "h38w32b" );
break;
case 10:
strcat( list, "h42w35b" );
break;
default:
_outtext(" Font size must be in the range 1..10\n Press A Key...");
getch();
break;
}
if ( _setfont( list ) == FALSE )
{
sprintf( temp, "Can't set font %s\n Press A Key...\0", list );
_outtext( temp );
getch();
return( FALSE );
}
_getfontinfo( &fi );
return( TRUE );
}
void mixall(void)
{
int x = 1;
int type = 1;
int color = 1;
unsigned cnum;
while ( !kbhit())
for (color = 1; color <= vc.numcolors; color++)
{
if (++x % 300 == 0)
++type;
if (type == 6)
type = 1;
cnum = get_color(&type, &r, &g, &b);
_remappalette(color, cnum);
/*if (color == vc.numcolors)
color = 1; */
}
getch();
/// _remapallpalette(color_array);
}
boolean reset_mouse(void)
/* This function initializes the mouse for programs that require one.
It is a redefinition of the QuickC Toolbox mouse_reset() function,
since the programs I write which require a mouse need two buttons.
The function returns FALSE if a two-button mouse is not installed. */
{
mouse_t status; /// Mouse status, ie. installed or not.
mouse_t buttons; /// Number of buttons available on mouse.
mouse_reset( &status, &buttons );
if ( ( status NE -1 ) OR ( buttons NE 2 ) )
return( FALSE );
///else
/// mouse_setgcurs( &gcursor_hand );
return( TRUE );
}