home *** CD-ROM | disk | FTP | other *** search
-
-
- #include <intuition/intuition.h>
- #include "star.h"
-
- #define HEIGHT 400
- #define WIDTH 640
- #define DEPTH 4
-
- struct Window *win;
- struct Screen *scr;
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct ViewPort *vp;
- struct RastPort *rp;
- struct IntuiMessage *message;
-
- USHORT class;
- USHORT code;
-
- struct NewScreen ns =
- { 0,0,WIDTH,HEIGHT,DEPTH,0,1,HIRES+LACE, /* View modes */
- CUSTOMSCREEN, /* Screen type */
- NULL, /* Font */
- NULL,NULL,NULL /* CustomBitmap */ };
-
- struct NewWindow nw =
- { 0,0,WIDTH,HEIGHT,0,1,MOUSEBUTTONS, /* IDCMP flags */
- ACTIVATE|BORDERLESS|RMBTRAP, /* Flags */
- NULL,NULL,NULL, /* Gadget,Checkmark,Name */
- NULL,NULL, /* Screen,BitMap */
- WIDTH,HEIGHT,100,100, /* Max Width,Height, Min Width,Height */
- CUSTOMSCREEN };
-
- int *values1,*values2,*values3; /* Declare 3 pointers to my 3 sets of points */
-
- void _main()
- {
- int x,times=0;
-
- Open_Stuff();
-
- Init_Colour();
-
-
-
- values1=Init_Values(30,30);
- values2=Init_Values(60,61); /* Initialize 3 sets of points */
- values3=Init_Values(100,301);
-
- if(values1==0 || values2==0 || values3==0)
- die(" I can't allocate memory for my points!");
-
- Clear_Rastport();
-
- while(idcmpch()!=1) /* Draw Stars until the user presses the LMB */
- {
- for(x=0;x<2;x++)
- {
- times++;
-
- SetAPen(rp,rand()%15+1);
- Draw_Star(rp,values1,rand()%500+40,rand()%300+40,rand()%20+5);
-
- SetAPen(rp,rand()%15+1);
- Draw_Star(rp,values2,rand()%500+70,rand()%260+70,rand()%40+10);
-
- SetAPen(rp,rand()%15+1);
- Draw_Star(rp,values3,rand()%420+110,rand()%180+110,rand()%200+33);
-
- if(times==30) { times=0; Clear_Rastport(); }
- }
-
- }
-
-
- die("");
- }
-
- int Clear_Rastport()
- {
- struct Image dummy =
- { 0,0,WIDTH,HEIGHT,0,NULL,0,0,NULL };
- DrawImage(rp,&dummy,0,0);
- return(1);
- }
-
- int Init_Colour()
- {
- int sec,micros;
-
- SetRGB4(vp,1,15,0,0);
- SetRGB4(vp,2,15,0,0);
- SetRGB4(vp,3,15,15,0);
- SetRGB4(vp,4,0,15,15);
- SetRGB4(vp,5,15,0,15);
- SetRGB4(vp,6,15,15,15);
- SetRGB4(vp,7,0,0,15);
- SetRGB4(vp,8,15,15,0);
- SetRGB4(vp,9,6,15,6);
- SetRGB4(vp,10,15,3,3);
- SetRGB4(vp,11,15,3,9);
-
- SetAPen(rp,11);
- Move(rp,220,200);
- Text(rp," STAR V1.0",17);
- Move(rp,216,215);
- Text(rp," By Jason Lowe",19);
- Move(rp,215,230);
- SetAPen(rp,6);
- Text(rp," Calculating points",22);
- Move(rp,210,245);
- Text(rp," Left Mouse Button EXITS",25);
- Move(rp,210,260);
- SetAPen(rp,8);
- Text(rp," Source for this program",25);
- Move(rp,205,275);
- Text(rp,"is avalable from the author.",28);
- Move(rp,207,290);
- Text(rp," This program is 100% C.",26);
-
- CurrentTime(&sec,µs); /* Reseed the random number generator */
- srand(999*sec+micros);
-
- return(1);
- }
-
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
- /*************************** ************************/
- /*************************** Functions.... ************************/
- /*************************** ************************/
- /*************************************************************************/
- /*************************************************************************/
- /*************************************************************************/
-
- int idcmpch()
- {
- if(win->UserPort->mp_SigBit)
- if(message=(struct IntuiMessage *)GetMsg(win->UserPort))
- {
- class=message->Class;
- code=message->Code;
- ReplyMsg((struct IntuiMessage *)message);
- switch(class)
- {
- case MOUSEBUTTONS:
- switch(code)
- {
- case SELECTDOWN:
- return(1);
- }
- }
- }
- return(0); /* Nothing interesting! */
- }
-
-
-
- Open_Stuff()
- {
-
- void *OpenLibrary();
- struct Window *OpenWindow();
- struct Screen *OpenScreen();
-
- if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
- die("Can't open intuition.library");
-
- if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
- die("Can't open graphics library");
-
-
- if((scr=OpenScreen(&ns))==NULL)
- ;
-
- nw.Screen=scr;
-
- if(!(win=(struct Window *)OpenWindow(&nw)))
- die("Can't open window");
-
- rp=win->RPort;
- vp=&scr->ViewPort;
-
- SetRGB4(vp,0,0,0,0);
-
- return(TRUE);
-
- }
-
-
- int die(s)
- char *s[];
- {
- char Alert[300];
- register int loop;
-
- if(strlen(s)!=0) /* Display alert if s isn't NULL */
- {
- memset((void *)Alert,0,sizeof(Alert));
- strcat(Alert,s);
- strcat(Alert," Press either mouse button to continue.");
- loop=strlen(s);
- Alert[0]=0; Alert[1]=32; Alert[2]=16;
- Alert[loop+2]='\0'; Alert[loop+3]=TRUE;
- Alert[loop+4]=0; Alert[loop+5]=32; Alert[loop+6]=32;
- Alert[loop+45]='\0'; Alert[loop+46]=FALSE;
- DisplayAlert(RECOVERY_ALERT,Alert,48);
- }
-
- if(values1) Free_Values(values1);
- if(values2) Free_Values(values2);
- if(values3) Free_Values(values3);
-
- if(win) CloseWindow(win);
- if(scr) CloseScreen(scr);
- if(GfxBase) CloseLibrary(GfxBase);
- if(IntuitionBase) CloseLibrary(IntuitionBase);
- exit();
- return(1);
- }
-
-
-