Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WindowsConstants.au3>
- #include <GUIConstants.au3>
- #include <WinAPI.au3>
- ; -Author: name22 (www.autoit.de)
- Global $hDll_GDI32 = DllOpen("gdi32.dll")
- Global $iLength = 100
- Global $iColor_Tree = 0x00FF00, $iColor_Fire = 0x0000FF, $iColor_Empty = 0
- Global $fIgnition = 0.0001, $fGrowth = 0.01, $fTree = 0.55
- Opt("GUIOnEventMode", 1)
- $hWnd = GUICreate("Forest Fire", $iLength, $iLength)
- GUISetState()
- $hDC_Window = _WinAPI_GetDC($hWnd)
- $hDC_BitmapTmp = _WinAPI_CreateCompatibleDC($hDC_Window)
- $hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
- $hBitmapTmp = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iLength, $iLength)
- $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iLength, $iLength)
- $hObj_Old1 = _WinAPI_SelectObject($hDC_BitmapTmp, $hBitmapTmp)
- $hObj_Old2 = _WinAPI_SelectObject($hDC_Bitmap, $hBitmap)
- OnAutoItExitRegister("_Shutdown")
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
- GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
- GUIRegisterMsg($WM_PAINT, "_DrawBuffer")
- _WinAPI_SetBkColor($hDC_Bitmap, $iColor_Empty)
- For $iY = 0 To $iLength - 1
- For $iX = 0 To $iLength - 1
- If Random(0, 1) < 0.4 Then _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Tree)
- Next
- Next
- _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
- _BitBlt($hDC_Bitmap, $hDC_Window)
- While True
- For $iY = 0 To $iLength - 1
- For $iX = 0 To $iLength - 1
- Switch _GetPixel($hDC_BitmapTmp, $iX, $iY)
- Case $iColor_Fire
- _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Empty)
- Case $iColor_Empty
- If Random(0, 1) < $fGrowth Then _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Tree)
- Case $iColor_Tree
- For $iX_Off = -1 To 1
- For $iY_Off = -1 To 1
- If $iX_Off = 0 And $iY_Off = 0 Then ContinueLoop
- If _GetPixel($hDC_BitmapTmp, $iX + $iX_Off, $iY + $iY_Off) = $iColor_Fire Then
- _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Fire)
- ContinueLoop 3
- EndIf
- Next
- Next
- If Random(0, 1) < $fIgnition Then _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Fire)
- EndSwitch
- Next
- _BitBlt($hDC_Bitmap, $hDC_Window)
- Next
- _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
- WEnd
- Func _SetPixel(ByRef $hDC, $iX, $iY, $iColor)
- DllCall($hDll_GDI32, 'INT', 'SetPixelV', 'HWND', $hDC, 'INT', $iX, 'INT', $iY, 'DWORD', $iColor)
- EndFunc ;==>_SetPixel
- Func _GetPixel(ByRef $hDC, $iX, $iY)
- $aRet = DllCall($hDll_GDI32, 'DWORD', 'GetPixel', 'HWND', $hDC, 'INT', $iX, 'INT', $iY)
- Return $aRet[0]
- EndFunc ;==>_GetPixel
- Func _DrawBuffer()
- _BitBlt($hDC_Bitmap, $hDC_Window)
- EndFunc
- Func _BitBlt(ByRef $hDC_Source, ByRef $hDC_Target)
- DllCall($hDll_GDI32, "BOOL", "BitBlt", "HANDLE", $hDC_Target, "INT", 0, "INT", 0, "INT", $iLength, "INT", $iLength, "HANDLE", $hDC_Source, "INT", 0, "INT", 0, "DWORD", $SRCCOPY)
- EndFunc ;==>_DrawBuffer
- Func _Shutdown()
- _WinAPI_SelectObject($hDC_BitmapTmp, $hObj_Old1)
- _WinAPI_SelectObject($hDC_Bitmap, $hObj_Old2)
- _WinAPI_ReleaseDC($hWnd, $hDC_Window)
- _WinAPI_DeleteDC($hDC_BitmapTmp)
- _WinAPI_DeleteDC($hDC_Bitmap)
- _WinAPI_DeleteObject($hBitmapTmp)
- _WinAPI_DeleteObject($hBitmap)
- DllClose($hDll_GDI32)
- EndFunc ;==>_Shutdown
- Func _Close()
- Exit
- EndFunc ;==>_Close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement