Lava Lamp

Blitz3D Forums/Blitz3D Beginners Area/Lava Lamp

Your code isn't working here and I don't have time to look through it, but here is a lavaball effect I did a few years ago.

Edit: you will need an image to make this work. Use the code in the next post to make it.


Const ScreenWidth = 320
Const ScreenHeight = 240

Graphics3D ScreenWidth,ScreenHeight,0,2
SetBuffer BackBuffer()

Dim image(screenwidth,screenheight)

Global tx#,ty#

Type vector2
	Field x#
	Field y#
End Type

Type particle
	Field entity 
	Field pos.vector2
	Field vel.vector2
	Field mass#
	Field force.vector2
End Type

blobtex = LoadTexture ("blob.bmp")

For loop = 1 To 50
	a.particle = New particle
	a\entity = CreateSprite ()
	a\pos = New vector2
	a\pos\x = Rnd(-30,30)
	a\pos\y = Rnd(-30,30)
	a\vel = New vector2
	a\vel\x = Rnd(-0.20,0.20)
	a\vel\y = Rnd(-0.20,0.20)
	a\mass = Rnd(3,10)

	ScaleSprite a\entity,a\mass,a\mass
	EntityTexture a\entity,blobtex
	EntityFX a\entity,1 ; full bright
	EntityBlend a\entity,3 ;additive mix
Next

cam = CreateCamera ()
PositionEntity cam,0,20,0
TurnEntity cam,90,0,0

CameraClsColor cam,0,79,174
ClsColor 0,79,174

While Not KeyHit(1)	
	updateblobs()
	MoveEntity cam,0,0,MouseZSpeed () *2
	;UpdateWorld()
	RenderWorld()

	drawblobs() ;draw the screen using a threshold
	;drawblobs2() ;draw the screen using a threshold (one color version)

	Flip 	
Wend

End

Function 	updateblobs()
	For p.particle = Each particle
		p\pos\x = p\pos\x + p\vel\x
		p\pos\y = p\pos\y + p\vel\y

		If p\pos\x  > 32 Or  p\pos\x  < -32 p\vel\x = -p\vel\x
		If p\pos\y  > 32 Or  p\pos\y  < -32 p\vel\y = -p\vel\y

		PositionEntity p\entity,p\pos\x,0,p\pos\y	
	Next
End Function

Function drawblobs2()	;make blobs
	LockBuffer BackBuffer()
		For x = 0 To ScreenWidth -1
			For y = 0 To ScreenHeight -1
				argb=ReadPixelFast(x,y);ImageBuffer(image_name))
				gotr=(ARGB Shr 16) And $ff 
				;gotg=(ARGB Shr 8) And $ff 
				;gotb=ARGB And $ff
				If gotr > 128
					WritePixelFast x,y,$0080FF
				Else
					WritePixelFast x,y,$004FC6
				EndIf 
			Next
		Next
	UnlockBuffer BackBuffer()
End Function

Function drawblobs()	;make blobs
	LockBuffer BackBuffer()
		For x = 0 To ScreenWidth -1 
			For y = 0 To ScreenHeight -1 
				argb=ReadPixelFast(x,y)
				r=(ARGB Shr 16) And $ff 
				If r > 105
					WritePixelFast x,y,$000000;$0080FF
				ElseIf r > 64
					WritePixelFast x,y,$ffffff
				Else 

				EndIf 
			Next
		Next

	UnlockBuffer BackBuffer()
End Function