home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / aminet / proclib20.lha / Graphics / _FAST_LINE.Amos / _FAST_LINE.amosSourceCode
AMOS Source Code  |  1993-09-30  |  2KB  |  78 lines

  1. Procedure _FAST_LINE[X1,Y1,X2,Y2]
  2.  '
  3.  '
  4.  ' Version: 1.0   
  5.  '      By: ** Michael Sikorsky **  
  6.  '  e-mail: sikorsky@bode.ee.ualberta.ca  
  7.  '    
  8.  ' Distribution:  This program is freely distributable.  All I ask is if
  9.  '                you make changes,improvements, or bug fixes (etc) that  
  10.  '                you mail me a new copy of the source.  Also somekind
  11.  '                of acknowledgment in your greetings/credits/manual/etc
  12.  '                would be appreciated, thanks. 
  13.  '  
  14.  ' Requirements:  none. 
  15.  '                              
  16.  '  Description:  Draws a line using only fixed point math (Bressenham)   
  17.  '                (note: can change the Plot command to something like
  18.  '                       Paste Icon...)                 
  19.  '
  20.  '   Parameters:  (X1,Y1) = co-ords of one end point. 
  21.  '                (X2,Y2) = co-ords of the other end point. 
  22.  '      
  23.  '      Returns:   nothing. 
  24.  '
  25.  '      Example:   _FAST_LINE[10,10,50,50] : Rem Draws a Line from (10,10) to (50,50) 
  26.  '
  27.  
  28.     DX=X2-X1
  29.     DY=Y2-Y1
  30.  
  31.     If(DX<0)
  32.        X_INC=-1
  33.     Else 
  34.        X_INC=1
  35.     End If 
  36.  
  37.     L=Abs(DX)
  38.  
  39.     If(DY<0)
  40.        Y_INC=-1
  41.     Else 
  42.        Y_INC=1
  43.     End If 
  44.  
  45.     M=Abs(DY)
  46.     DX2=2*L
  47.     DY2=2*M
  48.     If(L>=M)
  49.         ERR=DY2-L
  50.          I=0
  51.          While I<L
  52.             Plot X1,Y1
  53.             If(ERR>0)
  54.                 Add Y1,Y_INC
  55.                 Add ERR,-DX2
  56.             End If 
  57.             Add ERR,DY2
  58.             Add X1,X_INC
  59.             Inc I
  60.         Wend 
  61.     Else 
  62.         ERR=DX2-M
  63.          I=0
  64.          While I<M
  65.             Plot X1,Y1
  66.             If(ERR>0)
  67.                 Add X1,X_INC
  68.                 Add ERR,-DY2
  69.             End If 
  70.             Add ERR,DX2
  71.             Add Y1,Y_INC
  72.             Inc I
  73.          Wend 
  74.     End If 
  75.     Plot X1,Y1
  76.  
  77. '
  78. End Proc