Advertisement
Dr_Davenstein

Untitled

May 25th, 2020
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'unrolled floodfill
  2.  
  3. randomize timer
  4.  
  5. const false=0, True = not False, ScreenWidth = 640, ScreenHeight = 480
  6.  
  7. declare sub Paint2(byval pX as integer, byval pY as integer, byval Col as uinteger, byval scol as uinteger )
  8.  
  9. screenres screenwidth, screenheight, 32
  10.  
  11.  
  12. screenlock
  13. for i as integer = 1 to 1000
  14.    
  15.     dim as integer rx = int(rnd*ScreenWidth)
  16.    
  17.     dim as integer ry = int(rnd*ScreenHeight)
  18.    
  19.     dim as integer rad = rnd*100
  20.    
  21.     dim as uinteger rcol = rgb(rnd*255, rnd*255, rnd*255)
  22.    
  23.     dim as uinteger rbor = rgb(rnd*255, rnd*255, rnd*255)
  24.    
  25.     circle(rx,ry),rad,rbor
  26.     paint2( rx, ry, rcol, rbor )
  27.    
  28. next
  29. screenunlock
  30.  
  31. sleep
  32.  
  33.  
  34.  
  35. sub Paint2( byval pX as integer, byval pY as integer, byval Col as uinteger, byval scol as uinteger)
  36.  
  37.     static as integer sw, sh
  38.     static as uinteger tcol
  39.     static as uinteger ptr scr
  40.    
  41.     screeninfo sw,sh
  42.  
  43.     if py<0 or px<0 or px>sw-1 or py>sh-1 then exit sub
  44.    
  45.     dim as integer i = 0, bwid = (sw * sh) * 2, x ,y
  46.    
  47.     dim as ushort FloodId(bwid)
  48.    
  49.     FloodId(i) = pX
  50.     FloodId(i+1) = pY
  51.     i += 2
  52.  
  53.     scr = screenptr
  54.  
  55.     do while i
  56.        
  57.         i -= 2
  58.         x = FloodId(i)
  59.         y = FloodId(i+1)
  60.         scr[y*sw+x] = col
  61.  
  62.         if y>0 then
  63.  
  64.             tcol = scr[ ((y-1)*sw) + x]
  65.  
  66.             if  tcol <> scol and tcol <> col then
  67.  
  68.                 FloodId(i) = X
  69.                 FloodId(i+1) = Y - 1
  70.                 i += 2
  71.  
  72.             end if
  73.  
  74.         end if
  75.  
  76.         if x>0 then
  77.  
  78.             tcol = scr[(y*sw)+x-1]
  79.  
  80.             if  tcol <> scol and tcol <> col then
  81.  
  82.                 FloodId(i) = X - 1
  83.                 FloodId(i+1) = Y
  84.                 i += 2
  85.  
  86.             end if
  87.  
  88.         end if
  89.  
  90.         if y<sh-1 then
  91.  
  92.             tcol = scr[(y+1)*sw+x]
  93.  
  94.             if  tcol <> scol and tcol <> col then
  95.  
  96.                 FloodId(i) = X
  97.                 FloodId(i+1) = Y + 1
  98.                 i += 2
  99.  
  100.             end if
  101.  
  102.         end if
  103.  
  104.         if x<sw-1 then
  105.  
  106.             tcol = scr[(y*sw)+(x+1)]
  107.  
  108.             if  tcol <> scol and tcol <> col then
  109.  
  110.                 FloodId(i) = X + 1
  111.                 FloodId(i+1) = Y
  112.                 i += 2
  113.  
  114.             end if
  115.  
  116.         end if
  117.  
  118.     loop
  119.  
  120. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement