Lava Lamp

Blitz3D Forums/Blitz3D Beginners Area/Lava Lamp

Does anyone know how to make a virtual lava lamp. I made one but it was just a bunch of circles moving around the screen. I just can't get it to look like a real lava lamp.

Here is the code below. The only picture you need is a 32*32 white circle named ptcl.bmp

Graphics3D 640,480,0,2

lit=CreateLight()
SeedRnd(MilliSecs())

AppTitle "Lava Lamp Particles"

cam=Createcamera()
CameraRange cam,.1,1000
PositionEntity cam,0,0,-10
pl=CreatePlane(1,cam)
PositionEntity pl,0,0,.15
RotateEntity pl,-90,0,0
EntityAlpha pl,0
EntityPickMode pl,2

Global drag = true

Type pt
	Field x#,y#,dx#,dy#,temp#,ent
End Type
num = Input("Please enter the number of particles you want to have. ")
For i = 1 To num
	p.pt = New pt
	p\x# = Rnd#(0,640)
	p\y# = Rnd#(0,480)
	p\ent = LoadSprite("ptcl.bmp")
	p\temp = 0
Next
SetBuffer BackBuffer()
While Not KeyDown(1)
Cls
If KeyHit(57) Then drag = Not drag

For p.pt = Each pt
p\x# = p\x# + p\dx#
p\y# = p\y# + p\dy#

EntityColor p\ent,p\temp,(-p\temp)+255,0
sprite2d(cam,p\ent,p\x#,p\y#,30,0,1)
p\dy# = p\dy# + ((-p\temp#/255)+1)/10 - .05

If p\temp# > 0 Then p\temp# = p\temp# - .1

If p\y# > 480 Then
	p\dy# = -p\dy#/2
	p\y# = 479
EndIf
If p\x# > 640 Then
	p\dx# = -p\dx#/2
	p\x# = 639
EndIf
If p\x# < 0 Then
	p\dx# = -p\dx#/2
	p\x# = 1
EndIf
If p\y# < 0 Then
	p\dy# = -p\dy#/2
	p\y# = 1
EndIf

If drag Then
	If MouseDown(1) Then
		dist# = Sqr((p\x#-MouseX())^2+(p\y#-MouseY())^2)
		If dist# < 50 Then
			If p\temp# < 255 Then p\temp# = p\temp# + 30*(-dist# + 50)/50
		EndIf
	ElseIf MouseDown(2)
		dist# = Sqr((p\x#-MouseX())^2+(p\y#-MouseY())^2)
		If dist# < 50 Then
			If p\temp# > 0 Then p\temp# = p\temp# - 30*(-dist# + 50)/50
		EndIf
	EndIf
Else
	If MouseDown(1) Then
		dist# = Sqr((p\x#-MouseX())^2+(p\y#-MouseY())^2)
		If dist# < 50 Then
			p\x# = MouseX()
			p\y# = MouseY()
			p\dx# = 0
			p\dy# = 0
		EndIf
	EndIf
EndIf
For g.pt = Each pt
	If g\x# <> p\x# Or g\y# <> p\y# Then
		dist# = Sqr((p\x#-g\x#)^2+(p\y#-g\y#)^2)
		If dist# < 20 Then
			If p\temp# > g\temp# Then
				p\temp# = p\temp# - 10
				g\temp# = g\temp# + 10
			ElseIf p\temp# < g\temp# Then
				p\temp# = p\temp# + 10
				g\temp# = g\temp# - 10
			EndIf
			dx# = p\x# - g\x#
			dy# = p\y# - g\y#
			dx# = dx#*(dist#/20)
			dy# = dy#*(dist#/20)
			p\x# = p\x# + dx#/5
			p\y# = p\y# + dy#/5
			p\dx# = -p\dx#/3+Rnd(-.01,.01)
			p\dy# = -p\dy#/3+Rnd(-.01,.01)
			
		EndIf
	EndIf
Next

Next

UpdateWorld()
RenderWorld()
Flip
Wend
End

Function Sprite2D(cam,sprite,x#,y#,size#,ang#,alpha#)
	ent=CameraPick(cam,x,y)
	If ent Then 
		PositionEntity sprite,PickedX(),PickedY(),PickedZ()
		ScaleSprite sprite,size/2560,size/2560
		RotateSprite sprite,ang
		EntityAlpha sprite,alpha
	End If
End Function


Just click the circles to heat them up and right click them to cool them down.

Please give me any suggestions you have on how to make this look more realistic.

P.S. I recommend 100 particles.