home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Adventures in Heaven 2
/
adventuresinheaven2powergamesfordosandwindows.iso
/
dos
/
demos
/
scope
/
ascope.c
next >
Wrap
C/C++ Source or Header
|
1989-07-12
|
6KB
|
260 lines
/*
ascope.c, version 1.0
by Aaron Contorer, 1989
This program draws a kaleidoscope in the VGA 16-color, 640x480 resolution
graphics mode. It works ONLY on the VGA, as it takes advantage of the
large number of colors available on this graphics adapter.
Written in Microsoft Quick C 1.0.
This program is PUBLIC DOMAIN, so you may use, distribute, or modify it
as you wish. Please send the author a copy of anything interesting you do
with this program, and if you use some of this program in another program,
an acknowledgement on the screen would be appreciated. The author disclaims
all liability of any sort and all warranties on this program.
You can contact the author on CompuServe (address 71571,1773) or by mail at:
Aaron Contorer
President, Contorer Computing
Post Office Box 5056
Champaign, IL 61825
United States of America
*/
#include <graph.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#define MINBRIGHT 7
#define RANDOMTURN 300
/* How likely is a random turn-around, on a scale of 32767 */
#define MAXLINE 50
/* how many lines on the screen at a time */
#define COLORSTEP 7
int lastx=639;
int lasty=479;
int lastbigx = 599 << 4;
int lastbigy = 439 << 4;
#define MAPSIZE 16
long colormap[MAPSIZE];
long findnewcolor(char[]);
/* Find a new color similar to the given color */
long findnewcolor(char *old)
{
int red = old[0];
int green = old[1];
int blue = old[2];
int r;
r=rand();
if (r & 8) red += r & COLORSTEP;
else red -= r & COLORSTEP;
r >>= 4;
if (r & 8) green += r & COLORSTEP;
else green -= r & COLORSTEP;
r >>= 4;
if (r & 8) blue += r & COLORSTEP;
else blue -= r & COLORSTEP;
if (blue>0x3f) blue=0x3f;
else if (blue<MINBRIGHT) blue=MINBRIGHT;
if (green>0x3f) green=0x3f;
else if (green<MINBRIGHT) green=MINBRIGHT;
if (red>0x3f) red=0x3f;
else if (red<MINBRIGHT) red=MINBRIGHT;
return (((long)blue) << 16) | (green<<8) | red;
}
void initcolormap(void);
void initcolormap()
{
int i;
colormap[0] = 0L; /* the "erase" color never changes */
colormap[1] = 0x3f3f3fL; /* a color to start with */
for (i=2; i<MAPSIZE; i++) colormap[i] = findnewcolor(&colormap[i-1]);
for (i=0; i<MAPSIZE; i++) _remappalette(i, colormap[i]);
}
void rotatecolormap(int);
void rotatecolormap(int newcolor)
{
int i;
int prevcolor;
if (newcolor>1) prevcolor = newcolor-1;
else prevcolor = MAPSIZE-1;
colormap[newcolor] = findnewcolor(&colormap[prevcolor]);
_remappalette(newcolor, colormap[newcolor]);
}
void mirrorline(int,int,int,int);
void mirrorline(x0,y0,x1,y1)
{
x0 >>= 4;
y0 >>= 4;
x1 >>= 4;
y1 >>= 4;
_moveto(x0,y0);
_lineto(x1,y1);
_moveto(lastx-x0, y0);
_lineto(lastx-x1, y1);
y0 = lasty-y0;
y1 = lasty-y1;
_moveto(x0,y0);
_lineto(x1,y1);
_moveto(lastx-x0, y0);
_lineto(lastx-x1, y1);
}
int randsign(void);
int randsign()
{
if (rand() & 1) return 1;
return -1;
}
#define isgn(i) (i<0 ? -1 : 1)
/* Signum macro */
#define randacc() ((rand() & 3) + 1)
void randomize(void);
/* Initialize random number generator to ensure a different result every
time the program is run. */
void randomize()
{
long temp;
time(&temp);
srand((unsigned)temp);
}
int main(void);
main()
{
int i;
int endpoint[MAXLINE][4]; /* circular buffer for endpoints */
int first=0;
int free=0;
int dx0,dy0,dx1,dy1; /* velocities of endpoints */
int ax0,ay0,ax1,ay1; /* accelerations of endpoints */
int x0,y0,x1,y1;
int colorcount, usecolor;
if (!_setvideomode(_VRES16COLOR)) {
puts("Sorry, this program requres a VGA graphics card.");
exit(1);
}
_settextposition(12,35);
_outtext("A-Scope 1.0");
_settextposition(14,30);
_outtext("by Aaron M. Contorer");
randomize();
x0=rand() & 0x3fff;
y0=rand() & 0x3fff;
x1=rand() & 0x3fff;
y1=rand() & 0x3fff;
dx0=randsign() * (rand() & 0x3f);
dx1=randsign() * (rand() & 0x3f);
dy0=randsign() * (rand() & 0x3f);
dy1=randsign() * (rand() & 0x3f);
ax0=randsign() * randacc();
ay0=randsign() * randacc();
ax1=randsign() * randacc();
ay1=randsign() * randacc();
colorcount = 1;
usecolor = 0;
initcolormap();
while (!kbhit()) {
if (--colorcount <= 0) {
colorcount = 4;
usecolor++;
if (usecolor>=MAPSIZE) usecolor = 1;
rotatecolormap(usecolor);
}
x0 += dx0;
x1 += dx1;
y0 += dy0;
y1 += dy1;
dx0 += ax0;
dy0 += ay0;
dx1 += ax1;
dy1 += ay1;
if (rand()<RANDOMTURN || x0<0 || x0>lastbigx) if (isgn(ax0)==isgn(x0)) {
ax0 = -isgn(ax0) * randacc();
dx0=0; }
if (rand()<RANDOMTURN || x1<0 || x1>lastbigx) if (isgn(ax1)==isgn(x1)) {
ax1 = -isgn(ax1) * randacc();
dx1=1; }
if (rand()<RANDOMTURN || y0<0 || y0>lastbigy) if (isgn(ay0)==isgn(y0)) {
ay0 = -isgn(ay0) * randacc();
dy0=0; }
if (rand()<RANDOMTURN || y1<0 || y1>lastbigy) if (isgn(ay1)==isgn(y1)) {
ay1 = -isgn(ay1) * randacc();
dy1=1; }
endpoint[free][0] = x0;
endpoint[free][1] = y0;
endpoint[free][2] = x1;
endpoint[free][3] = y1;
_setcolor(usecolor);
mirrorline(endpoint[free][0], endpoint[free][1],
endpoint[free][2], endpoint[free][3]);
free++;
if (free >= MAXLINE) free = 0;
if (free == first) {
/* erase oldest line */
_setcolor(0);
mirrorline(endpoint[first][0], endpoint[first][1],
endpoint[first][2], endpoint[first][3]);
first++;
if (first >= MAXLINE) first = 0;
}
}
getch();
_setvideomode(_DEFAULTMODE);
puts("Thank you for using A-scope. I hope you enjoyed this program!\n");
puts("Author: Aaron Contorer [71571,1773]");
puts(" President, Contorer Computing");
puts(" Box 5056, Champaign, IL 61825, USA");
return 0;
}