Note: If the X and Y coordinates of the start and end points of a line segment are input, the program will generate a straight line, The current X and Y coordinates are displayed every 10 points generated. |
|
| |
# Include <graphics. h> Void main () { Int driver, mode; Int XA, ya, XB, Yb, C; Int dx, Dy, steps, K; Float FX, fy, X, Y; Int wx, WY; Driver = detect; Mode = 0; Initgraph (& driver, & mode ,""); Printf ("Please enter the start point:/N "); Printf ("XA = "); Scanf ("% d", & xa ); Printf ("Ya = "); Scanf ("% d", & ya ); Printf ("Please enter the end point:/N "); Printf ("XB = "); Scanf ("% d", & XB ); Printf ("Yb = "); Scanf ("% d", & Yb );DX = XB-Xa; DY = Yb-Ya; If (ABS (dx)> ABS (dy )) Steps = ABS (dx ); Else Steps = ABS (dy ); FX = (float) dx/(float) steps; FY = (float) dy/(float) steps; X = XA; Y = ya; Putpixel (X, Y, red ); For (k = 1; k <= steps; k ++) { X + = FX; Y + = FY; Putpixel (X, Y, red ); If (K % 10 = 0) { Printf ("XC = %. 2f YC = %. 2f/N", x, y ); Getch (); } } } |
|