Page 1 of 1

Fire!

Posted: Sat Sep 20, 2003 3:40 am
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)

Posted: Sat Sep 20, 2003 8:26 am
by TronDoc
it still looks nice at 640x480
and is not TOO slow on my
old pII 266Mhz with RagePro atir3
Joe

Posted: Sat Sep 20, 2003 9:45 am
by Dreglor
i think the main thing that slowing it is the drawing process

Posted: Sat Sep 20, 2003 11:26 am
by jack
works fine on my machine, but how do you make the flames taller?

Posted: Sat Sep 20, 2003 8:10 pm
by Dreglor
change "cool(x,y)=Random(5)" on lines 17 and 44 to something like "cool(x,y)=Random(1)"

Posted: Sat Sep 20, 2003 9:05 pm
by Num3
To make the code faster only replot the point that really change!!!

60% of the area is unchanged...

Posted: Sat Sep 20, 2003 9:21 pm
by Dreglor
ah yeah i did that for the math portion but not the drawing part *hit head*

Posted: Sat Sep 20, 2003 11:23 pm
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.

Posted: Sun Sep 21, 2003 1:48 am
by Dreglor
i wanted to modify this to have a partical engein on it but i never got it finshed...