' Line function ' ' Draws any line of any slope or angle. ' SUB DrawLine(X1%, Y1%, X2%, Y2%, C%) DIM currX!, currY! ' Current pixel to be plotted DIM deltaX!, deltaY!, slope! ' 2 deltas and slope deltaX! = X2% - X1% ' Get value for delta X deltaY! = Y2% - Y1% ' Get value for delta Y deltaX! = ABS(deltaX!) ' Need absolute values deltaY! = ABS(deltaY!) IF deltaY! > deltaX! THEN ' |slope| > 1 IF Y2% < Y1% THEN SWAP Y2%, Y1% ' Swap coordinates SWAP X2%, X1% ' Y1 must be < Y2 END IF ' Compute deltas and slope deltaX! = X2% - X1% deltaY! = Y2% - Y1% ' Slope off the vertical axis slope! = deltaX! / deltaY! ' Plot each pixel starting at (X1, X2) currX! = X1% FOR currY! = Y1% TO Y2% ' May use 'SetPixel currX!, currY!, C%' instead PSET(currX!, currY!), C% ' Increment X by slope currX! = currX! + slope! NEXT currY! EXIT SUB ELSEIF deltaX! <> 0! OR deltaY! <> 0! THEN ' |slope| < 1 IF X2% < X1% THEN SWAP X2%, X1% ' Swap coordinates SWAP Y2%, Y1% ' X1 must be < X2 END IF ' Compute deltas and slope deltaX! = X2% - X1% deltaY! = Y2% - Y1% ' Slope off the horizontal axis slope! = deltaY! / deltaX! ' Plot each pixel starting at (X1, X2) currY! = Y1% FOR currX! = X1% TO X2% ' May use 'SetPixel currX!, currY!, C%' instead PSET(currX!, currY!), C% ' Increment X by slope currY! = currY! + slope! NEXT currX! EXIT SUB ELSE ' Set a single pixel because X1 = X2 and Y1 = Y2 PSET(X1%, Y1%), C% END IF END SUB