set display mode 1024,768,32
sync on
sync rate 40
autocam off
hide mouse
color backdrop 0
 
create bitmap 1,screen width(),screen height()
make2images()
delete bitmap 1
 
 
amp#=1.0
rows=100
columns=100
elasticity#=0.00002
a=rows/2
b=columns/2
damping#=0.99
 
make object plain 1,rows,columns
xrotate object 1,-90
texture object 1,2
position object 1,rows/2.0,-10,columns/2.0
 
position camera rows/2,30,columns/2
yrotate camera -90
point camera rows/2,0,columns/2
 
 
num=rows*columns
dim obnum(rows+1,columns+1)
dim v#(rows,columns)
make matrix 1,rows,columns,rows,columns
for x=1 to rows
for z=1 to columns
obnum(x,z)=ob
ob=ob+1
next z
next x
 
prepare matrix texture 1,1,rows,columns
tile=1
for x=rows-1 to 0 step -1
for z=0 to columns-1
set matrix tile 1,z,x,tile
inc tile
next z
next x
 
 
 
 
starttime=timer()
 
do
 
`text 0,0,str$(screen fps())
time=timer()-starttime
dtperloop#=time-oldtime
inc totaldt#,dtperloop#
oldtime=time
 
inc loopnumber
if loopnumber=10
  loopnumber=0
  dt#=totaldt#/10.0
  totaldt#=0
endif
 
roll camera right 0.005*dt#
if inkey$()="1" then y#=-100
if inkey$()="2" then y#=10
set matrix height 1,a,b,y#
for x=1+1 to rows-1
for z=1+1 to columns-1
if x<rows
distxp1#=get matrix height(1,x+1,z)-get matrix height (1,x,z)
endif
if x>1
distxm1#=get matrix height(1,x-1,z)-get matrix height (1,x,z)
endif
if z<columns
distzp1#=get matrix height(1,x,z+1)-get matrix height (1,x,z)
endif
if z>1
distzm1#=get matrix height(1,x,z-1)-get matrix height (1,x,z)
endif
vectorsumx#=(distxp1#+distxm1#)
vectorsumz#=(distzp1#+distzm1#)
vectorsum#=vectorsumx#+vectorsumz#
a#=vectorsum#*elasticity#
v#(obnum(x,z))=v#(obnum(x,z))+a#*dt#
v#(obnum(x,z))=v#(obnum(x,z))*damping#
if v#(obnum(x,z))>0.01 then v#(obnum(x,z))=0.01
if v#(obnum(x,z))<-0.01 then v#(obnum(x,z))=-0.01
set matrix height 1,x,z,get matrix height(1,x,z)+v#(obnum(x,z))*dt#
`if get matrix height(1,x,z)>amp# then set matrix height 1,x,z,amp#
`if get matrix height(1,x,z)<-amp# then set matrix height 1,x,z,-amp#
next z
next x
update matrix 1
 
 
 
inc syncnumber
if syncnumber>20 then sync
loop
 
 
 
function make2images()
 
autocam off
color backdrop 0
position camera 0,0,0
for image=1 to 2
`if image=1 then color backdrop rgb(150,150,250) else color backdrop rgb(250,0,0)
for n=1 to 500
if image=1 then make object box n,rnd(10)+1,rnd(10)+1,rnd(10)+1
if image=2 then make object sphere n,rnd(7)+1,20,20
color object n,rnd(1000000000)
position object n,rnd(100)-50,rnd(100)-50,rnd(100)+50
next n
sync
get image image,0,0,screen width(),screen height(),1
delete objects 1,500
next image
 
endfunction