home *** CD-ROM | disk | FTP | other *** search
- /*
- SG C Tools 1.2
-
- (C) 1993 Steve Goldsmith
- All Rights Reserved
-
- Compiled with HI-TECH C 3.09 (CP/M-80).
- */
-
- #include <hitech.h>
- #include <vdc.h>
-
- /* draw line using modified bresenham's algorithm */
-
- void linevdc(int X1, int Y1, int X2, int Y2)
- {
- int XInc = 1;
- int YInc = 1;
- int DX, DY, X, Y, C, R;
-
- DX = X2-X1; /* delta x */
- if(DX < 0) /* adjust for negative delta */
- {
- XInc = -1;
- DX = -DX;
- }
- DY = Y2-Y1; /* delta y */
- if(DY < 0) /* adjust for negative delta */
- {
- YInc = -1;
- DY = -DY;
- }
- else
- if(DY > 0)
- YInc = 1;
- else
- YInc = 0;
-
- X = X1;
- Y = Y1;
- setpixvdc(X,Y); /* set first point */
- if (DX > DY) /* always draw with positive increment */
- {
- R = DX >> 1;
- for(C = 1; C <= DX; C++)
- {
- X += XInc;
- R += DY;
- if(R >= DX)
- {
- Y += YInc;
- R -= DX;
- }
- setpixvdc(X,Y);
- }
- }
- else
- {
- R = DY >> 1;
- for(C = 1; C <= DY; C++)
- {
- Y += YInc;
- R += DX;
- if(R >= DY)
- {
- X += XInc;
- R -= DY;
- }
- setpixvdc(X,Y);
- }
- }
- }
-