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

  1. /* lines.c -- calls line() with */
  2. /*            five parameters   */
  3.  
  4. #include <graph.h>
  5.  
  6. main()
  7. {
  8.     void line (x1, y1, x2, y2, color);
  9.  
  10.     int x1, x2, y1, y2, i, color;
  11.  
  12.     _setvideomode(_MRES16COLOR); /* 320 x 200  16 col. */
  13.     srand(2);                    /* new random seed    */
  14.     for (i = 0; i < 100; i++)
  15.         {
  16.         x1 = rand() % 319;       /* random coordinates */
  17.         x2 = rand() % 319;
  18.         y1 = rand() % 199;
  19.         y2 = rand() % 199;
  20.         color = (rand() % 14) + 1; /* random color 1-15 */
  21.         line(x1, y1, x2, y2, color); /* draw a line   */
  22.         }
  23.     while(!kbhit() ); /* wait for key to be hit */
  24.  
  25.     _setvideomode(_DEFAULTMODE); /* restore video mode */
  26. }
  27.  
  28. void line (x1, y1, x2, y2, color)
  29. int x1, y1, x2, y2, color;
  30. {
  31.     _moveto(x1, y1); /* position at first endpoint   */
  32.     _setcolor(color);
  33.     _lineto(x2, y2); /* draw line to second endpoint */
  34. }
  35.