home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff304.lzh
/
Circles
/
circles.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-10
|
9KB
|
437 lines
/*
* circles.c : Color circle pattern generator experimental interface
*
* this stuf adapted from mackie.c on fish disk 131.
* by Joel Swank 11-16-88
*
* Version 1.1 5/27/89
*
*
*/
#include "window.h"
/*
* The maximum number of lines on the screen at once.
*/
#define MAXLINES (100)
#define XRAS 100
#define YRAS 100
#define INTUITION_REV 1L
/*
* The global variables.
*/
struct GfxBase *GfxBase = NULL;
struct RastPort *rastport ;
int screenheight, screenwidth;
int erasecolor, curcolor = 1 ;
struct Screen *scr = NULL, *OpenScreen() ;
struct Window *Wind = NULL, *OpenWindow() ;
struct MsgPort *CreatePort() ;
struct IntuitionBase *IntuitionBase = NULL;
struct IntuiMessage *msg, *GetMsg();
struct Library *OpenLibrary();
WORD areabuffer[250];
struct TmpRas tmpras, *InitTmpRas();
struct AreaInfo myAreaInfo;
PLANEPTR planeptr = NULL, AllocRaster();
struct TextFont *OpenFont();
struct Window *wH = NULL; /* help window */
struct RastPort *rpH = NULL; /* help RastPort */
struct TextFont *font = NULL;
USHORT keycode, stop, rotcolor, bkgnd, freeze, erase;
ULONG class;
/*
* MainLine
*/
main() {
long i ;
char buf[100];
screenheight = YSIZE;
screenwidth = XSIZE;
if ((IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", INTUITION_REV)) == NULL)
done(21);
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", NULL);
if (GfxBase == NULL) done(22);
if ( (scr = OpenScreen(&newscreen)) == NULL)
{
AutoRequest(0L,&scrfailtxt,0L,&oktxt,0L,0L,300L,75L);
done(26);
}
New_Window.Screen = scr;
if ((Wind = (struct Window *) OpenWindow(&New_Window)) == NULL)
done(25);
rastport = Wind->RPort;
InitArea(&myAreaInfo,areabuffer,100);
rastport->AreaInfo = &myAreaInfo;
if ((planeptr=AllocRaster(XRAS,YRAS)) == NULL)
done(18);
rastport->TmpRas = InitTmpRas(&tmpras,planeptr,RASSIZE(XRAS,YRAS));
LoadRGB4(&(scr->ViewPort),&Palette,PaletteColorCount);
do_help();
clr_grf();
startlines() ;
/*for (i=0; i<MAXLINES; i++) {
advancelines() ;
drawnew() ;
} */
colors() ;
stop = FALSE;
freeze = FALSE;
erase = TRUE;
rotcolor = TRUE;
while (1) {
while((msg = (struct IntuiMessage *) GetMsg(Wind->UserPort)) ||
(msg = (struct IntuiMessage *) GetMsg(wH->UserPort))) {
keycode = msg->Code;
class = msg->Class;
ReplyMsg(msg);
switch(class) {
case VANILLAKEY:
switch (keycode)
{
case ' ': /* start/stop */
if (stop == TRUE) stop = FALSE;
else stop = TRUE;
break;
case 'o': /* one iteration */
stop = TRUE;
goto once;
case 'r': /* toggle pallete changes */
if (rotcolor == TRUE) rotcolor = FALSE;
else rotcolor = TRUE;
break;
case 'b': /* Black/white background */
if (bkgnd)
{
bkgnd = FALSE;
SetRGB4(&(scr->ViewPort), 0L, 0L, 0L, 0L);
} else {
SetRGB4(&(scr->ViewPort), 0L, 15L, 15L, 15L);
bkgnd = TRUE;
}
break;
case 'f': /* freeze/thaw color changing */
if (freeze == TRUE) freeze = FALSE;
else freeze = TRUE;
break;
case 'a': /* do about requester */
about();
break;
case 'q': /* Exit */
case 'x':
case '\033':
done(0);
break;
}
continue;
case REFRESHWINDOW :
draw_help();
break;
case CLOSEWINDOW:
done(0);
}
}
if (stop == TRUE)
{
Wait(( 1L << Wind->UserPort->mp_SigBit) | /* wait on mesg */
( 1L << wH->UserPort->mp_SigBit));
continue;
}
once:
advancelines() ;
drawnew() ;
colors() ;
advancelines() ;
drawnew() ;
colors() ;
advancelines() ;
drawnew() ;
colors() ;
advancelines() ;
drawnew() ;
colors() ;
advancelines() ;
drawnew() ;
colors() ;
advancelines() ;
drawnew() ;
colors() ;
}
}
/*
* End of MainLine
*/
/*
* done - just clean up that which is open, and then leave.
*/
done(how)
int how;
{
if (planeptr) FreeRaster(planeptr,XRAS,YRAS);
if (wH) CloseWindow(wH) ;
if (Wind) CloseWindow(Wind) ;
if (scr) CloseScreen(scr) ;
if (font) CloseFont(font) ;
if (IntuitionBase) CloseLibrary(IntuitionBase) ;
if (GfxBase) CloseLibrary(GfxBase) ;
/* OpenWorkBench() ; /* As requested */
exit(how) ;
}
/*
* This routine returns a random value from 0 to n-1.
*/
int randm(i)
int i ;
{
static long seed ;
long rval ;
if (seed == 0)
seed = 323214521 + scr->MouseX +
scr->MouseY ;
seed = seed * 123213 + 121 ;
rval = (seed >> 5) & 65535 ;
return ((i * rval) >> 16) ;
}
/*
* This routine sets x and y values to a random number.
*/
static long x, y ;
randomxy() {
x = randm(screenwidth) ;
y = randm(screenheight) ;
}
/*
* Main routines are always fun.
*/
short x1store[MAXLINES], y1store[MAXLINES] ;
short x2store[MAXLINES], y2store[MAXLINES] ;
short ptr ;
short dx1, dy1, dx2, dy2 ;
short ox1, oy1, ox2, oy2 ;
short nx1, ny1, nx2, ny2 ;
short dr[8], dg[8], db[8] ;
short or, og, ob ;
short nr[8], ng[8], nb[8] ;
/*
* Initialize things for the first lines.
*/
startlines() {
int i;
ptr = 0 ;
ox1 = randm(screenwidth) ;
ox2 = randm(screenwidth) ;
oy1 = randm(screenheight) ;
oy2 = randm(screenheight) ;
dx1 = 13 ;
dx2 = 14 ;
dy1 = 11 ;
dy2 = 16 ;
for (i=0;i < 8; i++)
{
nr[i] = (short) ((Palette[i] >>8) & 15) <<3;
ng[i] = (short) ((Palette[i] >>4) & 15) <<3;
nb[i] = (short) (Palette[i] & 15) <<3;
dr[i] = -3 ;
dg[i] = 5 ;
db[i] = 7 ;
}
}
/*
* Advance the number by the delta, and check the boundaries.
*/
adv(o, d, n, w)
short *o, *d, *n ;
long w ;
{
*n = *o + *d ;
if (*n < 0) {
*n = 0 ;
*d = randm(12) + 7 ;
} else if (*n >= w) {
*n = w - 1 ;
*d = - randm(12) - 7 ;
}
}
/*
* Advance the number by the delta, and check the boundaries.
*/
advc(o, d, n, w)
short *o, *d, *n ;
long w ;
{
*n = *o + *d ;
if (*n < 0) {
*n = 0 ;
*d = randm(6) + 1 ;
} else if (*n >= w) {
*n = w - 1 ;
*d = - randm(6) - 1 ;
}
}
/*
* Advance the two points which make up the lines.
*/
advancelines() {
adv(&ox1, &dx1, &nx1, screenwidth) ;
adv(&ox2, &dx2, &nx2, screenwidth) ;
adv(&oy1, &dy1, &ny1, screenheight) ;
adv(&oy2, &dy2, &ny2, screenheight) ;
}
/*
* Draw a new set of filled circles.
*/
drawnew() {
x1store[ptr] = ox1 = nx1 ;
x2store[ptr] = ox2 = nx2 ;
y1store[ptr] = oy1 = ny1 ;
y2store[ptr] = oy2 = ny2 ;
DrawSpot((long)ox2, (long)oy2) ;
DrawSpot((long)(screenwidth-ox1-1), (long)(screenheight-oy1-1)) ;
DrawSpot((long)(screenwidth-ox2-1), (long)(screenheight-oy2-1)) ;
DrawSpot((long)ox1, (long)oy1) ;
ptr++ ;
if (ptr == MAXLINES)
ptr = 0 ;
}
/*
* Draw a filled circle at given location with clipping
*/
DrawSpot(x,y)
long x,y;
{
long radi;
radi = randm(30)+10;
if (x<radi) radi = x;
if (x+radi>XSIZE) radi = XSIZE-x;
if (y<radi) radi = y;
if (y+radi>YSIZE) radi = YSIZE-y;
if (radi > 1)
{
AreaEllipse(rastport,x,y,radi,radi);
AreaEnd(rastport);
}
}
/*
* This routine mucks with the colors.
*/
colors() {
if (!freeze)
{
if (++curcolor > 7) curcolor = 1 ;
SetAPen(rastport, (long)curcolor) ;
}
if (rotcolor )
{
or = nr[curcolor] ;
og = ng[curcolor] ;
ob = nb[curcolor] ;
advc(&or, &dr[curcolor], &nr[curcolor], 128) ;
advc(&og, &dg[curcolor], &ng[curcolor], 128) ;
advc(&ob, &db[curcolor], &nb[curcolor], 128) ;
SetRGB4(&(scr->ViewPort), (long)curcolor, (long)(nr[curcolor] >> 3),
(long)(ng[curcolor] >> 3), (long)(nb[curcolor] >> 3)) ;
}
}
/*
* do_help - display help text
*/
do_help()
{
NewWindowStructureHelp.Screen = scr;
wH = OpenWindow(&NewWindowStructureHelp); /* open the window */
if ( wH == NULL )
{
AutoRequest(Wind,&winfailtxt,0L,&oktxt,0L,0L,300L,75L);
done(20);
}
rpH = wH->RPort; /* get a rastport pointer for the window */
font = OpenFont(&TOPAZ80); /* make sure correct size font */
if (font) SetFont(rpH,font);
SetAPen(rpH,1L);
draw_help();
}
draw_help()
{
int i;
for (i=0; i<MAXHELP; i++) /* dump the whole help text array */
{
if (!HelpText[i]) break;
Move(rpH,5L,(long) (i+1)*9+20);
Text(rpH,HelpText[i], (long) strlen(HelpText[i]));
}
}
/*
* Handle 'about' request
*/
about()
{
AutoRequest(wH,&aboutmsg,0L,&oktxt,0L,0L,300L,75L);
}
clr_grf()
{
SetAPen(rastport, 0L) ;
Forbid() ;
RectFill(rastport, 0L, 0L, (long)screenwidth-1, (long)screenheight-1) ;
Permit() ;
SetAPen(rastport, 1L) ;
}
#ifdef AZTEC_C
/*
* Gracefull exit
*/
_abort()
{
done(13);
}
_wb_parse()
{
}
#endif