Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define fbc -gen gcc -O 3
  2.  
  3. #include "crt.bi"
  4. #include "windows.bi"
  5.  
  6. const NOISESIZE = 63
  7.  
  8. #define IntToFix(_IN) ((_IN) shl cfBits)
  9. #define FixToInt(_IFN) ((_IFN) shr cfBits)
  10. const cfBits = 8
  11. const cfIntMask = cint(&hFFFFFFFF shl cfBits)
  12. const cfOne = 1 shl cfBits
  13. const cfNoiseSize = IntToFix(NOISESIZE)
  14.  
  15. static shared as integer ifNoise(65535)
  16. static shared as single fNoise(65535)
  17. randomize()
  18. for N as integer = 0 to 65535
  19.   fNoise(N) = rnd
  20.   ifNoise(N) = fNoise(N)*cfOne  
  21. next N
  22.  
  23. #if 1
  24.   function noise( x as integer , y as integer , z as integer ) as single
  25.   '    srand(x + 1000 * y + 1e6 * z)
  26.   '    return (rand() / RAND_MAX)
  27.      
  28.       randomize x + 1000 * y + 1e6 * z
  29.       return rnd
  30.   end function
  31. #endif
  32.  
  33. function smoothNoise1d(x as single) as single
  34.     x=abs(x)
  35.     dim as integer iX1=int(x)
  36.     dim as integer iX2=ix1+1
  37.     dim as single tx=x-iX1
  38.     iX1 and= NOISESIZE
  39.     iX2 and= NOISESIZE
  40.     dim as single l=noise(iX1,0,0)
  41.     dim as single r=noise(iX2,0,0)
  42.     dim as single v=l + (r-l)*tx
  43.     return v
  44. end function
  45.  
  46. function smoothNoise2dF(x as single, y as single) as single
  47.     x=abs(x) : y=abs(y)
  48.     dim as integer iX1=int(x)
  49.     dim as integer iY1=int(y)
  50.     dim as integer iX2=ix1+1
  51.     dim as integer iY2=iy1+1
  52.     dim as single tx=x-iX1
  53.     dim as single ty=y-iY1
  54.    
  55.     iX1 and= NOISESIZE
  56.     iX2 and= NOISESIZE
  57.     iY1 and= NOISESIZE
  58.     iY2 and= NOISESIZE
  59.    
  60.     #if 1
  61.       iY1 shl= 10: iY2 shl= 10
  62.       dim as single lt=fNoise((iY1+iX1) and 65535)
  63.       dim as single rt=fNoise((iY1+iX2) and 65535)
  64.       dim as single rb=fNoise((iY2+iX2) and 65535)
  65.       dim as single lb=fNoise((iY2+iX1) and 65535)
  66.     #else
  67.       dim as single lt=Noise(iX1,iY1,0)
  68.       dim as single rt=Noise(iX2,iY1,0)
  69.       dim as single rb=Noise(iX2,iY2,0)
  70.       dim as single lb=Noise(iX1,iY2,0)
  71.     #endif
  72.    
  73.     dim as single sxt=lt + (rt-lt)*tx
  74.     dim as single sxb=lb + (rb-lb)*tx
  75.    
  76.     dim as single v=sxt+(sxb-sxt)*ty
  77.     return v
  78. end function
  79. function smoothNoise2dI(ifX as integer, iFy as integer) as integer
  80.     ifX=abs(ifX) : ifY=abs(ifY)
  81.     dim as integer ifX1=ifX and cfIntMask
  82.     dim as integer ifY1=ifY and cfIntMask
  83.     dim as integer ifX2=ifX1+cfOne
  84.     dim as integer ifY2=ifY1+cfOne
  85.     dim as integer ifTX=ifX-ifX1
  86.     dim as integer ifTY=ifY-ifY1
  87.    
  88.     ifX1 = FixToInt(ifX1) and NoiseSize
  89.     ifX2 = FixToInt(ifX2) and NoiseSize
  90.     ifY1 and= cfNoiseSize
  91.     ifY2 and= cfNoiseSize
  92.    
  93.    
  94.     ifY1 shl= (10-cfBits)
  95.     ifY2 shl= (10-cfBits)
  96.     dim as integer lt=ifNoise((ifY1+ifX1) and 65535)
  97.     dim as integer rt=ifNoise((ifY1+ifX2) and 65535)
  98.     dim as integer rb=ifNoise((ifY2+ifX2) and 65535)
  99.     dim as integer lb=ifNoise((ifY2+ifX1) and 65535)
  100.    
  101.     dim as integer ifXT=lt + (((rt-lt)*ifTX) shr cfBits)
  102.     dim as integer ifXB=lb + (((rb-lb)*ifTX) shr cfBits)
  103.     dim as integer v=ifXT+(((ifXB-ifXT)*ifTY) shr cfBits)
  104.     return v
  105. end function
  106.  
  107. function smoothNoise3d(x as single, y as single, z as single) as single
  108.     x=abs(x)
  109.     y=abs(y)
  110.     z=abs(z)
  111.     dim as integer iX1=int(x)
  112.     dim as integer iY1=int(y)
  113.     dim as integer iZ1=int(z)
  114.     dim as integer iX2=ix1+1
  115.     dim as integer iY2=iy1+1
  116.     dim as integer iZ2=iz1+1
  117.     dim as single tx=x-iX1
  118.     dim as single ty=y-iY1
  119.     dim as single tz=z-iZ1
  120.    
  121.     iX1 and= NOISESIZE
  122.     iX2 and= NOISESIZE
  123.     iY1 and= NOISESIZE
  124.     iY2 and= NOISESIZE
  125.     iZ1 and= NOISESIZE
  126.     iZ2 and= NOISESIZE
  127.    
  128.     dim as single ltf=noise(iX1,iY1,iZ1)
  129.     dim as single rtf=noise(iX2,iY1,iZ1)
  130.     dim as single rbf=noise(iX2,iY2,iZ1)
  131.     dim as single lbf=noise(iX1,iY2,iZ1)
  132.     dim as single sxtf=ltf + (rtf-ltf)*tx
  133.     dim as single sxbf=lbf + (rbf-lbf)*tx
  134.    
  135.     dim as single ltb=noise(iX1,iY1,iZ2)
  136.     dim as single rtb=noise(iX2,iY1,iZ2)
  137.     dim as single rbb=noise(iX2,iY2,iZ2)
  138.     dim as single lbb=noise(iX1,iY2,iZ2)
  139.     dim as single sxtb = ltb + (rtb-ltb)*tx
  140.     dim as single sxbb = lbb + (rbb-lbb)*tx
  141.    
  142.     dim as single vf = sxtf+(sxbf-sxtf)*ty
  143.     dim as single vb = sxtb+(sxbb-sxtb)*ty
  144.     dim as single v = vf + (vb-vf)*tz
  145.    
  146.     return v
  147. end function
  148.  
  149. function turbulence1d(x as single, size as single) as single
  150.     dim as single value, initialSize=any
  151.     if size<1 then size=1
  152.     initialSize = size
  153.     while(size >= 1)
  154.         value += smoothNoise1d(x / size) * size
  155.         size /= 2.0
  156.     wend
  157.     value*=0.5
  158.     return value/initialSize
  159. end function
  160.  
  161. function turbulence2dI(x as integer, y as integer, size as integer) as integer
  162.     dim as integer value, initialSize=any
  163.     if size<2 then size=2
  164.     initialSize = (size-1)
  165.     x = IntToFix(x): y = IntToFix(y)
  166.     while(size >= 1)
  167.         value += smoothNoise2dI(x \ size, y \ size) * size
  168.         size shr= 1
  169.     wend      
  170.     return (value shr 1)\initialSize
  171. end function
  172. function turbulence2dF(x as single, y as single, size as integer) as single
  173.     dim as single value, initialSize=any
  174.     if size<1 then size=1
  175.     initialSize = size
  176.     while(size >= 1)
  177.         value += smoothNoise2dF(x / size, y / size) * size
  178.         size shr= 1
  179.     wend
  180.     value*=0.5
  181.     return value/(initialSize-1)
  182. end function
  183.  
  184. function turbulence3d(x as single, y as single, z as single, size as single) as single
  185.     dim as integer value, initialSize=any
  186.     if size<1 then size=1
  187.     initialSize = size
  188.     while(size >= 1)
  189.         value += smoothNoise3d(x / size, y / size, z / size) * size        
  190.         size /= 2.0
  191.     wend
  192.     value*=0.5
  193.     return value/(initialSize-1)
  194. end function
  195.  
  196.  
  197. dim as integer sx,sy
  198. sx = 480
  199. sy = 300
  200.  
  201.  
  202. screenres(sx,sy,32,1,0)
  203.  
  204. SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS)
  205.  
  206. dim as double TMR = timer
  207. screenlock
  208. var pPix = cast(ulong ptr,screenptr)
  209. for y as integer = 0 to sy-1
  210.     for x as integer = 0 to sx-1
  211.         dim as ubyte clr = 255*turbulence2df(x,y,32)
  212.         *pPix = rgb(clr,clr,clr): pPix += 1
  213.         'pset(x,y),rgb(clr,clr,clr)
  214.     next x
  215. next y
  216. screenunlock
  217.  
  218. sleep()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement