home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap05 / galax.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-05  |  1023 b   |  34 lines

  1. /* GALAX.C -- creates an ellipse by selecting */
  2. /*              from random pixels            */
  3.  
  4. #include <graph.h> /* for graphics */
  5. #include <math.h>  /* for sqrt() */
  6. #include <conio.h> /* for kbhit() */
  7.  
  8. main()
  9. {
  10.     int pixels, radius = 50;
  11.     double center_x = 320, center_y = 100,
  12.         xpos, ypos;
  13.     srand(0);
  14.     _setvideomode(_HRESBW);
  15.     _setcolor(1);
  16.     for (pixels = 1; pixels < 25000; pixels++)
  17.         {
  18.         /* draws filled ellipse, due */
  19.         /* to dimensions of hires screen */
  20.         /* generate random location */
  21.         xpos = rand() % 639;
  22.         ypos = rand() % 199;
  23.         if (sqrt /* is distance within radius? */
  24.               ((xpos - center_x) * (xpos - center_x)
  25.               + (ypos - center_y) * (ypos - center_y))
  26.               < radius)
  27.            _setpixel(xpos, ypos);
  28.         if (kbhit() )
  29.              break; /* exit if key pressed */
  30.         }
  31.     getch(); /* freeze screen until key pressed */
  32.     _setvideomode(_DEFAULTMODE);
  33. }
  34.