home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_07 / v7n7099a.txt < prev    next >
Text File  |  1989-09-05  |  2KB  |  64 lines

  1. /* Sample Macintosh C program:
  2.  
  3.      put up a window, draw a nested set of rectangles, exit when
  4.      the mouse button goes down
  5. */
  6.  
  7. #include "WindowMgr.h"
  8. #include "EventMgr.h"
  9. #include "QuickDraw.h"
  10.  
  11. main()
  12. {
  13.      int  xA,  yA,  xB,  yB,  xC,  yC,  xD,  yD,
  14.          xxA, yyA, xxB, yyB, xxC, yyC, xxD, yyD;
  15.      float p, q;
  16.      int i;
  17.  
  18.      WindowPtr myWindow; 
  19.      EventRecord myEvent;
  20.      static Rect bounds = { 10, 10, 400, 400 };
  21.  
  22.      InitGraf(&thePort);
  23.      InitFonts();
  24.      InitWindows();
  25.      InitCursor();
  26.      myWindow = NewWindow(0, &bounds, "\pSample Window", 
  27.                           1, 0, -1, 1, 0);
  28.  
  29.      p = 0.95;
  30.      q = 1.0 - p;
  31.      xA =  25;     yA =  25;
  32.      xB = 300;     yB = 300;
  33.      xC = 300;     yC = 300;
  34.      xD =  25;     yD = 300;
  35.  
  36.      for (i = 0; i < 50; i++) {
  37.          MoveTo(xA, yA);
  38.          LineTo(xB, yB);     LineTo(xC, yC);
  39.          LineTo(xD, yD);     LineTo(xA, yA);
  40.  
  41.          xxA = p * xA + q * xB;
  42.          yyA = p * yA + q * yB;
  43.          xxB = p * xB + q * xC;
  44.          yyB = p * yB + q * yC;
  45.          xxC = p * xC + q * xD;
  46.          yyC = p * yC + q * yD;
  47.          xxD = p * xD + q * xA;
  48.          yyD = p * yD + q * yA;
  49.  
  50.          xA = xxA; xB = xxB; xC = xxC; xD = xxD;
  51.          yA = yyA; yB = yyB; yC = yyC; yD = yyD;
  52.      }
  53.  
  54.      MoveTo(25, 350);
  55.      DrawString("\pPunch the mouse to exit . . .");
  56.  
  57.      for (;;) {
  58.          GetNextEvent(everyEvent, &myEvent);
  59.          if (myEvent.what == mouseDown)
  60.               return;
  61.      }
  62. }
  63.  
  64.