hi there
i made this "liquid" recently thought i might post it here.
as usual, it uses the advanced2d plugin but it is not necessary.
changing the values of :
visc#
bounce#
grav#
grav2#
will modify the "liquids" behaviour
sync on : sync rate 0
w = screen width() : h = screen height()
type UDTdot
x# : y# : z#
vec
c as dword
gx : gy
endtype
a = 300
b = w/10 : c = h/10
dim d(a) as UDTdot
for i = 1 to a : n = make vector2(i) : next
for i = 1 to a
d(i).x# = rnd(w) : d(i).y# = rnd(h)
d(i).vec = createvector()
NEXT
frame = 10
bounce# = 0.5
grav# = 0.05
grav2# = 0.001
visc# = 10000
ca = 2
wc as dword
wc = rgb(3,9,18)
a2setblendmode 2,2,1
do
if upkey() then inc visc#
if downkey() then dec visc#
text 0,0,str$(amount)
set vector2 1,mousex()-w/2.0,mousey()-h/2.0
set vector2 3,-y vector2(1),x vector2(1)
lenvec(1,grav#) : lenvec(3,grav2#)
for i = 1 to a
add vector2 d(i).vec,d(i).vec,1
ox# = d(i).x# : oy# = d(i).y#
d(i).x# = d(i).x#+x vector2(d(i).vec) : d(i).y# = d(i).y#+y vector2(d(i).vec)
d(i).x# = minmaxx(d(i).vec,d(i).x#,frame,w-frame,bounce#) : d(i).y# = minmaxy(d(i).vec,d(i).y#,frame,h-frame,bounce#)
rem a2circle d(i).x#,d(i).y#,6,rgb(1,3,6)
rem if i < 100 then a2line ox#,oy#,d(i).x#,d(i).y#,rgb(125,125,255)
NEXT
a2startlinebatch amount
amount = 0
for i = 1 to a
for j = 1 to a
if j <> i and squaredist(d(i).x#,d(i).y#,d(j).x#,d(j).y#) < visc#
set vector2 2,d(i).x#-d(j).x#,d(i).y#-d(j).y#
lenvec(2,40.0/(squared length vector2(2)+1))
add vector2 d(i).vec,d(i).vec,2 : add vector2 d(i).vec,d(i).vec,3
len# = length vector2(d(i).vec)*0.99 : len5# = len#*5
a2line d(i).x#,d(i).y#,d(j).x#,d(j).y#,rgb(3+len5#,9+len5#,18+len5#) : inc amount
endif
next
lenvec(d(i).vec,len#)
NEXT
a2endbatch
sync : cls
dimscreen(rgb(ca,ca,ca) )
LOOP
function dimscreen(dimness as dword)
a2setblendmode 2,2,3
a2fillbox 0,0,screen width(),screen height(),dimness
a2setblendmode 2,2,1 : a2dot 1,-10,0
ENDFUNCTION
function getbox(x#,w10)
x = x#/w10
endfunction x
function lenvec(vec,len#)
normalize vector2 vec,vec
multiply vector2 vec,len#
ENDFUNCTION
function createvector()
num = find free vector()
null = make vector2(num)
ENDFUNCTION num
function minmaxy(vec,variable#,vmin#,vmax#,b#)
if variable# < vmin# then variable# = vmin# : set vector2 vec,x vector2(vec)*b#,-y vector2(vec)*b#
if variable# > vmax# then variable# = vmax# : set vector2 vec,x vector2(vec)*b#,-y vector2(vec)*b#
endfunction variable#
function minmaxx(vec,variable#,vmin#,vmax#,b#)
if variable# < vmin# then variable# = vmin# : set vector2 vec,-x vector2(vec)*b#,y vector2(vec)*b#
if variable# > vmax# then variable# = vmax# : set vector2 vec,-x vector2(vec)*b#,y vector2(vec)*b#
endfunction variable#
function normangle(z1#,z2#)
if z1#-z2# < -180 then z1# = z1#+360
if z1#-z2# > 180 then z1# = z1#-360
endfunction z1#
function squaredist(x1#,y1#,x2#,y2#)
d# = (x1#-x2#)^2+(y1#-y2#)^2
ENDFUNCTION d#
function dist(x1#,y1#,x2#,y2#)
d# = sqrt((x1#-x2#)^2+(y1#-y2#)^2)
ENDFUNCTION d#
and a filled variant
Rem ***** Main Source File *****
sync on : sync rate 0
w = screen width() : h = screen height()
type UDTdot
x# : y# : z#
vec
c as dword
gx : gy
endtype
a = 300
b = w/10 : c = h/10
dim d(a) as UDTdot
for i = 1 to a : n = make vector2(i) : next
for i = 1 to a
d(i).x# = rnd(w) : d(i).y# = rnd(h)
d(i).vec = createvector()
NEXT
frame = 10
bounce# = 0.5
grav# = 0.08
ener# = 10.0
grav2# = 0.000
visc# = 9000
ca = 2
wc as dword
wc = rgb(30,90,180)
do
if upkey() then inc visc#
if downkey() then dec visc#
text 0,0,str$(amount)
set vector2 1,mousex()-w/2.0,mousey()-h/2.0
set vector2 3,-y vector2(1),x vector2(1)
lenvec(1,grav#) : lenvec(3,grav2#)
for i = 1 to a
add vector2 d(i).vec,d(i).vec,1
ox# = d(i).x# : oy# = d(i).y#
d(i).x# = d(i).x#+x vector2(d(i).vec) : d(i).y# = d(i).y#+y vector2(d(i).vec)
d(i).x# = minmaxx(d(i).vec,d(i).x#,frame,w-frame,bounce#) : d(i).y# = minmaxy(d(i).vec,d(i).y#,frame,h-frame,bounce#)
rem a2circle d(i).x#,d(i).y#,6,rgb(1,3,6)
rem if i < 100 then a2line ox#,oy#,d(i).x#,d(i).y#,rgb(125,125,255)
NEXT
a2starttrianglebatch amount
amount = 0
for i = 1 to a
on = 0
for j = 1 to a
if j <> i and squaredist(d(i).x#,d(i).y#,d(j).x#,d(j).y#) < visc#
set vector2 2,d(i).x#-d(j).x#,d(i).y#-d(j).y#
lenvec(2,ener#/(squared length vector2(2)+1))
add vector2 d(i).vec,d(i).vec,2 : add vector2 d(i).vec,d(i).vec,3
len# = length vector2(d(i).vec)*0.99 : len5# = len#*0.5
if on > 0
rem a2filltriangle d(i).x#,d(i).y#,d(j).x#,d(j).y#,d(on).x#,d(on).y#,rgb(1+len5#,2+len5#,3+len5#) : inc amount
a2filltriangle d(i).x#,d(i).y#,d(j).x#,d(j).y#,d(on).x#,d(on).y#,wc : inc amount
on = 0
endif
if on = 0 then on = j
endif
next
lenvec(d(i).vec,len#)
NEXT
a2endbatch
sync : cls
rem dimscreen(rgb(ca,ca,ca) )
LOOP
function dimscreen(dimness as dword)
a2setblendmode 2,2,3
a2fillbox 0,0,screen width(),screen height(),dimness
a2setblendmode 2,2,1 : a2dot 1,-10,0
ENDFUNCTION
function getbox(x#,w10)
x = x#/w10
endfunction x
function lenvec(vec,len#)
normalize vector2 vec,vec
multiply vector2 vec,len#
ENDFUNCTION
function createvector()
num = find free vector()
null = make vector2(num)
ENDFUNCTION num
function minmaxy(vec,variable#,vmin#,vmax#,b#)
if variable# < vmin# then variable# = vmin# : set vector2 vec,x vector2(vec)*b#,-y vector2(vec)*b#
if variable# > vmax# then variable# = vmax# : set vector2 vec,x vector2(vec)*b#,-y vector2(vec)*b#
endfunction variable#
function minmaxx(vec,variable#,vmin#,vmax#,b#)
if variable# < vmin# then variable# = vmin# : set vector2 vec,-x vector2(vec)*b#,y vector2(vec)*b#
if variable# > vmax# then variable# = vmax# : set vector2 vec,-x vector2(vec)*b#,y vector2(vec)*b#
endfunction variable#
function normangle(z1#,z2#)
if z1#-z2# < -180 then z1# = z1#+360
if z1#-z2# > 180 then z1# = z1#-360
endfunction z1#
function squaredist(x1#,y1#,x2#,y2#)
d# = (x1#-x2#)^2+(y1#-y2#)^2
ENDFUNCTION d#
function dist(x1#,y1#,x2#,y2#)
d# = sqrt((x1#-x2#)^2+(y1#-y2#)^2)
ENDFUNCTION d#