Code: Select all
;====================================
; Fire Effect, flype
;====================================
EnableExplicit
#W = 200
#H = 150
#Z = 2
Global Dim pix.l(#W+2, #H+2)
;====================================
Procedure FireEffect_Calc()
Protected x, y
For y = 0 To #H + 1
For x = 1 To #W - 1
pix(x, y) = (pix(x-1, y) + pix(x+1, y) + pix(x, y+1) + pix(x, y+1)) >> 2
Next
Next
EndProcedure
Procedure FireEffect_Draw()
Protected x, y
If StartDrawing(CanvasOutput(0))
For y = 0 To #H - 1
For x = 0 To #W - 1
Box(x*#Z, y*#Z, #Z, #Z, pix(x, y))
Next
Next
StopDrawing()
EndIf
EndProcedure
Procedure FireEffect_Feed()
Protected i
For i = 0 To 255 Step 32
pix(Random(#W, 0), #H+2) = i
Next
EndProcedure
Procedure FireEffect_Update()
FireEffect_Calc()
FireEffect_Feed()
FireEffect_Draw()
EndProcedure
;====================================
If OpenWindow(0, 0, 0, #W*#Z, #H*#Z, "Fire Effect", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, #W*#Z, #H*#Z)
AddWindowTimer(0, 0, 5)
BindEvent(#PB_Event_Timer, @FireEffect_Update(), 0, 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
;====================================