Advertisement
Dr_Davenstein

Unrolled line algorithm

Oct 23rd, 2021
3,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare sub nLine( byref x1 as integer, byref y1 as integer, byref x2 as integer, byref y2 as integer, byref c as uinteger, byref lthick as integer = 0  )
  2.  
  3. screenres 640,480,32
  4.  
  5.  
  6.  
  7.  
  8.  
  9. do
  10.    
  11.     screenlock
  12.     nLine int(rnd*640),int(rnd*480),int(rnd*640),int(rnd*480), rgb(rnd*256,rnd*256,rnd*256), 1
  13.     screenunlock
  14.    
  15.     sleep 3,1
  16.    
  17. loop until inkey$=chr$(27)
  18.  
  19. sleep
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. sub nLine( byref x1 as integer, byref y1 as integer, byref x2 as integer, byref y2 as integer, byref c as uinteger, byref lthick as integer = 0  )
  29.  
  30.     dim as integer Xdif = x2 - x1
  31.     dim as integer Ydif = y2 - y1
  32.     dim as integer xit, yit, tempx, tempy
  33.    
  34.     if Xdif < 0 then
  35.         Xdif = -Xdif
  36.     end if
  37.    
  38.     if Ydif < 0 then
  39.         Ydif = -Ydif
  40.     end if
  41.    
  42.     if Xdif >= Ydif then
  43.         if x2 < x1 then
  44.             swap x2, x1
  45.             swap y2, y1
  46.         end if
  47.        
  48.         if y2 < y1 then
  49.             Xit = -1
  50.         else
  51.             Xit = 1
  52.         end if
  53.        
  54.         TempY = y1
  55.        
  56.         for TempX = x1 to x2
  57.             'pset(TempX, TempY), c
  58.             'line(tempx-lthick,tempy-lthick)-(tempx+lthick,tempy+lthick),c,bf
  59.             circle(tempx, tempY), lThick, c,,,,f
  60.             Yit = Yit - Ydif
  61.            
  62.             if Yit < 0 then
  63.                 Yit = Yit + Xdif
  64.                 TempY = TempY + Xit
  65.             end if
  66.         next
  67.        
  68.     else
  69.        
  70.         if y2 < y1 then
  71.             swap x2, x1
  72.             swap y2, y1
  73.         end if
  74.        
  75.         if x2 < x1 then
  76.             Xit = -1
  77.         else
  78.             Xit = 1
  79.         end if
  80.        
  81.         TempX = x1
  82.        
  83.         for TempY = y1 to y2
  84.             'pset(TempX, TempY), c
  85.             'line(tempx-lthick,tempy-lthick)-(tempx+lthick,tempy+lthick),c,bf
  86.             circle(tempx, tempY), lThick, c,,,,f
  87.             Yit = Yit - Xdif
  88.            
  89.             if Yit < 0 then
  90.                 Yit = Yit + Ydif
  91.                 TempX = TempX + Xit
  92.             end if
  93.         next
  94.        
  95.     end if
  96.  
  97. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement