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

  1. /* pixels.c -- create shapes       */
  2. /*             from random pixels  */
  3.  
  4. #include <graph.h> /* for graphics */
  5.  
  6. main()
  7. {
  8.     int pixels, xpos, ypos;
  9.     /* window coordinates */
  10.     int xmin = 100, xmax = 540;
  11.     int ymin = 50,  ymax = 150;
  12.  
  13.     srand(0);               /* init random nums */
  14.     _setvideomode(_HRESBW); /* CGA 640 x 200    */
  15.     _setcolor(1);           /* white foreground */
  16.  
  17.     /* generate random pixel locations      */
  18.     for (pixels = 1; pixels < 10000; pixels++)
  19.         {
  20.         xpos = rand() % 639;
  21.         ypos = rand() % 199;
  22.  
  23.         /* set pixel if within window */
  24.         if ((xpos > xmin && xpos < xmax) &&
  25.              (ypos > ymin && ypos < ymax))
  26.            _setpixel(xpos, ypos);
  27.         }
  28.     getch(); /* freeze screen until key pressed */
  29.              /* restore original video mode */
  30.     _setvideomode(_DEFAULTMODE);
  31. }
  32.