OK, this is my last try of posting this. If it dissappears again I give up!
A while back I made some code which generated a normal map in real-time of a water simulation which could then be used within a shader and was quite effective.
This is a little screensaver I made whilst messing around with the code from that water simulation.
hide mouse
set normalization on
get image 1,0,0,128,128
make memblock from image 1,1
make object plain 1,50,50
make mesh from object 1,1
for l=1 to 34
add limb 1,l,1
rotate limb 1,l,l*5,0,0
next l
delete mesh 1
position object 1,1000,1000,1000
texture object 1,1
set object ambient 1,0
set object light 1,0
set object cull 1,0
disable object zwrite 1
ghost object on 1
clone object 2,1
rotate object 2,0,90,0
set object ambient 2,0
set object light 2,0
set object cull 2,0
disable object zwrite 2
position camera 1000,1025,950
rotate camera 20,0,0
type Vertices
Height as float
Fixed as integer
Velocity as float
endtype
dim Grid(2,129,129) as Vertices
point camera 1000,1000,1000
color backdrop 0
sync on
sync rate 30
do
m=scancode()+mouseclick()+mousemovex()+mousemovey()+mousemovez()
if m>0
end
endif
turn object left 1,5
turn object left 2,5
pitch object up 1,2
pitch object up 2,2
inc t,1
RedTint#=abs(sin(t/2))*768.0
GreenTint#=abs(cos(t/2))*768.0
BlueTint#=abs(sin((t/2)+45))*768.0
for x=0 to 128
for y=0 to 128
Grid(0,x,y).Height=Grid(1,x,y).Height
a#=abs(Grid(0,x,y).Height)/5.0
r#=a#*RedTint#
g#=a#*GreenTint#
b#=a#*BlueTint#
if r#>255.0
r#=255.0
endif
if g#>255.0
g#=255.0
endif
if b#>255.0
b#=255.0
endif
r=r#
g=g#
b=b#
WriteToImageMemblock(1,128,128,x,y,r,g,b)
next y
next x
make image from memblock 1,1
if rnd(10)=1
for d=0 to rnd(2)
X=rnd(128)
Y=rnd(128)
Z#=(rnd(10))*-0.5
Grid(0,X,Y).Height=Z#
Grid(0,X,Y).Fixed=1
next d
endif
for x=1 to 127
for y=1 to 127
if Grid(0,x,y).Fixed=0
a#=Grid(0,x-1,y-1).Height
b#=Grid(0,x-1,y).Height
c#=Grid(0,x,y-1).Height
d#=(Grid(0,x,y).Height+(Grid(0,x,y).Velocity*3.0))*3.0
e#=Grid(0,x-1,y+1).Height
f#=Grid(0,x+1,y-1).Height
g#=Grid(0,x,y+1).Height
h#=Grid(0,x+1,y).Height
i#=Grid(0,x+1,y+1).Height
Grid(1,x,y).Height=(a#+b#+c#+d#+e#+f#+g#+h#+i#)/11.0
Grid(0,x,y).Velocity=(Grid(1,x,y).Height-Grid(0,x,y).Height)+(Grid(0,x,y).Velocity*0.18)
if Grid(1,x,y).Height<-5.0
inc Grid(0,x,y).Velocity,0.125
Grid(1,x,y).Height=-5.0
endif
if Grid(1,x,y).Height>5.0
dec Grid(0,x,y).Velocity,0.125
Grid(1,x,y).Height=5.0
endif
else
Grid(1,x,y).Height=Grid(0,x,y).Height
dec Grid(0,x,y).Fixed,1
endif
next y
next x
sync
loop
rem ============================================================================================
rem === WriteToImageMemblock() ===
rem ============================================================================================
function WriteToImageMemblock(MemblockID,ImageWidth,ImageHeight,X,Y,RedValue,GreenValue,BlueValue)
rem Find relative position in memblock
MemblockPosition=X+(Y*ImageWidth)
rem Check the position is in the memblock range
if MemblockPosition>=0
if MemblockPosition<(ImageWidth*ImageHeight)
rem Adjust the memblock accordingly
write memblock dword MemblockID,12+(MemblockPosition*4),rgb(RedValue,GreenValue,BlueValue)
endif
endif
rem End the function
endfunction
rem ============================================================================================
rem === ReadFromImageMemblock() ===
rem ============================================================================================
function ReadFromImageMemblock(MemblockID,ImageWidth,ImageHeight,X,Y)
rem Find relative position in memblock
MemblockPosition=X+(Y*ImageWidth)
rem Check the position is in the memblock range
if MemblockPosition>=0
if MemblockPosition<(ImageWidth*ImageHeight)
rem Adjust the memblock accordingly
ColorValue=memblock dword(MemblockID,12+(MemblockPosition*4))
endif
endif
rem End the function
endfunction ColorValue
I then made this slightly altered, more colourful, version.
hide mouse
get image 1,0,0,128,128
make memblock from image 1,1
make object plain 1,50,50
make mesh from object 1,1
for l=1 to 34
add limb 1,l,1
rotate limb 1,l,l*5,0,0
next l
delete mesh 1
position object 1,1000,1000,1000
texture object 1,1
set object ambient 1,0
set object light 1,0
set object cull 1,0
disable object zwrite 1
ghost object on 1
clone object 2,1
rotate object 2,0,90,0
set object ambient 2,0
set object light 2,0
set object cull 2,0
disable object zwrite 2
position camera 1000,1025,950
rotate camera 20,0,0
type Vertices
Height as float
Fixed as integer
Velocity as float
endtype
dim Grid(2,129,129) as Vertices
point camera 1000,1000,1000
color backdrop 0
sync on
sync rate 30
do
m=scancode()+mouseclick()+mousemovex()+mousemovey()+mousemovez()
if m>0
end
endif
turn object left 1,5
turn object left 2,5
pitch object up 1,2
pitch object up 2,2
inc t,1
for x=0 to 128
for y=0 to 128
RedTint#=abs(sin((t/2)+(cos(x*y*0.1)*45.0)))*768.0
GreenTint#=abs(cos((t/2)+(sin((x*y*0.1)+45.0)*45.0)))*768.0
BlueTint#=abs(sin(((t/2)+(sin(x*y*0.1)*45.0))+45.0))*768.0
Grid(0,x,y).Height=Grid(1,x,y).Height
a#=abs(Grid(0,x,y).Height)/5.0
r#=a#*RedTint#
g#=a#*GreenTint#
b#=a#*BlueTint#
if r#>255.0
r#=255.0
endif
if g#>255.0
g#=255.0
endif
if b#>255.0
b#=255.0
endif
r=r#
g=g#
b=b#
WriteToImageMemblock(1,128,128,x,y,r,g,b)
next y
next x
make image from memblock 1,1
if rnd(10)=1
for d=0 to rnd(2)
X=rnd(128)
Y=rnd(128)
Z#=(rnd(10))*-1.0
Grid(0,X,Y).Height=Z#
Grid(0,X,Y).Fixed=1
next d
endif
for x=1 to 127
for y=1 to 127
if Grid(0,x,y).Fixed=0
a#=Grid(0,x-1,y-1).Height
b#=Grid(0,x-1,y).Height
c#=Grid(0,x,y-1).Height
d#=(Grid(0,x,y).Height+(Grid(0,x,y).Velocity*3.0))*3.0
e#=Grid(0,x-1,y+1).Height
f#=Grid(0,x+1,y-1).Height
g#=Grid(0,x,y+1).Height
h#=Grid(0,x+1,y).Height
i#=Grid(0,x+1,y+1).Height
Grid(1,x,y).Height=(a#+b#+c#+d#+e#+f#+g#+h#+i#)/11.0
Grid(0,x,y).Velocity=(Grid(1,x,y).Height-Grid(0,x,y).Height)+(Grid(0,x,y).Velocity*0.18)
if Grid(1,x,y).Height<-5.0
inc Grid(0,x,y).Velocity,0.125
Grid(1,x,y).Height=-5.0
endif
if Grid(1,x,y).Height>5.0
dec Grid(0,x,y).Velocity,0.125
Grid(1,x,y).Height=5.0
endif
else
Grid(1,x,y).Height=Grid(0,x,y).Height
dec Grid(0,x,y).Fixed,1
endif
next y
next x
sync
loop
rem ============================================================================================
rem === WriteToImageMemblock() ===
rem ============================================================================================
function WriteToImageMemblock(MemblockID,ImageWidth,ImageHeight,X,Y,RedValue,GreenValue,BlueValue)
rem Find relative position in memblock
MemblockPosition=X+(Y*ImageWidth)
rem Check the position is in the memblock range
if MemblockPosition>=0
if MemblockPosition<(ImageWidth*ImageHeight)
rem Adjust the memblock accordingly
write memblock dword MemblockID,12+(MemblockPosition*4),rgb(RedValue,GreenValue,BlueValue)
endif
endif
rem End the function
endfunction
rem ============================================================================================
rem === ReadFromImageMemblock() ===
rem ============================================================================================
function ReadFromImageMemblock(MemblockID,ImageWidth,ImageHeight,X,Y)
rem Find relative position in memblock
MemblockPosition=X+(Y*ImageWidth)
rem Check the position is in the memblock range
if MemblockPosition>=0
if MemblockPosition<(ImageWidth*ImageHeight)
rem Adjust the memblock accordingly
ColorValue=memblock dword(MemblockID,12+(MemblockPosition*4))
endif
endif
rem End the function
endfunction ColorValue