home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- SHM.C V1.42 Copyright 1987 C.Ediss 8th August 87
- ************************************************************************/
- /* The default pattern takes about 3.4 minutes to generate */
-
- #include <intuition/intuition.h>
- #include <float.h>
- #include <math.h>
-
- #include "shm_defines"
-
- extern struct Menu *SHMenu;
- extern void manual(),future(),parms(),palette();
- extern int cycle_time();
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct Screen *CustScr;
- struct Window *Wdw;
- struct IntuiMessage *message;
- struct ViewPort *WVP;
-
- USHORT col1[16] =
- {
- 0x000,0xFFF,0xF70,0x008,0xE66,0xFAB,0xFDB,0xFC0,
- 0xFF2,0xCF0,0x5D0,0x7DF,0x6AF,0xD0E,0xF2E,0x00F
- };
- USHORT col2[16];
-
- struct TextAttr Fnt =
- {
- "topaz.font",
- TOPAZ_EIGHTY,
- FS_NORMAL,
- FPF_ROMFONT
- };
-
- int hc = 345, hcd = 345, /* horizontal centre */
- vc = 115, vcd = 115, /* vertical centre */
- hs = 237, hsd = 237, /* horizontal size */
- vs = 75, vsd = 75; /* vertical size */
-
- double hpp = 2, hppd = 2, /* horizontal primary phase */
- vpp = 0, vppd = 0, /* vertical primary phase */
- hsp = 1, hspd = 1, /* horizontal secondary phase */
- vsp = 2, vspd = 2, /* vertical secondary phase */
- di = .00008, did = .00008, /* decay increment */
- sf = 2.04, sfd = 2.04, /* secondary frequency */
- cp = 0.4, cpd = 0.4; /* coupling */
-
- struct NewScreen NewCustScr =
- {
- 0,0, /* Left, Top */
- XMAX,YMAX,4, /* Width, Height, Depth */
- 0,1, /* DetailPen, BlockPen */
- HIRES, /* No INTERLACE */
- CUSTOMSCREEN, /* Screen Type */
- &Fnt, /* Pointer to custom font */
- NL, /* Pointer to screen title */
- NL, /* Pointer to screen gadgets */
- NL, /* Pointer to CustomBitMap */
- };
-
- struct NewWindow NewWdw =
- {
- 0,0, /* Left Top */
- XMAX,YMAX, /* Width Height */
- 0,1, /* Detail Block */
- MENUPICK | ACTIVEWINDOW | REQCLEAR | INTUITICKS,
- ACTIVATE | BORDERLESS | REPORTMOUSE,
- NL, /* Pointer to first gadget */
- NL, /* Pointer to check mark image */
- " SHM V1.42 Copyright 1987 C.Ediss. All Rights Reserved.",
- NL, /* Pointer to screen structure, dummy */
- NL, /* Pointer to custom bit map */
- 0,0, /* Minimum width, height */
- 0,0, /* Maximum width, height */
- CUSTOMSCREEN /* Type of screen it resides on */
- };
-
- /************************************************************************
- Fast Cosine Data Table
- ************************************************************************/
- double c[91] =
- {1.000,.9998,.9994,.9986,.9976,.9962,
- .9945,.9925,.9903,.9877,.9848,.9816,
- .9781,.9744,.9703,.9659,.9613,.9563,
- .9511,.9455,.9397,.9336,.9272,.9205,
- .9135,.9063,.8988,.8910,.8829,.8746,
- .8660,.8572,.8480,.8387,.8290,.8191,
- .8090,.7986,.7880,.7771,.7660,.7547,
- .7431,.7313,.7193,.7071,.6946,.6820,
- .6691,.6560,.6428,.6293,.6156,.6018,
- .5878,.5735,.5592,.5446,.5299,.5150,
- .5000,.4848,.4694,.4540,.4383,.4226,
- .4067,.3907,.3746,.3583,.3420,.3255,
- .3090,.2923,.2756,.2588,.2419,.2249,
- .2079,.1908,.1736,.1564,.1391,.1218,
- .1045,.0871,.0697,.0523,.0348,.0174,0.0};
-
- /************************************************************************
- Fast Cosine Function
- ************************************************************************/
- double cs(z)
- double z;
- {
- int a;
- z/=TWOPI;
- a=(int) 359*(z-floor(z));
- if (a<=90) return(c[a]);
- else if (a<=180) return(-c[180-a]);
- else if (a<=270) return(-c[a-180]);
- return(c[360-a]);
- }
-
- /************************************************************************
- The Main Program
- ************************************************************************/
- void main()
- {
- int class,code,cycle,cycle_time(),draw,i,inum,k,mnum,run,snum,
- tc,ti,x,y;
- double clr,cs(),t,amp;
- USHORT ct;
- void cleanup();
-
- clr = 0;
- for (i=0; i<16; i++) col2[i] = col1[i];
- cycle = 0; /* Cycle flag */
- draw = 1; /* Draw flag */
- run = 1; /* Run flag */
- t = 0; /* Time */
- tc = 2; /* Cycle time */
- ti = 0; /* Tick counter */
- amp=1; /* Amplitude */
-
- IntuitionBase = (struct IntuitionBase *)
- OpenLibrary("intuition.library",0);
- if (IntuitionBase == NL) cleanup();
-
- GfxBase = (struct GfxBase *)
- OpenLibrary("graphics.library",0);
- if (GfxBase == NL) cleanup();
-
- if ((NewWdw.Screen = CustScr =
- (struct Screen *)OpenScreen(&NewCustScr)) == NL) cleanup();
-
- if (( Wdw =
- (struct Window *)OpenWindow(&NewWdw)) == NL) cleanup();
-
- WVP = (struct ViewPort *)ViewPortAddress(Wdw);
- LoadRGB4(WVP,&col1,16); /* Load our new colors */
-
- SetMenuStrip(Wdw,SHMenu);
-
- while (run)
- {
- if ((draw>0) && (amp>=0))
- {
- t += DT; /* Time incremented */
- clr += DT; /* Colour counter incremented */
- if (clr>=TWOPI) clr -= TWOPI; /* 0<col<TWOPI */
- k = (int) 15-floor(12*clr/TWOPI); /* Current colour */
- SetAPen(RP,k);
- amp -= di; /* Make amplitude smaller */
- x = (int)hc + hs*amp*(cp*cs(sf*t+hsp)+cs(t+hpp));
- y = (int)vc + vs*amp*(cp*cs(sf*t+vsp)+cs(t+vpp));
- WritePixel(RP,x,y); /* Plot a point */
- } /* draw */
-
- if ((cycle>0) && (ti>=tc))
- {
- ct = col1[15];
- for (x=15; x>4; x--) col1[x]=col1[x-1];
- col1[4] = ct;
- LoadRGB4(WVP,&col1,16); /* Cycle the colours */
- ti = 0;
- } /* cycle */
-
- while ((message = (struct IntuiMessage *)
- GetMsg (Wdw->UserPort)))
- {
- class = message->Class;
- code = message->Code;
- mnum = MENUNUM(code);
- inum = ITEMNUM(code);
- snum = SUBNUM(code);
- ReplyMsg(message);
- if ((class == INTUITICKS) && cycle) ti += 1;
- if (class == MENUPICK)
- {
- if ((code) != MENUNULL)
- {
- switch (mnum)
- {
- case 0 : switch (inum)
- {
- case 0 : draw=1;
- cycle=0;
- break;
- case 1 : draw=0;
- cycle=0;
- break;
- case 2 : draw=0;
- cycle=0;
- clr = 0;
- t=0;
- amp = 1;
- break;
- case 3 : draw=0;
- cycle=1;
- break;
- case 4 : draw = 0;
- cycle = 0;
- SetAPen(RP,0);
- RectFill(RP,0,0,XMAX-1,YMAX-1);
- SetAPen(RP,k);
- break;
- case 5 : manual(Wdw);
- break;
- case 6 : future(Wdw);
- break;
- case 7 : run=0;
- }
- break;
- case 1 : switch (inum)
- {
- case 0 : parms(Wdw);
- break;
- } /* ITEMNUM switch */
- break;
- case 2 : switch (inum)
- {
- case 0 : palette(Wdw);
- break;
- case 1 : tc=cycle_time(Wdw,tc);
- } /* ITEMNUM switch */
- } /* MENUNUM switch */
- } /* != MENUNULL if */
- } /* MENUPICK if */
- } /* message while */
- } /* while run */
- cleanup();
- }
-
- /************************************************************************
- Cleanup Resources
- ************************************************************************/
- void cleanup()
- {
- if (Wdw != NL) CloseWindow(Wdw);
- if (CustScr != NL) CloseScreen(CustScr);
- if (GfxBase != NL) CloseLibrary(GfxBase);
- if (IntuitionBase != NL) CloseLibrary(IntuitionBase);
- exit(FALSE);
- }
-