It's a 2D fire I'm afraid. Makes use of a particle sprite, but there are no AVIs. It's still coloured, scaled, alphas and positioned dynamically and is customisable.
As I said in the post, it's gonna be used for billboards. It's not me showing off.
It's for practical use - just thought I'd share the code. It could well be used for 3D applications though. This code does the job in 3D, although it's a quick botch.
Type FlameParticleType
OldX# as float
OldY# as float
X# as float
Y# as float
Color# as float
endtype
set display mode 1024,768,32
sync on
sync rate 100
color backdrop rgb(0,0,0)
backdrop on
hide mouse
autocam off
`********************
`***Fire constants***
`********************
`Half Width of particle sprite (used to offset to center (Set to half the width of the image))
dim ImageWidth(1)
ImageWidth(1) = 32
`Number of fire particles (Good Value = 500)
dim Particles(1)
Particles(1) = 600
`Radius of source of particles (fire base) (Good value = 50)
dim Radius(1)
Radius(1) = 50
`Upwards Base Speed of Particles (Good Value = 400)
dim Speed(1)
Speed(1) = 400
`Horizontal Particle Movement Speed (Good value = 50)
dim RandomNess(1)
RandomNess(1) = 1
`Speed at which heat of particle decreases (Good value = 200)
Dim ColorCut(1)
ColorCut(1) = 200
`Initial Scale of Partcles (Good Value = 200 (Higher values can cause crash))
dim FireSize(1)
FireSize(1) = 100
`X Positional offset of Fire source
Dim FireXOffset(1)
FireXOffset(1) = 0
`Y Positional offset of Fire source
Dim FireYOffset(1)
FireYOffset(1) = -50
`Choose 0 for flame mode and 1 for smoke mode
Dim FireSmokeMode(1)
FireSmokeMode(1) = 0
`Fire Particle Variables
dim FlamPart(Particles(1)) as FlameParticleType
if FireSmokeMode(1) = 0
load image "firepart.bmp",1
else
load image "oddpart.bmp",1
endif
``TEMP STUFF
dim XSpeed#(1)
XSpeed#(1) = 0.4
dim YSpeed#(1)
YSpeed#(1) = 0
dim BounceX#(1)
BounceX#(1) = screen width()/2.0
dim BounceY#(1)
BounceY#(1) = screen height()/2.0
make object box 1,5,100,5
color object 1,rgb(20,15,0)
offset limb 1,0,0,40,0
make object box 2,10,15,10
color object 2,rgb(40,30,5)
position camera 0,120,-100
yrotate camera 20
xrotate camera 20
set ambient light 10
color light 0,rgb(255,255,0)
set directional light 0,0,-1,0
`Initialise Particles to ensure fire routine is ready before first sync
`(very cpu intensive for large number of particles)
`InitialiseParticles()
do
`Loop through particles
for part=1 to Particles(1)
`particle doesnt exist, then make it
if FlamPart(part).color# <= 0
SetFlameParticle(part)
else
`Particle already exists, so process it
MoveParticle(part)
MorphParticle(part)
DisplayParticle(part)
endif
next part
ControlFire()
sync
loop
function SetFlameParticle(part)
`Position and set color of particle
BounceAround()
`basex# = (screen width()/2) + FireXOffset(1)
`basey# = (screen height())-Radius(1) + FireYOffset(1)
basex# = BounceX#(1)
basey# = BounceY#(1)
FlamPart(part).X# = basex#-Radius(1)+(rnd(Radius(1)*2))
FlamPart(part).Y# = basey#-Radius(1)+(rnd(Radius(1)*2))
distance# = sqrt((basex#-FlamPart(part).X#)^2+(basey#-FlamPart(part).Y#)^2)
FlamPart(part).Color# = 255-(200*(Distance#/Radius(1)))
sprite part,int(FlamPart(part).X#),int(FlamPart(part).Y#),1
offset sprite part,ImageWidth(1),ImageWidth(1)
endfunction
function MoveParticle(part)
`Move the position of the fire particle randomly
FlamPart(part).Y# = FlamPart(part).Y# - (Speed(1)+rnd(Speed(1)))/200.0
FlamPart(part).X# = FlamPart(part).X# + ((RandomNess(1)-rnd(RandomNess(1)*2))/400.0)
endfunction
function MorphParticle(part)
`Decrement Sprites colour
FlamPart(part).Color# = FlamPart(part).Color# - (rnd(ColorCut(1))/50.0)
`Use colour as a base to change transparency, RGB components and scale
if int(FlamPart(part).color#) >= 0
if FireSmokeMode(1) = 0
set sprite diffuse part,255,int(FlamPart(part).color#),0
else
set sprite diffuse part,int(FlamPart(part).color#),int(FlamPart(part).color#),int(FlamPart(part).color#)
endif
set sprite alpha part,int(128-((255-FlamPart(part).Color#)/2.0))
scale sprite part,int(FireSize(1)*(FlamPart(part).color#/255))
rotate sprite part,wrapvalue(sprite angle(part)-10+rnd(20))
endif
endfunction
function DisplayParticle(part)
`Sets the sprites position
sprite part,int(FlamPart(part).X#),int(FlamPart(part).Y#),1
endfunction
function ControlFire()
`Move the fire source around with the arrow keys
if upkey()
FireYOffset(1) = FireYOffset(1)-1
endif
if downkey()
FireYOffset(1) = FireYOffset(1)+1
endif
if leftkey()
FireXOffset(1) = FireXOffset(1)-1
endif
if rightkey()
FireXOffset(1) = FireXOffset(1)+1
endif
endfunction
function BounceAround()
yrotate object 1,wrapvalue(object angle y(1)+0.05)
xrotate object 1,sin(object angle y(1))*40
position object 2,0,0,0
xrotate object 2, object angle x(1)
yrotate object 2, object angle y(1)
move object up 2,80
position camera 0,80,0
yrotate camera wrapvalue(camera angle y()-0.05)
move camera -100
BounceX#(1) = object screen x(2)
BounceY#(1) = object screen y(2)
distance# = sqrt((object position x(2)-camera position x())^2+(object position y(2)-camera position y())^2+(object position z(2)-camera position z())^2)
FireSize(1) = int(300-distance#*1.5)
Radius(1) = int(150-distance#*0.75)
endfunction
function InitialiseParticles()
`Loop through particles
for part=1 to Particles(1)
`Make Particle
if FlamPart(part).color# <= 0
SetFlameParticle(part)
endif
for part2=1 to part
MoveParticle(part)
MorphParticle(part)
DisplayParticle(part)
next part2
next part
endfunction
Just replace the code above with this code. You still need the particle image in the same directory.
This image is a 3D torch made of a few boxes sweeping around infront of the camera on fire.
Signature? No! Obsolete! These days it's all about chip and pin!