Code : Tout sélectionner
;====================================
; Fire Effect, flype
;====================================
EnableExplicit
#W = 200
#H = 150
#Z = 2
Global pow = 30
Global Dim pix.l(#W+2, #H+2)
;====================================
Procedure Clamp(x, min, max)
If x > max
ProcedureReturn max
EndIf
If x < min
ProcedureReturn min
EndIf
ProcedureReturn x
EndProcedure
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_Clear(color)
Protected x, y
For y = 0 To #H + 2
For x = 0 To #W + 2
pix(x, y) = color
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
If pix(x, y) < 210
Box(x*#Z, y*#Z, #Z, #Z, RGB(255, pix(x, y), 0))
Else
Box(x*#Z, y*#Z, #Z, #Z, RGB(255, 255, pix(x, y)))
EndIf
Next
Next
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, Str(pow), $00ffff)
StopDrawing()
EndIf
EndProcedure
Procedure FireEffect_Feed()
Protected i
For i = 0 To 20
pix(Random(#W, 0), #H+2) = Clamp(Random(pow, 0) * 2, 0, 255)
Next
EndProcedure
Procedure FireEffect_FeedMouse(color)
Protected x, y
Protected md = Random(10, 0)
Protected mx = ( WindowMouseX(0) + 1 ) / #Z
Protected my = ( WindowMouseY(0) + 1 ) / #Z
For y = -md To md
For x = -md To md
pix(Clamp(mx + x, 0, #W), #H+2) = color
;pix(Clamp(mx + x, 0, #W), my) = color
Next
Next
EndProcedure
Procedure FireEffect_SetPow()
pow + ( 5 * GetGadgetAttribute(0, #PB_Canvas_WheelDelta) )
pow = Clamp(pow, 0, 255)
EndProcedure
Procedure FireEffect_Update()
FireEffect_Calc()
FireEffect_Feed()
FireEffect_Draw()
FireEffect_FeedMouse(Random(255, 220))
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)
FireEffect_Clear(0)
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_MouseWheel: FireEffect_SetPow()
Case #PB_EventType_LeftClick: FireEffect_Clear(255)
Case #PB_EventType_RightClick: FireEffect_Clear(0)
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
FireEffect_Update()
ForEver
EndIf
;====================================