fire

BlitzPlus Forums/BlitzPlus Programming/fire

here is one last version before i go to sleep, 1 am

hold down the mouse in the white box to draw fire, its pritty cool, if you draw at the very bottom the fire stays and keeps going so you can make neet effects, its been transformed to 3d which is making it MUCH faster :)

have fun with it
il make a function set for it 2maro

Graphics3D 640,480

img = CreateTexture(100,100)

SetBuffer BackBuffer()
frame = 0
cooling = 2

entity = CreateSprite()
camera = CreateCamera()
PositionEntity camera,0,0,-1
EntityTexture entity,img
While Not KeyDown(1)

SetBuffer BackBuffer()
Cls
If MouseDown(1) 

SetBuffer TextureBuffer(img)
Color 255,255,255
Rect MouseX()-5,MouseY()-5,5,5
SetBuffer BackBuffer()
EndIf
LockBuffer TextureBuffer(img)
For x = 2 To 98
 	For y = 2 To 98
		top = ReadPixelFast(x,y-1,TextureBuffer(img))
		bot = ReadPixelFast(x,y+1,TextureBuffer(img))
		lleft = ReadPixelFast(x+1,y,TextureBuffer(img))
		rright = ReadPixelFast(x-1,y,TextureBuffer(img))
		If (GetRed(top)+GetRed(bot)+GetRed(lleft)+GetRed(rright))/4-cooling  > 0
		WritePixelFast x+Rand(-1,1),y-1,Combine((GetRed(top)+GetRed(bot)+GetRed(lleft)+GetRed(rright))/4-cooling ,0,0),TextureBuffer(img)
		EndIf
	Next
Next
UnlockBuffer TextureBuffer(img)

If frame = 100
	frame = 0
	cooling = Rand(1,5)
EndIf
frame = frame+1
	 

RenderWorld()
Rect 0,0,100,100

Flip
Wend
		
		
		
		
		
		
Function GetRed(col)	
Return (col Shr 16) And $FF 
End Function 
Function GetGreen(col)
Return  (col Shr 8) And $FF
End Function 
Function GetBlue(col)
Return col And $FF 
End Function 

Function Combine(r,g,b)
Return (b Or (g Shl 8) Or (r Shl 16) Or (255 Shl 24)) 
End Function