home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Share Gallery 1
/
share_gal_1.zip
/
share_gal_1
/
GA
/
GA025.ZIP
/
KALEDIS.C
next >
Wrap
Text File
|
1988-04-08
|
6KB
|
229 lines
/*
* KALEDIS EGA/VGA Kaleidoscope
*
* Judson D. McClendon
* Sun Valley Systems
* 844 Sun Valley Road
* Birmingham, AL 35215
* (205) 853-8440
* Compuserve [74415,1003]
*/
/*
* Compiled using Microsoft C 5.0 with option /Ox
*/
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <graph.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys\timeb.h>
#define TRUE 1
#define FALSE 0
#define MAXCOLORS 16
#define ESC 27
void main(void); /* Main */
void curpos(int, int); /* Position cursor to row, col */
void printat(int, int, char *); /* Print string at row, col */
int getkey(void); /* Get decoded keypress no echo */
int random(int); /* Generate Random Number 0 <= r < n */
int X1, Y1, X2, Y2, XV1, YV1, XV2, YV2, HC, XA, YA, XB, YB, chr;
int i, bc = 1, delay = 0;
int wid = 4, hgt = 3;
int CX = 320, CY = 240, M = 240;
long far Pcol[MAXCOLORS];
long Red, Green, Blue;
long dummy = 0;
struct timeb TIME;
struct videoconfig VC;
enum {VGA,EGA} adapter = VGA;
void main() /* main */
{
_getvideoconfig(&VC);
_clearscreen(_GCLEARSCREEN);
printat( 3,25, "K A L E I D O S C O P E");
printat( 5,25, "Version 2.1 for EGA/VGA");
printat( 7,27, "Judson D. McClendon");
printat( 8,27, "844 Sun Valley Road");
printat( 9,27, "Birmingham, AL 35215");
printat(10,31, "205-853-8440");
printat(11,26, "Compuserve [74415,1003]");
printat(13,23, "Press 'P' to pause,");
printat(14,29, "'C' to clear screen,");
printat(15,29, "'B' to toggle background,");
printat(16,29, "'0'-'9' set speed,");
printat(17,29, "ESCape to exit,");
printat(18,29, "any key to begin/resume...");
chr = getkey();
if (chr == ESC)
exit(0);
ftime(&TIME); /* Initialize random number generator */
srand(TIME.millitm);
if (! _setvideomode(_VRES16COLOR)) { /* VGA 640x480x16 color */
CY = 175;
wid = 9;
hgt = 5;
adapter = EGA;
if (! _setvideomode(_ERESCOLOR)) { /* EGA 640x350x16 color */
printat(20,25, "Must have EGA or VGA!");
exit(1);
}
}
M = CY - 1;
while (TRUE) {
Pcol[0] = 0L;
Pcol[0] = 0L;
for (i = bc; i < MAXCOLORS; i++) {
Red = (long)random(64);
Green = (long)random(64);
Blue = (long)random(64);
Pcol[i] = ((Blue << 8 | Green) << 8 | Red);
}
_remapallpalette(&Pcol[0]);
_clearscreen(_GCLEARSCREEN);
X1 = random(M) + 1;
X2 = random(M) + 1;
Y1 = random(X1);
Y2 = random(X2);
while (random(200) > 1) {
XV1 = random(11) - 5;
XV2 = random(11) - 5;
YV1 = random(11) - 5;
YV2 = random(11) - 5;
HC = random(16);
_setcolor(HC);
while (random(10) > 1) {
XA = X1 * wid / hgt;
XB = X2 * wid / hgt;
YA = Y1 * wid / hgt;
YB = Y2 * wid / hgt;
_moveto( (CX+XA), (CY-Y1) ); _lineto( (CX+XB), (CY-Y2) );
_moveto( (CX-YA), (CY+X1) ); _lineto( (CX-YB), (CY+X2) );
_moveto( (CX-XA), (CY-Y1) ); _lineto( (CX-XB), (CY-Y2) );
_moveto( (CX-YA), (CY-X1) ); _lineto( (CX-YB), (CY-X2) );
_moveto( (CX-XA), (CY+Y1) ); _lineto( (CX-XB), (CY+Y2) );
_moveto( (CX+YA), (CY-X1) ); _lineto( (CX+YB), (CY-X2) );
_moveto( (CX+XA), (CY+Y1) ); _lineto( (CX+XB), (CY+Y2) );
_moveto( (CX+YA), (CY+X1) ); _lineto( (CX+YB), (CY+X2) );
X1 = (X1 + XV1) % M;
Y1 = (Y1 + YV1) % M;
X2 = (X2 + XV2) % M;
Y2 = (Y2 + YV2) % M;
if (delay) {
for (i = 1; i < delay; i++)
dummy += i * delay;
dummy -= delay;
;
}
};
if (kbhit()) {
chr = getkey();
if (chr == 'P') {
getkey();
}
else if (chr == ESC) {
_clearscreen(_GCLEARSCREEN);
_setvideomode(_DEFAULTMODE);
exit(0);
}
else if (chr == 'C') {
break;
}
else if (chr == 'B') {
bc = 1 - bc;
break;
}
else if (isdigit(chr)) {
delay = ('9' - chr) * 3000;
}
}
} /* while (line) */
} /* while (screen) */
_setvideomode(_DEFAULTMODE);
exit(0);
}
/*
* Position cursor to row, col
*/
void curpos(int row, int col)
{
union REGS cpu;
cpu.h.ah = 2;
cpu.h.dh = (char)row -1;
cpu.h.dl = (char)col -1;
cpu.h.bh = 0;
int86(16, &cpu, &cpu);
}
/*
* Position cursor to row, col
*/
int getkey(void) /* Get decoded keypress no echo */
{
int chr;
chr = getch();
if (chr) {
return(toupper(chr));
}
else {
return(1000 + getch());
}
}
/* Print string at row, col */
void printat(int row, int col, char *fld)
{
curpos(row, col);
cputs(fld);
}
int random(int r) /* Generate Random Number 0-r */
{
int s;
long t;
s = rand();
t = (long) s * r / 32768;
return((int) t);
}