Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define fbc -gen gcc -O 3
- #include "crt.bi"
- #include "windows.bi"
- const NOISESIZE = 63
- #define IntToFix(_IN) ((_IN) shl cfBits)
- #define FixToInt(_IFN) ((_IFN) shr cfBits)
- const cfBits = 8
- const cfIntMask = cint(&hFFFFFFFF shl cfBits)
- const cfOne = 1 shl cfBits
- const cfNoiseSize = IntToFix(NOISESIZE)
- static shared as integer ifNoise(65535)
- static shared as single fNoise(65535)
- randomize()
- for N as integer = 0 to 65535
- fNoise(N) = rnd
- ifNoise(N) = fNoise(N)*cfOne
- next N
- #if 1
- function noise( x as integer , y as integer , z as integer ) as single
- ' srand(x + 1000 * y + 1e6 * z)
- ' return (rand() / RAND_MAX)
- randomize x + 1000 * y + 1e6 * z
- return rnd
- end function
- #endif
- function smoothNoise1d(x as single) as single
- x=abs(x)
- dim as integer iX1=int(x)
- dim as integer iX2=ix1+1
- dim as single tx=x-iX1
- iX1 and= NOISESIZE
- iX2 and= NOISESIZE
- dim as single l=noise(iX1,0,0)
- dim as single r=noise(iX2,0,0)
- dim as single v=l + (r-l)*tx
- return v
- end function
- function smoothNoise2dF(x as single, y as single) as single
- x=abs(x) : y=abs(y)
- dim as integer iX1=int(x)
- dim as integer iY1=int(y)
- dim as integer iX2=ix1+1
- dim as integer iY2=iy1+1
- dim as single tx=x-iX1
- dim as single ty=y-iY1
- iX1 and= NOISESIZE
- iX2 and= NOISESIZE
- iY1 and= NOISESIZE
- iY2 and= NOISESIZE
- #if 1
- iY1 shl= 10: iY2 shl= 10
- dim as single lt=fNoise((iY1+iX1) and 65535)
- dim as single rt=fNoise((iY1+iX2) and 65535)
- dim as single rb=fNoise((iY2+iX2) and 65535)
- dim as single lb=fNoise((iY2+iX1) and 65535)
- #else
- dim as single lt=Noise(iX1,iY1,0)
- dim as single rt=Noise(iX2,iY1,0)
- dim as single rb=Noise(iX2,iY2,0)
- dim as single lb=Noise(iX1,iY2,0)
- #endif
- dim as single sxt=lt + (rt-lt)*tx
- dim as single sxb=lb + (rb-lb)*tx
- dim as single v=sxt+(sxb-sxt)*ty
- return v
- end function
- function smoothNoise2dI(ifX as integer, iFy as integer) as integer
- ifX=abs(ifX) : ifY=abs(ifY)
- dim as integer ifX1=ifX and cfIntMask
- dim as integer ifY1=ifY and cfIntMask
- dim as integer ifX2=ifX1+cfOne
- dim as integer ifY2=ifY1+cfOne
- dim as integer ifTX=ifX-ifX1
- dim as integer ifTY=ifY-ifY1
- ifX1 = FixToInt(ifX1) and NoiseSize
- ifX2 = FixToInt(ifX2) and NoiseSize
- ifY1 and= cfNoiseSize
- ifY2 and= cfNoiseSize
- ifY1 shl= (10-cfBits)
- ifY2 shl= (10-cfBits)
- dim as integer lt=ifNoise((ifY1+ifX1) and 65535)
- dim as integer rt=ifNoise((ifY1+ifX2) and 65535)
- dim as integer rb=ifNoise((ifY2+ifX2) and 65535)
- dim as integer lb=ifNoise((ifY2+ifX1) and 65535)
- dim as integer ifXT=lt + (((rt-lt)*ifTX) shr cfBits)
- dim as integer ifXB=lb + (((rb-lb)*ifTX) shr cfBits)
- dim as integer v=ifXT+(((ifXB-ifXT)*ifTY) shr cfBits)
- return v
- end function
- function smoothNoise3d(x as single, y as single, z as single) as single
- x=abs(x)
- y=abs(y)
- z=abs(z)
- dim as integer iX1=int(x)
- dim as integer iY1=int(y)
- dim as integer iZ1=int(z)
- dim as integer iX2=ix1+1
- dim as integer iY2=iy1+1
- dim as integer iZ2=iz1+1
- dim as single tx=x-iX1
- dim as single ty=y-iY1
- dim as single tz=z-iZ1
- iX1 and= NOISESIZE
- iX2 and= NOISESIZE
- iY1 and= NOISESIZE
- iY2 and= NOISESIZE
- iZ1 and= NOISESIZE
- iZ2 and= NOISESIZE
- dim as single ltf=noise(iX1,iY1,iZ1)
- dim as single rtf=noise(iX2,iY1,iZ1)
- dim as single rbf=noise(iX2,iY2,iZ1)
- dim as single lbf=noise(iX1,iY2,iZ1)
- dim as single sxtf=ltf + (rtf-ltf)*tx
- dim as single sxbf=lbf + (rbf-lbf)*tx
- dim as single ltb=noise(iX1,iY1,iZ2)
- dim as single rtb=noise(iX2,iY1,iZ2)
- dim as single rbb=noise(iX2,iY2,iZ2)
- dim as single lbb=noise(iX1,iY2,iZ2)
- dim as single sxtb = ltb + (rtb-ltb)*tx
- dim as single sxbb = lbb + (rbb-lbb)*tx
- dim as single vf = sxtf+(sxbf-sxtf)*ty
- dim as single vb = sxtb+(sxbb-sxtb)*ty
- dim as single v = vf + (vb-vf)*tz
- return v
- end function
- function turbulence1d(x as single, size as single) as single
- dim as single value, initialSize=any
- if size<1 then size=1
- initialSize = size
- while(size >= 1)
- value += smoothNoise1d(x / size) * size
- size /= 2.0
- wend
- value*=0.5
- return value/initialSize
- end function
- function turbulence2dI(x as integer, y as integer, size as integer) as integer
- dim as integer value, initialSize=any
- if size<2 then size=2
- initialSize = (size-1)
- x = IntToFix(x): y = IntToFix(y)
- while(size >= 1)
- value += smoothNoise2dI(x \ size, y \ size) * size
- size shr= 1
- wend
- return (value shr 1)\initialSize
- end function
- function turbulence2dF(x as single, y as single, size as integer) as single
- dim as single value, initialSize=any
- if size<1 then size=1
- initialSize = size
- while(size >= 1)
- value += smoothNoise2dF(x / size, y / size) * size
- size shr= 1
- wend
- value*=0.5
- return value/(initialSize-1)
- end function
- function turbulence3d(x as single, y as single, z as single, size as single) as single
- dim as integer value, initialSize=any
- if size<1 then size=1
- initialSize = size
- while(size >= 1)
- value += smoothNoise3d(x / size, y / size, z / size) * size
- size /= 2.0
- wend
- value*=0.5
- return value/(initialSize-1)
- end function
- dim as integer sx,sy
- sx = 480
- sy = 300
- screenres(sx,sy,32,1,0)
- SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS)
- dim as double TMR = timer
- screenlock
- var pPix = cast(ulong ptr,screenptr)
- for y as integer = 0 to sy-1
- for x as integer = 0 to sx-1
- dim as ubyte clr = 255*turbulence2df(x,y,32)
- *pPix = rgb(clr,clr,clr): pPix += 1
- 'pset(x,y),rgb(clr,clr,clr)
- next x
- next y
- screenunlock
- sleep()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement