Argh! Not another plasma demo! Well, yes it is. Enjoy.
set display mode 1024,768,32
sync on
sync rate 0
autocam off
hide mouse
color backdrop 0
amp#=20.0
rows=100
columns=100
elasticity#=0.0002
a=20
b=5
position camera rows/2,50,columns/2
yrotate camera -90
point camera rows/2,0,columns/2
create bitmap 1,10,10
box 0,0,10,10,rgb(0,255,0),rgb(255,0,0),rgb(0,0,255),rgb(255,255,0)
get image 1,0,0,10,10
delete bitmap 1
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
gosub load
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#
y#=amp#*sin(theta#)
theta#=theta#+0.01*dt#
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#
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
if spacekey()>0 and saving=0 then gosub save
if spacekey()=0 and saving=1 then saving=0
inc syncnumber
if syncnumber>20 then sync
loop
save:
if file exist("data.dat")=1 then delete file "data.dat"
open to write 1,"data.dat"
saving=1
for x=1+1 to rows-1
for z=1+1 to columns-1
write float 1,get matrix height(1,x,z)
write float 1,v#(obnum(x,z))
next z
next x
close file 1
return
load:
if file exist("data.dat")
open to read 1,"data.dat"
for x=1+1 to rows-1
for z=1+1 to columns-1
read float 1,height#
set matrix height 1,x,z,height#
read float 1,v#(obnum(x,z))
next z
next x
close file 1
endif
return
I have included a load and save routine, so you can save a file with the desired start position of the demo. Just press space to save the desired starting point. Then the next time you run it, it will start from the point you chose.
Please help me test this code! I have attempted to use a timer loop so that it works the same at different frames per second. But because my pc is so slow I can only test it over a small range of fps's. Please test it at a low fps (say 20 fps) by adjusting line 3 to 'sync rate 20', then put it back to the maximum fps (sync rate 0) and tell me if it behaves any differently - eg. if it seems to go faster, or appears jerky or jagged. Thanks.