Lava Lamp

Blitz3D Forums/Blitz3D Beginners Area/Lava Lamp

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Thanks

I modified my own version to look more like lava. It really looks like a liquid!

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)
	tex = LoadTexture("blob.bmp")
	p\ent = CreateSprite()
	EntityTexture p\ent,tex
	p\temp = 0
	EntityBlend p\ent,3
	EntityFX p\ent,1
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#,80,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


It uses your blob image and effects to make it look a lot better. Thanks!!!