home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / SoundSwirl / drawing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-15  |  1.5 KB  |  68 lines  |  [TEXT/KAHL]

  1. /************************
  2. ** draw.c
  3. **
  4. ** routines for drawing stuff
  5. *************************/
  6.  
  7. #include <math.h>
  8. #include "main.h"
  9.  
  10.  
  11. /****************** local variables ******************/
  12.  
  13.  
  14. #define NUMPOINTS 20
  15. static Point pt_array[NUMPOINTS];
  16. static short currentPt=0;
  17. static short lastPt=0;
  18.  
  19. #define NextPointIndex(x)    (((x)==(NUMPOINTS-1))?0:(x)+1)
  20. #define PrevPointIndex(x)    (((x)==0)?(NUMPOINTS-1):(x)-1)
  21.  
  22. static double angle=0.0;          /* current direction, in radians */
  23.  
  24.  
  25. void DrawStep(void)
  26. {
  27.     Point center, next, oldPt1, oldPt2;
  28.     static int inited=0;
  29.  
  30.     GetMouse( ¢er);
  31.     if (!inited)  /* initialize the position array */
  32.     {
  33.         register int i;
  34.         for (i=0;i<NUMPOINTS; i++)
  35.             pt_array[i] = center;
  36.         lastPt = 1;
  37.         inited=1;
  38.     } /* if */
  39.     
  40.     
  41.     /** erase the last line segment **/
  42.     oldPt1 = pt_array[ lastPt];
  43.     oldPt2 = pt_array[ NextPointIndex(lastPt)];
  44.     PenPat( qd.white);
  45.     MoveTo( oldPt1.h, oldPt1.v);
  46.     LineTo( oldPt2.h, oldPt2.v);
  47.     lastPt = NextPointIndex(lastPt);
  48.     
  49.     if (gListening)
  50.         gOffset = FetchSndOffset();   /* get the current sound level */
  51.     else
  52.         gOffset = 0;
  53.     
  54.     next.h = (short)((gRadius+gOffset) * cos(angle)) + center.h;
  55.     next.v = (short)((gRadius+gOffset) * sin(angle)) + center.v;
  56.     
  57.     PenPat( qd.black);
  58.     MoveTo( pt_array[ currentPt].h, pt_array[ currentPt].v);
  59.     currentPt = NextPointIndex( currentPt);
  60.     pt_array[ currentPt] = next;
  61.     LineTo( pt_array[ currentPt].h, pt_array[ currentPt].v);
  62.  
  63.     angle += gAngleStep;
  64.     if (angle > 2*PI) angle -= 2*PI;
  65.     return;
  66. } /* DrawStep() */
  67.  
  68.