Cobbled this together from various sources - bit late now - falling asleep, zzzZZZzzzZZZ zzzZZZzzzZZZ
There's a bit of code in middle somewhere that does the normals stuff. It assumes light source at bottom left of matrix. Fiddle with numbers if you want something different.
ms=6000 : mt=60
sync on : sync rate 0 : autocam off : randomize timer()
w=4 : h=4 : r=64
create bitmap 1,w*r,h*r
for f=1 to h
for g=1 to w
b=rnd(255) : ink rgb(b,b,b),rgb(0,0,0) : box (g-1)*r,(f-1)*r,g*r,f*r
next g
next f
for f=1 to (w*h*10)
a1=rnd(w*r) : b1=rnd(h*r) : c1=rnd(20)+2 : d1=rnd(20)+2
ink rgb(rnd(255),rnd(255),rnd(255)),rgb(0,0,0)
box a1,b1,a1+c1,b1+d1
next f
get image 1,0,0,w*r,h*r,1 : delete bitmap 1
make matrix 1,ms,ms,mt,mt
prepare matrix texture 1,1,w,h
for f=0 to (mt-1)
for g=0 to (mt-1)
set matrix tile 1,f,g,rnd((w*h)-1)+1
next g
next f
set matrix trim 1,0.1,0.1
for f=1 to rnd(20)
randomize matrix 1,3000
next f
smooth_matrix(1,mt,mt,6)
` set normals
for x=0 to mt
for y=0 to mt
a=get matrix height(1,x,y)
if x < mt and y < mt
b=get matrix height(1,x+1,y+1)
endif
dif=a-b
x#=1-sin(dif*2) : y#=x# : z#=x#
set matrix normal 1,x,y,x#,y#,z#
next y
next x
update matrix 1
position camera 20,0,20
do
control camera using arrowkeys 0,5,3
cx#=camera position x()
cz#=camera position z()
h#=get ground height(1,cx#,cz#)
position camera cx#,h#+50,cz#
sync
loop
function smooth_matrix(matnum,tilex,tilez,times)
for multiple=1 to times
for x=1 to tilex-1
for z=1 to tilez-1
a=get matrix height(matnum,x-1,z+1)
b=get matrix height(matnum,x,z+1)
c=get matrix height(matnum,x+1,z+1)
d=get matrix height(matnum,x+1,z)
e=get matrix height(matnum,x+1,z-1)
f=get matrix height(matnum,x,z-1)
g=get matrix height(matnum,x-1,z-1)
h=get matrix height(matnum,x-1,z)
total=a+b+c+d+e+f+g+h
av#=total/8
set matrix height matnum,x,z,av#
next z
next x
for x=0 to tilex
set matrix height matnum,x,0,get matrix height(matnum,x,1)
set matrix height matnum,x,tilez,get matrix height(matnum,x,tilez-1)
next x
for z=0 to tilez
set matrix height matnum,0,z,get matrix height(matnum,1,z)
set matrix height matnum,tilex,z,get matrix height(matnum,tilex-1,z)
next z
next multiple
update matrix matnum
endfunction
The programmer formerly known as sonic