home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * dazzle.c
- *
- * A simple graphics program demo for the Amiga by
- * M. Peter Engelbrite
- *
- * A note about the name "dazzle"- back in the days of
- * MITS(Altair), SWTP and Processor Technology, there was
- * a color graphics board for the S-100 named the "Dazzler".
- * A computer program came with this board named "Dazzle".
- * That program had the same type of eight-fold symmetry that
- * my program does (although it was much simpler in the
- * generation of the patterns). Legend has it that a 'mystery'
- * programmer wrote that program in a few hours, and sold it
- * to Chromemco (the manufacturer) for a song. Whenever I
- * experiment with a graphics system, I test it with some
- * version of this program and name it Dazzle in honor of that
- * mystery programmer.
- *
- * Many thanks to Scott Ballantyne for "sparks", portions of
- * which were used in this program.
- *
- ************************************************************************/
-
- /* Because of a wierd bug in the current Manx C compiler I am using */
- /* (versions 1.99G), the comments below have been moved to their current */
- /* location, from the end of the include file lines. Fred Fish, 3/8/86 *
-
- /* Not all of these are used -- I include them */
- /* 'cause I'm sick of compiler warnings. */
- #pragma inline
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- #define MAXX 320
- #define MAXY 200
- #define row 100
- #define col 150
- #define INIT 1
- #define EXEC 0
-
- /* if you make any changes, please update the version number
- following the decimal */
-
- int PauseMode, TitleOn;
- int offsa, offsb;
- int color, cyclecnt;
- unsigned char *Epal;
-
- /* these are utility functions for use in changing colors */
- /* randomly select a new color, also randomizes the hue for that color */
- newcolor()
- {
- color = RangeRand(255) + 1; /* leave lower colors alone */
- /* give it a new look, also */
- Epal[color*3] = (Epal[(color-1)*3] + RangeRand(6))%32;
- Epal[color*3+1] = (Epal[(color-1)*3+1] + RangeRand(6))%32;
- Epal[color*3+2] = (Epal[(color-1)*3+2] + RangeRand(6))%32;
- SetPal( Epal );
- }
-
- /* selects the next in sequence of available colors */
- nextcolor()
- {
- if(++color > 255) color = 1;
- }
-
- /* sets a specific color */
- setcolor(coler)
- int coler;
- {
- color = coler;
- if(color == 0) color = 1;
- }
-
- /* user definable graphics functions */
- /* each function should set offsa and offsb and optionally chage the color
- it may maintain local variables, it should accept a value init which
- is set to TRUE to indicate that initialization is to occur. offsa and
- offsb should range between 0 and 99 (overflow is not fatal, though).
- The function may call setcolor(n), newcolor(), or nextcolor() to change
- the color. The name of your function must be added to the structure
- dotfunc in do_dazzle() at the end of this module. You will find that
- it is very easy to experiment and obtain interesting effects.
- */
-
- streamer(init)
- int init;
- {
- static int cnt1, cnt2, cnt3;
-
- if(init)
- {
- cnt1 = cnt2 = 0;
- cnt3 = 24;
- }
- if(cnt1++ > cnt2)
- {
- offsa -= cnt2;
- cnt1 = 0;
- cnt2 = cnt2 + 1;
- if (cnt2 > cnt3)
- {
- cnt2 = 0;
- if((cnt3 = cnt3 + RangeRand(4)) > 44) cnt3 = 0;
- }
- if(offsb++ >= 99) offsb = 0;
- }
- if(offsa++ >= 99) offsa = 0;
- if(RangeRand(1000) == 0) newcolor();
- }
-
- lotsadots(init)
- int init;
- {
- offsa = RangeRand(100);
- offsb = RangeRand(100);
- newcolor();
- }
-
- ribbons(init)
- int init;
- {
- static int cnt1, cnt2, cnt3;
-
- if(init)
- {
- cnt1 = cnt2 = 0;
- cnt3 = 24;
- }
- if(cnt1++ > cnt2)
- {
- offsa -= cnt2;
- cnt1 = 0;
- cnt2 = cnt2 + 1;
- if (cnt2 > cnt3)
- {
- cnt2 = 0;
- if((cnt3 = cnt3 + RangeRand(4)) > 44) cnt3 = 0;
- }
- nextcolor();
- if(offsb++ >= 99) offsb = 0;
- }
- if(offsa++ >= 99) offsa = 0;
- if(RangeRand(1000) == 0) newcolor();
- }
-
-
- scribble(init)
- int init;
- {
-
- if((offsa = offsa + RangeRand(3) - 1) > 99) offsa = 0;
- if((offsb = offsb + RangeRand(3) - 1) > 99) offsb = 0;
- if(RangeRand(500) == 0) newcolor();
- }
-
- curves(init)
- int init;
- {
- static int wid, andx, bndx, aspeed, bspeed;
-
- if(init)
- {
- andx = bndx = wid = 0;
- aspeed = RangeRand(64) + 20;
- bspeed = RangeRand(64) + 20;
- newcolor();
- }
-
- if((wid = (wid + 1) & 15) == 0)
- {
- offsa = (int)(sin((double)andx * .0005) * 42.0) + 42;
- offsb = (int)(sin((double)bndx * .0005) * 42.0) + 42;
- andx += aspeed;
- bndx += bspeed;
- if(andx > 32000) andx = 0;
- if(bndx > 32000) bndx = 0;
- nextcolor();
- }
- else
- offsa++;
- }
-
- lines(init)
- int init;
- {
- static int wid, aspeed, bspeed, ndx;
-
- if(init)
- {
- wid = ndx = 0;
- aspeed = bspeed = 1;
- }
- if((wid = (wid + 1) & 3) == 0)
- {
- offsa += aspeed;
- ndx += bspeed;
- if(offsa < 0)
- {
- aspeed = 1;
- offsa = 0;
- if(RangeRand(3) == 0) newcolor();
- }
- if(ndx < 0)
- {
- bspeed = RangeRand(4) + 1;
- ndx = 0;
- }
- if(offsa >= 100)
- {
- aspeed = - 1;
- offsa = 99;
- }
- if(ndx >= 97)
- {
- bspeed = 0 - (RangeRand(4) + 1);
- ndx = 96;
- }
- offsb = ndx;
- }
- else
- offsb++;
- }
-
- squares(init)
- int init;
- {
- static int aend, astrt, sqcnt;
-
- if(init) sqcnt = 0;
- if(sqcnt != 0) {
- if(++offsa > aend) {
- offsa = astrt;
- offsb++;
- sqcnt--;
- if(offsb > 99) {
- sqcnt = 0;
- offsb = 99;
- }
- nextcolor();
- }
- }
- if(sqcnt == 0) {
- sqcnt = (RangeRand(10)) + 8;
- offsa = (astrt = RangeRand(64));
- aend = (RangeRand(64)) + astrt + 8;
- if(aend > 99) aend = 99;
- while((offsb = RangeRand(128)) > 99);
- newcolor();
- }
- }
-
- triangles(init)
- int init;
- {
- static int aend, astrt, sqcnt;
-
- if(init) sqcnt = 0;
- if(sqcnt != 0) {
- if(++offsa > aend) {
- nextcolor();
- astrt++;
- aend--;
- if(astrt >= aend) {
- sqcnt = 0;
- } else {
- offsa = astrt;
- offsb++;
- if(offsb > 99) {
- sqcnt = 0;
- offsb = 99;
- }
- }
- }
- }
- if(sqcnt == 0) {
- sqcnt = 1;
- offsa = (astrt = RangeRand(64));
- aend = RangeRand(64) + astrt + 8;
- if(aend > 99) aend = 99;
- offsb = RangeRand(100);
- newcolor();
- }
- }
-
- zigzags(init)
- int init;
- {
- static int cnt, andx, bndx;
-
- if(init) cnt = -1;
- if(cnt-- <= 0)
- {
- andx = RangeRand(3) - 1;
- bndx = RangeRand(3) - 1;
- cnt = RangeRand(15);
- newcolor();
- }
- offsa += andx;
- offsb += bndx;
- if(offsa <= 0 || offsa >= 99) andx = -andx;
- if(offsb <= 0 || offsb >= 99) bndx = -bndx;
-
- }
-
- grid(init)
- int init;
- {
- static int aend, astrt, xcol, imagepnt, imagestrt;
- static char image[] =
- {
-
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,0,1,1,0,0,
- 1,1,0,0,0,1,1,1,
- 1,1,1,0,0,0,1,1,
- 0,0,1,1,0,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
-
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,1,1,0,0,0,0,
- 1,1,1,0,0,0,1,1,
- 1,1,0,0,0,1,1,1,
- 0,0,0,0,1,1,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
-
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 1,1,0,1,1,0,1,1,
- 1,1,0,1,1,0,1,1,
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
-
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,
- 0,0,0,1,1,0,0,0,
- 0,0,0,1,1,0,0,0,
-
- };
-
- if((imagepnt & 63) == 0 || init)
- {
- imagestrt = RangeRand(4) * 64;
- offsa = RangeRand(12) * 8;
- astrt = offsa;
- aend = offsa + 7;
- offsb = RangeRand(12) * 8;
- imagepnt = imagestrt;
- if(RangeRand(25) == 0)
- {
- newcolor();
- xcol = RangeRand(24) + 5;
- }
- offsa--;
- }
- if(++offsa > aend)
- {
- offsa = astrt;
- offsb++;
- }
- color = (image[imagepnt++]) ? xcol : 0;
- }
-
- diag1(init)
- int init;
- {
- offsb--;
- if(offsa++ > 98) {
- offsa = 0;
- offsb++;
- nextcolor();
- }
- if(offsb < 0) {
- offsb = 99;
- }
- }
-
- diag2(init)
- int init;
- {
- offsb++;
- if(offsa++ > 98) {
- offsa = 0;
- offsb--;
- nextcolor();
- }
- if(offsb > 99) {
- offsb = 0;
- }
- }
-
- diag3(init)
- int init;
- {
- static int cnt, cnt2;
-
- if(init) cnt = cnt2 = 0;
-
- offsb++;
- if(offsa++ > 98)
- {
- offsa = 0;
- offsb--;
- color = 4;
- if(++cnt2 > 20) cnt2 = 0;
- }
- if(cnt++ > cnt2)
- {
- cnt = 0;
- if(color++ > 255) color = 4;
- }
- if(offsb > 99) offsb = 0;
- }
-
- diag4(init)
- int init;
- {
- offsb--;
- if(offsa++ > 98) {
- offsa = 0;
- offsb++;
- }
- if(offsb < 0) {
- offsb = 99;
- }
- setcolor(((offsa * offsb) >> 4) & 31);
- }
-
- sweep(init)
- int init;
- {
- static int ainc, alen;
-
- if(init || alen > 51)
- {
- alen = ainc = offsa = offsb = 0;
- }
- if(ainc++ > alen)
- {
- offsb++;
- ainc = 0;
- }
- if(offsa++ >= 99)
- {
- nextcolor();
- alen++;
- offsa = offsb = 0;
- }
- }
-
- fadein(init)
- int init;
- {
- offsa = RangeRand(99) + 1;
- offsb = RangeRand(99) + 1;
- setcolor(offsa / offsb);
- }
-
- spiral(init)
- int init;
- {
- static int sidecnt, sidelen, colorcnt, dirndx, adir, bdir;
- static int newadir[] = {0,1,0,-1};
- static int newbdir[] = {1,0,-1,0};
-
- if(init || offsa >= 99 || offsb >= 99)
- {
- sidecnt = 100;
- sidelen = 0;
- dirndx = 0;
- offsa = RangeRand(99);
- offsb = RangeRand(99);
- colorcnt = 0;
- }
- if(sidecnt++ >= sidelen)
- {
- sidecnt = 0;
- dirndx = (dirndx + 1) & 3;
- if((dirndx & 1) == 0) sidelen++;
- adir = newadir[dirndx];
- bdir = newbdir[dirndx];
- }
- offsa += adir;
- offsb += bdir;
- if((colorcnt++ & 3) == 0) nextcolor();
-
- }
-
- spiral1(init)
- int init;
- {
- static int sidecnt, sidelen, dirndx, adir, bdir, size;
- static int newadir[] = {1,1,-1,-1};
- static int newbdir[] = {1,-1,-1,1};
-
- if(init || offsa >= 99 || offsb >= 99 || sidelen >= size)
- {
- sidecnt = 100;
- sidelen = 0;
- dirndx = 0;
- offsa = RangeRand(99);
- offsb = RangeRand(99);
- size = RangeRand(70);
- }
- if(sidecnt++ >= sidelen)
- {
- sidecnt = 0;
- if(++dirndx > 3)
- {
- sidelen++;
- offsa--;
- dirndx = 0;
- nextcolor();
- }
- adir = newadir[dirndx];
- bdir = newbdir[dirndx];
- }
- offsa += adir;
- offsb += bdir;
- }
-
- zigstream(init)
- int init;
- {
- static int sidecnt, sidelen, colorcnt, dirndx, adir, bdir;
- static int newadir[] = {0,1};
- static int newbdir[] = {1,0};
-
- if(init || offsa >= 99 || offsb >= 99)
- {
- sidecnt = 100;
- sidelen = 0;
- dirndx = 0;
- offsa = RangeRand(99);
- offsb = RangeRand(99);
- colorcnt = 0;
- setcolor(4);
- }
- if(sidecnt++ >= sidelen)
- {
- sidecnt = 0;
- if((++dirndx & 1) == 0)
- {
- sidelen++;
- dirndx = 0;
- }
- adir = newadir[dirndx];
- bdir = newbdir[dirndx];
- }
- offsa += adir;
- offsb += bdir;
- if((colorcnt++ & 3) == 0) nextcolor();
-
- }
-
- formula1(init)
- int init;
- {
- static int cona, conb, conx;
-
- if(init || offsa > 99)
- {
- offsa = 0;
- offsb = -1;
- cona = RangeRand(2) + 1;
- conb = RangeRand(3) + 1;
- conx = RangeRand(4) + 2;
- }
- if(offsb++ > offsa)
- {
- offsa++;
- offsb = 0;
- }
- setcolor(((offsb * offsb * conb) - (offsa << cona)) >> conx);
- }
-
- cycolor()
- {
- int i, j;
- char red, green, blue;
-
- red = Epal[3];
- green = Epal[4];
- blue = Epal[5];
- for( i=1; i<255; i++ )
- {
- for( j=0; j<3; j++ )
- Epal[i*3+j] = Epal[(i+1)*3+j];
- }
- Epal[255*3] = red;
- Epal[255*3+1] = green;
- Epal[255*3+2] = blue;
- SetPal( Epal );
- cyclecnt = 50;
- }
-
- do_dazzle()
- {
- int (*currentfunc)();
- int type, typecnt, typetime;
-
- struct dotfuncs
- {
- int (*func)();
- int maxtime;
- };
-
- /* add the names of the custom graphics functions here */
- static struct dotfuncs dotfunc[] =
- {
- /* function name, number of cycles to run (randomized) */
- formula1, 15000,
- lotsadots, 6000,
- streamer, 2000,
- ribbons, 6000,
- curves, 6000,
- lines, 4000,
- squares, 6000,
- triangles, 8000,
- zigzags, 6000,
- grid, 6000,
- diag1, 8000,
- diag2, 8000,
- diag3, 12000,
- diag4, 12000,
- sweep, 3000,
- fadein, 15000,
- spiral, 15000,
- spiral1, 15000,
- zigstream, 10000
- };
-
- newcolor();
- cyclecnt = offsa = offsb = 0;
- typecnt = 100;
- typetime = 10;
-
- while( 1 )
- {
- if( bioskey(1) )
- return;
- if(typecnt++ > typetime)
- {
- type = RangeRand((sizeof(dotfunc) / sizeof(struct dotfuncs)));
- typecnt = 0;
- typetime = RangeRand(dotfunc[type].maxtime);
- if(RangeRand(5) == 0)
- {
- /* clear screen here */
- clr_screen();
- newcolor();
- }
- currentfunc = dotfunc[type].func;
- (*currentfunc)(INIT); /* initialize */
- }
- (*currentfunc)(EXEC);
- if(offsa > 99)
- offsa = 99;
- if(offsb > 99)
- offsb = 99;
- if(cyclecnt-- <= 0)
- cycolor();
- WritePixel( col + offsb, row + offsa);
- WritePixel( col + offsb, row - offsa);
- WritePixel( col - offsb, row + offsa);
- WritePixel( col - offsb, row - offsa);
- WritePixel( col + offsa, row + offsb);
- WritePixel( col + offsa, row - offsb);
- WritePixel( col - offsa, row + offsb);
- WritePixel( col - offsa, row - offsb);
- }
- }
-
- setcolors()
- {
- printf( "Dazzle 1.1 by M. Peter Engelbrite\n" );
- printf( "Turbo C version by Gary F. Syck\n" );
- printf( "\n\n\n\nPress Any Key" );
- bioskey( 0 );
- Epal[0] = 0;
- Epal[1] = 0;
- Epal[2] = 0;
- Epal[3] = RangeRand(32);
- Epal[4] = RangeRand(32);
- Epal[5] = RangeRand(32);
- for( color=2; color<256; color++ )
- {
- Epal[color*3] = (Epal[(color-1)*3] + RangeRand(6))%32;
- Epal[color*3+1] = (Epal[(color-1)*3+1] + RangeRand(6))%32;
- Epal[color*3+2] = (Epal[(color-1)*3+2] + RangeRand(6))%32;
- }
- SetPal( Epal );
- clr_screen();
- }
-
- main()
- {
- long t;
-
- Epal = malloc( 3*256 );
- clr_screen();
- setcolors();
-
- time( &t );
- srand((int) t );
- do_dazzle();
- bioskey( 0 );
- _AX = 0x3;
- asm int 10h;
- }
-
- int RangeRand( rng )
- int rng;
- {
- return rand()%rng;
- }
-
- WritePixel( x, y )
- int x, y;
- {
- _DX = y;
- _CX = x;
- _AL = color;
- _AH = 0xc;
- asm int 10h;
- }
-
- clr_screen()
- {
- _AX = 0x13; /* set mode 13 */
- asm int 10h;
- }
-
- GetPal( Buf )
- char *Buf;
- {
- asm push ds;
- asm pop es;
- _DX = Buf;
- _BX = 0;
- _CX = 256;
- _AX = 0x1017;
- asm int 10h;
- }
-
- SetPal( Buf )
- char *Buf;
- {
- asm push ds;
- asm pop es;
- _DX = Buf;
- _BX = 0;
- _CX = 256;
- _AX = 0x1012;
- asm int 10h;
- }
-