home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 647.lha / shotSTAR / old.LZH / old / shotSTAR_old.c next >
Encoding:
C/C++ Source or Header  |  1992-06-11  |  4.5 KB  |  162 lines

  1. /*
  2.    shotSTAR v1.0 for AmigaDOS, by Aaron Holmes.
  3.    This program is available in three forms for three operating systems;
  4.    Macintosh, MS-DOS, and, with this latest release: AmigaDOS. This simple
  5.    demo uses the trigonometric ratios sine and cosine to create dazzling
  6.    string-art-like images. No two are exactly alike! (FPU RECOMMENDED!)
  7. */
  8.  
  9. #include <intuition/intuition.h>
  10. #include <math.h>
  11.  
  12. #define _X 320
  13. #define _Y 200
  14. #define MaxR _X
  15. #define MaxT 6.283185307   /* slightly exaggerated */
  16. #define MaxI 32768
  17.  
  18. void SetUP(void);
  19. void TakeDOWN(void);
  20.  
  21. struct TextAttr TopazFont = { "topaz.font", 8, FS_NORMAL, FPB_ROMFONT };
  22.  
  23. UWORD OurPalette[2] = { 0x0000, 0x000F };   /* IN COLOR!!! */
  24.  
  25. UWORD chip BlankPointer[] =
  26. {
  27.    0x0000, 0x0000,   /* no screen burn-in */
  28.    0x0000, 0x0000,
  29.    0x0000, 0x0000
  30. };
  31.  
  32. struct NewScreen OSDef =
  33. {
  34.    0, 0, 640, 400, 1,   /* left top wide high deep */
  35.    0, 0,                /* detail 'n' block pens */
  36.    HIRES | LACE,        /* flags (res junk) */
  37.    CUSTOMSCREEN | SCREENBEHIND | SCREENQUIET,   /* type */
  38.    &TopazFont,          /* font (let's be creative) */
  39.    "shotSTAR v1.0",     /* title... ok, so it's invisible */
  40.    NULL,                /* gadgets */
  41.    NULL                 /* custom bitmap */
  42. };
  43.  
  44. struct NewWindow OWDef =
  45. {
  46.    0, 0, 640, 400,   /* left top wide high */
  47.    0, 0,             /* detail 'n' block pens */
  48.    MOUSEBUTTONS,     /* IDCMP flags */
  49.    SMART_REFRESH | GIMMEZEROZERO | BORDERLESS |
  50.    RMBTRAP | ACTIVATE,   /* misc. flags */
  51.    NULL,             /* gadgets */
  52.    NULL,             /* checkmark */
  53.    NULL,             /* title */
  54.    NULL,             /* screen */
  55.    NULL,             /* superbitmap */
  56.    0, 0, 0, 0,       /* no resizing this bugger */
  57.    CUSTOMSCREEN      /* on a what? */
  58. };
  59.  
  60. struct IntuitionBase *IntuitionBase;
  61. struct GfxBase *GfxBase;
  62. struct Screen *OurScreen;
  63. struct Window *OurWindow;
  64.  
  65. /******************** the MAIN function ********************/
  66.  
  67. main()
  68. {
  69.    struct IntuiMessage *OurMessage;
  70.    struct RastPort *RP;
  71.    
  72.    double Theta, Rad2Add;
  73.    
  74.    int i, x, y, r;
  75.    
  76.    unsigned t;
  77.    
  78.    SetUP();   /* get all SetUP */
  79.    
  80.    RP = OurWindow->RPort;   /* save ourselves some time */
  81.    SetDrMd(RP, JAM1);       /* make sure we're in the right mode */
  82.    
  83.    time(&t);
  84.    srand(t);   /* not THAT pseudo */
  85.    
  86.    FOREVER
  87.    {
  88.       Rad2Add = rand();   /* draw a random number */
  89.       if(!Rad2Add == 0)
  90.          Rad2Add = Rad2Add * MaxT / MaxI;   /* limit it to 6.28 */
  91.       
  92.       for(i = 1; i >= 0; i--)   /* do this twice */
  93.       {
  94.          Theta = 0;   /* set these to starting values */
  95.          x = _X;
  96.          y = _Y;
  97.          r = 0;
  98.          
  99.          SetAPen(RP, i);   /* select a color (lotta choices) */
  100.          Move(RP, x, y);   /* start a line */
  101.          
  102.          do
  103.          {
  104.             if(OurMessage = (struct IntuiMessage *)
  105.             GetMsg(OurWindow->UserPort))   /* got a message? */
  106.             {
  107.                ReplyMsg(OurMessage);
  108.                TakeDOWN();   /* time to quit */
  109.             }
  110.             
  111.             x = _X + r * cos(Theta);   /* our next move */
  112.             y = _Y + r * sin(Theta);
  113.             
  114.             Draw(RP, x, y);   /* finish a line */
  115.             
  116.             Theta += Rad2Add;                  /* offset Theta */
  117.             if(Theta >= MaxT) Theta -= MaxT;   /* back 360 */
  118.             
  119.             r++;   /* expand */
  120.          }
  121.          while(r <= MaxR);
  122.       }
  123.    }
  124. }
  125.  
  126. /******************** the SetUP function ********************/
  127.  
  128. void SetUP()
  129. {
  130.    /* try opening the libraries and our screen */ 
  131.    IntuitionBase = (struct IntuitionBase *)
  132.    OpenLibrary("intuition.library", 0);
  133.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  134.    OurScreen = (struct Screen *)OpenScreen(&OSDef);
  135.    /* I hope it worked */
  136.    if((!IntuitionBase) || (!GfxBase) || (!OurScreen)) TakeDOWN();
  137.    
  138.    OWDef.Screen = OurScreen;   /* the window is ours */
  139.    
  140.    /* and now, our window */
  141.    OurWindow = (struct Window *)OpenWindow(&OWDef);
  142.    /* I hope it worked */
  143.    if(!OurWindow) TakeDOWN();
  144.    
  145.    LoadRGB4(&OurScreen->ViewPort, OurPalette, 2);      /* set palette */
  146.    SetPointer(OurWindow, &BlankPointer, 1, 1, 0, 0);   /* no arrow */
  147.    ScreenToFront(OurScreen);                           /* we're here */
  148. }
  149.  
  150. /******************** the TakeDOWN function ********************/
  151.  
  152. void TakeDOWN()
  153. {
  154.    if(OurWindow) CloseWindow(OurWindow);   /* close what we opened */
  155.    if(OurScreen) CloseScreen(OurScreen);
  156.    if(GfxBase) CloseLibrary(GfxBase);
  157.    if(IntuitionBase) CloseLibrary(IntuitionBase);
  158.    
  159.    /* we're outta here... adios AMIGA */
  160.    exit(TRUE);
  161. }
  162.