This is an Example how to build a endless animation of clouds
with Perlin Noise.
sync on : sync rate 0 : randomize timer() : autocam off
backdrop on : color backdrop 0 : ink rgb(0, 0, 255), 0
dim map(255, 255)
dim tmp(33, 33, 3) as float
make memblock 1, 12 + (256 * 256 * 4)
write memblock dword 1, 0, 256
write memblock dword 1, 4, 256
write memblock dword 1, 8, 32
bx = (screen width() >> 1) - 100
by = (screen height() >> 1) - 10
MakeNoise(0)
SmoothNoise(0)
repeat
inc i
OverlapNoise()
CurveNoise(30, 0.97)
ViewNoise(i)
if not l
MakeNoise(1)
SmoothNoise(1)
if i < 96
MakeFadePal(1)
else
MakeFadePal(2)
endif
l = 32
endif
dec l
FadeNoise()
WorkBar(bx, by, 200.0 / 128 * i)
until i = 128
color backdrop rgb(164, 0, 255) : ink rgb(0, 0, 255), 0
make object sphere 1, 256, 32, 32
scale object texture 1, 2, 4
set object cull 1, 0
set object light 1, 0
ghost object on 1, 2
i = 1
repeat
if t < timer()
texture object 1, i
t = timer() + 100
inc i
if i = 129 then i = 1
endif
rotate camera 0, mousex(), 0
set cursor 0, 0
print "FPS: ", screen fps()
print "Image: ", i
sync
until mouseclick()
end
function MakeNoise(s)
for x = 1 to 32
for y = 1 to 32
tmp(x, y, s) = rnd(255)
if not s then tmp(x, y, 2) = tmp(x, y, s)
next y
next x
for i = 1 to 32
tmp(i, 0, s) = tmp(i, 32, s)
tmp(i, 33, s) = tmp(i, 1,s)
tmp(0, i, s) = tmp(32, i, s)
tmp(33, i, s) = tmp(1, i, s)
next i
tmp(0, 0, s) = tmp(32, 32, s)
tmp(33, 33, s) = tmp(1, 1, s)
tmp(33, 0, s) = tmp(1, 32, s)
tmp(0, 33, s) = tmp(32, 1, s)
endfunction
function SmoothNoise(s)
for x = 1 to 32
for y = 1 to 32
c = (tmp(x - 1, y - 1, s) + tmp(x + 1, y - 1, s) + tmp(x - 1, y + 1, s) + tmp(x + 1, y + 1, s)) / 16
e = (tmp(x - 1, y, s) + tmp(x + 1, y, s) + tmp(x, y - 1, s) + tmp(x, y + 1, s)) / 8
m = tmp(x, y, s) / 4
tmp(x, y, s) = c + e + m
if not s then tmp(x, y, 2) = tmp(x, y, s)
next y
next x
endfunction
function Interpolate(x#, y#)
x = int(x#) : xf# = x# - x
y = int(y#) : yf# = y# - y
x0 = x mod 32 + 1 : x1 = (x + 1) mod 32 + 1
y0 = y mod 32 + 1 : y1 = (y + 1) mod 32 + 1
t = tmp(x0, y1, 0) + xf# * (tmp(x1, y1, 0) - tmp(x0, y1, 0))
b = tmp(x0, y0, 0) + xf# * (tmp(x1, y0, 0) - tmp(x0, y0, 0))
r = b + yf# * (t - b)
endfunction r
function OverlapNoise()
for o = 0 to 3
f# = 1 << o
a = 8 >> o
for x = 0 to 255
for y = 0 to 255
map(x, y) = map(x, y) + Interpolate(x / f#, y / f#) / a
next y
next x
next o
endfunction
function CurveNoise(c#, s#)
for x = 0 to 255
for y = 0 to 255
c = map(x, y) - (255 - c#)
if c < 0 then c = 0
map(x, y) = 255 - s# ^ c * 255
next y
next x
endfunction
function ViewNoise(i)
for x = 0 to 255
for y = 0 to 255
c = map(x, y)
map(x, y) = 0
write memblock dword 1, 12 + (y * 256 + x) * 4, rgb(c, c, c)
next y
next x
make image from memblock i, 1
endfunction
function MakeFadePal(s)
for x = 0 to 33
for y = 0 to 33
tmp(x, y, 3) = (tmp(x, y, s) - tmp(x, y, 0)) / 32
next y
next x
endfunction
function FadeNoise()
for x = 0 to 33
for y = 0 to 33
tmp(x, y, 0) = tmp(x, y , 0) + tmp(x, y, 3)
next y
next x
endfunction
function WorkBar(x, y, w)
ink rgb(128, 128, 128), 0 : box x, y, x + 200, y + 20
ink rgb(255, 255, 255), 0 : box x, y, x + w, y + 20
set cursor x + 90, y + 20 : print w >> 1, "%"
sync
endfunction