home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter35 / l35-2.c < prev    next >
C/C++ Source or Header  |  1997-06-18  |  3KB  |  91 lines

  1. /*
  2.  * Sample program to illustrate EGA/VGA line drawing routines.
  3.  *
  4.  * Compiled with Borland C++ 4.02
  5.  * Checked by Jim Mischel 11/21/94 
  6.  *
  7.  * Must be linked with L14-1.C or L14-3.ASM.  Build with either
  8.  * of these command lines:
  9.  *   bcc l14-2.c l14-1.c, or
  10.  *   bcc l14-2.c l14-3.asm
  11.  *
  12.  * By Michael Abrash.
  13.  */
  14.  
  15. #include <dos.h>     /* contains geninterrupt */
  16.  
  17. #define GRAPHICS_MODE   0x10
  18. #define TEXT_MODE       0x03
  19. #define BIOS_VIDEO_INT  0x10
  20. #define X_MAX           640      /* working screen width */
  21. #define Y_MAX           348      /* working screen height */
  22.  
  23. extern void EVGALine();
  24.  
  25. /*
  26.  * Subroutine to draw a rectangle full of vectors, of the specified
  27.  * length and color, around the specified rectangle center.
  28.  */
  29. void VectorsUp(XCenter, YCenter, XLength, YLength, Color)
  30. int XCenter, YCenter;   /* center of rectangle to fill */
  31. int XLength, YLength;   /* distance from center to edge
  32.                            of rectangle */
  33. int Color;              /* color to draw lines in */
  34. {
  35.    int WorkingX, WorkingY;
  36.  
  37.    /* Lines from center to top of rectangle */
  38.    WorkingX = XCenter - XLength;
  39.    WorkingY = YCenter - YLength;
  40.    for ( ; WorkingX < ( XCenter + XLength ); WorkingX++ )
  41.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color);
  42.  
  43.    /* Lines from center to right of rectangle */
  44.    WorkingX = XCenter + XLength - 1;
  45.    WorkingY = YCenter - YLength;
  46.    for ( ; WorkingY < ( YCenter + YLength ); WorkingY++ )
  47.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color);
  48.  
  49.    /* Lines from center to bottom of rectangle */
  50.    WorkingX = XCenter + XLength - 1;
  51.    WorkingY = YCenter + YLength - 1;
  52.    for ( ; WorkingX >= ( XCenter - XLength ); WorkingX-- )
  53.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color);
  54.  
  55.    /* Lines from center to left of rectangle */
  56.    WorkingX = XCenter - XLength;
  57.    WorkingY = YCenter + YLength - 1;
  58.    for ( ; WorkingY >= ( YCenter - YLength ); WorkingY-- )
  59.       EVGALine(XCenter, YCenter, WorkingX, WorkingY, Color );
  60. }
  61.  
  62. /*
  63.  * Sample program to draw four rectangles full of lines.
  64.  */
  65. void main()
  66. {
  67.    char temp;
  68.  
  69.    /* Set graphics mode */
  70.    _AX = GRAPHICS_MODE;
  71.    geninterrupt(BIOS_VIDEO_INT);
  72.  
  73.    /* Draw each of four rectangles full of vectors */
  74.    VectorsUp(X_MAX / 4, Y_MAX / 4, X_MAX / 4,
  75.       Y_MAX / 4, 1);
  76.    VectorsUp(X_MAX * 3 / 4, Y_MAX / 4, X_MAX / 4,
  77.       Y_MAX / 4, 2);
  78.    VectorsUp(X_MAX / 4, Y_MAX * 3 / 4, X_MAX / 4,
  79.       Y_MAX / 4, 3);
  80.    VectorsUp(X_MAX * 3 / 4, Y_MAX * 3 / 4, X_MAX / 4,
  81.       Y_MAX / 4, 4);
  82.  
  83.    /* Wait for the enter key to be pressed */
  84.    scanf("%c", &temp);
  85.  
  86.    /* Back to text mode */
  87.    _AX = TEXT_MODE;
  88.    geninterrupt(BIOS_VIDEO_INT);
  89. }
  90.  
  91.