REM ***********************************************
REM Title: Jelly Physics
REM Author: Ric
REM Downloaded from: http://dbcc.zimnox.com/
REM ***********************************************
 
`*** Jelly Physics by Ric ***
 
 
sync on:sync rate 40:autocam off:hide mouse:color backdrop 0
 
make object sphere 1,1
color object 1,rgb(255,0,0)
position object 1,-2,0,0
make object cone 2,0.8
color object 2,rgb(0,255,0)
position object 2,0,0,-2
make object cube 3,1
color object 3,rgb(0,0,255)
position object 3,2,0,0
position camera 0,0,-5
sync
get image 1,0,0,screen width(),screen height(),1
delete object 1
delete object 2
delete object 3
 
omega#=1.0
amp#=20.0
rows=50
columns=50
elasticity#=0.004
damping#=0.99
a=15
b=10
 
position camera rows/2,50,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
 
do
 
y#=amp#*sin(theta#)
theta#=theta#+2
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
vectorsum#=distxp1#+distxm1#+distzp1#+distzm1#
a#=vectorsum#*elasticity#
v#(obnum(x,z))=v#(obnum(x,z))+a#
set matrix height 1,x,z,get matrix height(1,x,z)+v#(obnum(x,z))
v#(obnum(x,z))=v#(obnum(x,z))*damping#
next z
next x
update matrix 1
sync
 
loop