Fire!

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Fire!

Post by Dreglor »

i created a nice looking fire example

it runs a bit slow in the res i have it...

heres the code for it
heres an updated version of it

Code: Select all

;********************************
;*Name: Fire                    *
;*By: Dreglor                   *
;*last updated: 9-20-03 1:26pm  *
;********************************

y.w=0
x.w=0
screen_width.w=1024
screen_height.w=768
Dim cool.w(screen_width,screen_height)
Dim buf.w(screen_width,screen_height)
yy.w=0
xx.w=0
For y=1 To screen_height-1
  For x=1 To screen_width-1
    cool(x,y)=Random(3) 
    buf(x,y)=0
  Next x
Next y
InitSprite()
OpenScreen(screen_width,screen_height,32,"FIRE!")
InitPalette(256)
CreatePalette(0)
Dim color(255)
For i=0 To 84 
color(i)=Int(255/84*i)+0<<8+0<<16 
color(i+85)=255+Int(255/84*i)<<8+0<<16
color(i+85+85)=255+255<<8+Int(255/84*i)<<16
Next i 
InitKeyboard()
Repeat 
  StartDrawing(ScreenOutput()) 
  For y=1 To screen_height-1
    For x=1 To screen_width-1 
      If buf(x,y) > 0
        If buf(x,y) < 0
          buf(x,y)=0
        Else
          buf(x,y)=((buf(x+1,y)+buf(x-1,y)+buf(x,y+1)+buf(x,y-1))/4-cool(x,y))
        EndIf        
        buf(x,y-1)=buf(x,y)
        cool(x,y-1)=cool(x,y)
        cool(x,y)=Random(3)
        If buf(x,y) > 0
          Plot(x,y,color(buf(x,y)))
        Endif
      EndIf
      buf(x,screen_height-2)=255
    Next x
  Next y
  StopDrawing()
  FlipBuffers()
  ;ClearScreen(0,0,0) don't need it :o
  ExamineKeyboard()  
Until KeyboardReleased(#PB_Key_Escape)
CloseScreen()
End

there you go, btw i though i had posted this earlyer but i guess i didn't (must be the lack of sleep lol)
Last edited by Dreglor on Sat Sep 20, 2003 9:27 pm, edited 1 time in total.
~Dreglor
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

it still looks nice at 640x480
and is not TOO slow on my
old pII 266Mhz with RagePro atir3
Joe
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

i think the main thing that slowing it is the drawing process
~Dreglor
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

works fine on my machine, but how do you make the flames taller?
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

change "cool(x,y)=Random(5)" on lines 17 and 44 to something like "cool(x,y)=Random(1)"
~Dreglor
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

To make the code faster only replot the point that really change!!!

60% of the area is unchanged...
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

ah yeah i did that for the math portion but not the drawing part *hit head*
~Dreglor
User avatar
aszid
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 01, 2003 8:38 pm
Location: California, USA
Contact:

Post by aszid »

another way to make it run better (and probably look better too) would be to just use particle emitters.... i'm pretty swamped at work right now... but when i get home i'll make an equivilant code that uses particles instead.
--Aszid--

Making crazy people sane, starting tomorrow.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

i wanted to modify this to have a partical engein on it but i never got it finshed...
~Dreglor
Post Reply