Tạo sở thú trên màn hình với UDF GIFAnimation của ngôn ngữ lập trình Autoit
Thư viện GIFAnimation.au3
Chim:
#include <WindowsConstants.au3>#include <WinAPI.au3>#include "GIFAnimation.au3"Opt("GUICloseOnESC", 1); ESC to exit
Opt("MustDeclareVars", 1)
Opt("TrayMenuMode", 3)
TraySetToolTip("Flying Birds")
Global $iExit = TrayCreateItem("Exit")
TraySetState()
TrayTip("Exit", "Exit via tray menu", 5, 1)
Global $sTempFolder = @ScriptDir & "\GIFS"
DirCreate($sTempFolder)
Global $Images[9] = [ _
"eagle2.gif", _
"eagle1.gif", _
"eagle2.gif", _
"swan-flying.gif", _
"swan-flying1.gif", _
"goose_flying.gif", _
"gooses_flying.gif", _
"flamingo.gif", _
"Crow_Right.gif" _
]
For $i = 0 to UBound($Images) -1
If Not FileExists($sTempFolder & "\" & $Images[$i]) Then
TrayTip("Download " & $Images[$i], "Please wait...", 0)
InetGet("http://users.telenet.be/GreenCan/AutoIt/Images/" & $Images[$i], $sTempFolder & "\" & $Images[$i])
TrayTip("", "", 0)
EndIf
If Not FileExists($sTempFolder & "\" & $Images[$i]) Then MsgBox(262192, "Download", $Images[$i] & " Download failed!")
Next
Global $SM_VIRTUALWIDTH = 78
Global $VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
Global $sFile = $sTempFolder & "\" & $Images[0]
; Get dimension of the GIF
Global $aGIFDimension = _GIF_GetDimension($sFile)
; Make GUI
Global $hGui = GUICreate("GIF Animation", $aGIFDimension[0], $aGIFDimension[1], -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
; GIF job
Global $hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
GUICtrlSetTip(-1, "ESC to exit")
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
GUISetState()
Global $fh = -50, $fv = 0, $iHoldFL = 0, $bDown = 1, $iImage = 0, $ilevel = Random(50,150,1), $ilevelIncrement
If $ilevel > 75 Then
$ilevelIncrement = 6
Else
$ilevelIncrement = 3
EndIf
; Loop till end
While 1
If TrayGetMsg() = $iExit Then Exit
$fh += $ilevelIncrement
If $iHoldFL < 50 Then
$iHoldFL += 1
sleep(1)
Else
If $bDown Then
$fv += $ilevelIncrement/5 ;0.2
sleep(1)
Else
$fv -= $ilevelIncrement/5 ;0.2
sleep(2)
EndIf
EndIf
If $fv <0 Or $fv > $ilevel Then
If $bDown Then
$bDown = False
$fv = $ilevel
$iHoldFL = 0
Else
$bDown = True
$fv = 0
$iHoldFL = 0
EndIf
EndIf
If $fh > $VirtualDesktopWidth+50 Then
$fh = -500
$iImage += 1
If $iImage > UBound($Images)-1 Then $iImage = 0
$sFile = $sTempFolder & "\" & $Images[$iImage]
; delete current gif
_GIF_DeleteGIF($hGIF)
; delete GUI
GUIDelete($hGui)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; Make NEW GUI
$hGui = GUICreate("GIF Animation", $aGIFDimension[0], $aGIFDimension[1], -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
GUICtrlSetTip(-1, "ESC to exit")
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
GUISetState()
$ilevel = Random(50,150,1)
If $ilevel > 75 Then
$ilevelIncrement = 6
Else
$ilevelIncrement = 3
EndIf
EndIf
WinMove($hGUI,"", $fh, $fv)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
Ếch
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include "GIFAnimation.au3"
Opt("GUICloseOnESC", 1); ESC to exit
Opt("MustDeclareVars", 1)
Opt("TrayMenuMode", 3)
TraySetToolTip("Crawling Frog")
Global $iExit = TrayCreateItem("Exit")
TraySetState()
TrayTip("Exit", "Exit via tray menu", 5, 1)
Global $sTempFolder = @ScriptDir & "\GIFS"
DirCreate($sTempFolder)
Global $Images[2] = [ _
"Frog_crawling_L2R.gif", _
"Frog_crawling_R2L.gif" _
]
For $i = 0 to UBound($Images) -1
;~ ConsoleWrite($sTempFolder & @CR)
;~ Exit
If Not FileExists($sTempFolder & "\" & $Images[$i]) Then
TrayTip("Download " & $Images[$i], "Please wait...", 0)
InetGet("http://users.telenet.be/GreenCan/AutoIt/Images/" & $Images[$i], $sTempFolder & "\" & $Images[$i])
TrayTip("", "", 0)
EndIf
If Not FileExists($sTempFolder & "\" & $Images[$i]) Then MsgBox(262192, "Download", $Images[$i] & " Download failed!")
Next
Global $SM_VIRTUALWIDTH = 78
Global $VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
Global $sFile = $sTempFolder & "\" & $Images[0]
; Get dimension of the GIF
Global $aGIFDimension = _GIF_GetDimension($sFile)
; Make GUI
Global $hGui = GUICreate("GIF Animation", $aGIFDimension[0], $aGIFDimension[1], -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
; GIF job
Global $hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
GUISetState()
Global $fh = -500, $iHoldFL = 0, $bDown = 1, $iImage = 0, $fv = Random(-200,@DesktopHeight - 100,1)
; Loop till end
While 1
If TrayGetMsg() = $iExit Then Exit
;~ If GUIGetMsg() = - 3 Then Exit
If $iImage = 0 Then
$fh += 1.5
Else
$fh -= 1.5
EndIf
$fv += 0.2
If ($iImage = 0 And $fh > $VirtualDesktopWidth+50 Or $fv >@DesktopHeight+50) Or ($iImage = 1 And $fh < -500 Or $fv >@DesktopHeight+50) Then
$iImage += 1
If $iImage > UBound($Images)-1 Then $iImage = 0
If $iImage = 0 Then
$fh = - 500
Else
$fh = $VirtualDesktopWidth + 500
EndIf
$fv = Random(-200,@DesktopHeight - 100,1)
$sFile = $sTempFolder & "\" & $Images[$iImage]
; delete current gif
_GIF_DeleteGIF($hGIF)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
GUISetState()
EndIf
WinMove($hGUI,"", $fh, $fv)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
Báo
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include "GIFAnimation.au3"
;Opt("GUICloseOnESC", 1); ESC to exit
Opt("MustDeclareVars", 1)
Opt("TrayMenuMode", 3)
TraySetToolTip("Cheetah Run")
Global $iExit = TrayCreateItem("Quit")
#===============================================================
; If $bDebug is True, pause between animal appearing will be randomly increased
Global $bDebug = False
; If $bTiger is True then an additional script will be launch to display the walking tiger
Global $bTiger = True
#===============================================================
TraySetState()
TrayTip("Quit", "Exit via tray menu", 5, 1)
Global $sTempFolder = @ScriptDir & "\GIFS"
DirCreate($sTempFolder)
Global $Images[4] = [ _
"CheetahRun2_L2R.GIF", _
"CheetahRun2_R2L.GIF", _
"CheetahRun_L2R.GIF", _
"CheetahRun_R2L.GIF" _
]
Global $StaticImages[2] = [ _
"CheetahSits_R2L.GIF", _
"CheetahSits_L2R.GIF" _
]
For $i = 0 to UBound($Images) -1
;~ ConsoleWrite($sTempFolder & @CR)
;~ Exit
If Not FileExists($sTempFolder & "\" & $Images[$i]) Then
TrayTip("Download " & $Images[$i], "Please wait...", 0)
InetGet("http://users.telenet.be/GreenCan/AutoIt/Images/" & $Images[$i], $sTempFolder & "\" & $Images[$i])
TrayTip("", "", 0)
EndIf
If Not FileExists($sTempFolder & "\" & $Images[$i]) Then MsgBox(262192, "Download", $Images[$i] & " Download failed!")
Next
For $i = 0 to UBound($StaticImages) -1
If Not FileExists($sTempFolder & "\" & $StaticImages[$i]) Then
TrayTip("Download " & $StaticImages[$i], "Please wait...", 0)
InetGet("http://users.telenet.be/GreenCan/AutoIt/Images/" & $StaticImages[$i], $sTempFolder & "\" & $StaticImages[$i])
TrayTip("", "", 0)
EndIf
If Not FileExists($sTempFolder & "\" & $StaticImages[$i]) Then MsgBox(262192, "Download", $StaticImages[$i] & " Download failed!")
Next
Global $SM_VIRTUALWIDTH = 78
Global $VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
Global $sFile = $sTempFolder & "\" & $Images[0]
; Get dimension of the GIF
Global $aGIFDimension = _GIF_GetDimension($sFile)
; Make GUI
Global $hGui = GUICreate("GIF Animation", $aGIFDimension[0], $aGIFDimension[1], -1000, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
; GIF job
Global $hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
GUISetState()
Global $fh = -500, $iHoldFL = 0, $bDown = 1, $iImage = 0, $fv = Random(0,@DesktopHeight - 100,1), _
$PassStatic1 = False, $PassStatic2 = False, $fhRandom1 = Random(300,$VirtualDesktopWidth - 100,1), $fhRandom2 = Random(100,$VirtualDesktopWidth - 300,1)
; Loop till end
While 1
If TrayGetMsg() = $iExit Then Quit()
;~ If GUIGetMsg() = - 3 Then Exit
If $iImage = 0 Then ; left to right
$fh += 15
ElseIf $iImage = 1 Then ; right to left
$fh -= 15
ElseIf $iImage = 2 Then ; left to right
$fh += 12
$fv += 3
If $fh > $fhRandom1 and Not $PassStatic1 Then
; show sitting Cheetah
$fh += 48
$fv += 12
$PassStatic1 = True
$sFile = $sTempFolder & "\" & $StaticImages[1]
; delete current gif
_GIF_DeleteGIF($hGIF)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; move GUI to avoid transparent glitch
WinMove($hGUI,"", -1000, $fv, $aGIFDimension[0], $aGIFDimension[1])
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
WinMove($hGUI,"", $fh, $fv, $aGIFDimension[0], $aGIFDimension[1])
GUISetState()
; pause random between 5 and 10 seconds
For $i = 1 to Random(50,100,1)
If TrayGetMsg() = $iExit Then Quit()
Sleep(100)
Next
; continue with running Cheetah
$fh += 0; 42
$fv += 12; 24
$sFile = $sTempFolder & "\" & $Images[$iImage]
; delete current gif
_GIF_DeleteGIF($hGIF)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; move GUI to avoid transparent glitch
WinMove($hGUI,"", -1000, $fv, $aGIFDimension[0], $aGIFDimension[1])
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
WinMove($hGUI,"", $fh, $fv, $aGIFDimension[0], $aGIFDimension[1])
GUISetState()
EndIf
ElseIf $iImage = 3 Then ; right to left
$fh -= 12
$fv += 3
If $fh < $fhRandom2 and Not $PassStatic2 Then
; show sitting Cheetah
$fh -= 24
$fv += 12
$PassStatic2 = True
$sFile = $sTempFolder & "\" & $StaticImages[0]
; delete current gif
_GIF_DeleteGIF($hGIF)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; move GUI to avoid transparent glitch
WinMove($hGUI,"", -1000, $fv, $aGIFDimension[0], $aGIFDimension[1])
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
WinMove($hGUI,"", $fh, $fv, $aGIFDimension[0], $aGIFDimension[1])
GUISetState()
; pause random between 5 and 10 seconds
For $i = 1 to Random(50,100,1)
If TrayGetMsg() = $iExit Then Quit()
Sleep(100)
Next
; continue with running Cheetah
$fh -= 96; 108
$fv += 12; 27
$sFile = $sTempFolder & "\" & $Images[$iImage]
; delete current gif
_GIF_DeleteGIF($hGIF)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; move GUI to avoid transparent glitch
WinMove($hGUI,"", -1000, $fv, $aGIFDimension[0], $aGIFDimension[1])
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; Show it
WinMove($hGUI,"", $fh, $fv, $aGIFDimension[0], $aGIFDimension[1])
GUISetState()
EndIf
EndIf
Sleep(2)
If ($iImage = 0 Or $iImage = 2 And $fh > $VirtualDesktopWidth+50 Or $fv >@DesktopHeight+50) _
Or ($iImage = 1 Or $iImage = 3 And $fh < -500 Or $fv >@DesktopHeight+50) Then
$iImage += 1
If $iImage > UBound($Images)-1 Then $iImage = 0
If $iImage = 0 Then
$fhRandom1 = Random(300,$VirtualDesktopWidth - 100,1)
$fhRandom2 = Random(100,$VirtualDesktopWidth - 300,1)
If Random(1,2,1)= 1 Then $PassStatic1 = False ; 2 will not stop cheetah
If Random(1,2,1)= 1 Then $PassStatic2 = False ; 2 will not stop cheetah
;~ ConsoleWrite(@ScriptLineNumber & " $fhRandom1:" & $fhRandom1 & " $fhRandom2:" & $fhRandom2 & " " & $PassStatic1 & " " & $PassStatic2 & @CR)
EndIf
If $iImage = 0 Then
$fh = - 500
$fv = Random(0,@DesktopHeight - 100,1)
ElseIf $iImage = 1 Then
$fh = $VirtualDesktopWidth + 500
$fv = Random(0,@DesktopHeight - 100,1)
ElseIf $iImage = 2 Then
$fh = - 500
$fv = Random(0,200,1)
Else
$fh = $VirtualDesktopWidth + 500
$fv = Random(0,200,1)
;~ ConsoleWrite(@ScriptLineNumber & " " & $fv & @CR)
EndIf
$sFile = $sTempFolder & "\" & $Images[$iImage]
; delete current gif
_GIF_DeleteGIF($hGIF)
; Get dimension of the GIF
$aGIFDimension = _GIF_GetDimension($sFile)
; New GIF
$hGIF = _GUICtrlCreateGIF($sFile, "", 0, 0)
; Make GUI transparent
GUISetBkColor(345) ; some random color
_WinAPI_SetLayeredWindowAttributes($hGui, 345, 255) ; making the GUI transparent
_WinAPI_SetParent($hGui, 0)
; sleep between 0.1 and 100 seconds, but check for exit
_ReduceMemory()
For $i = 1 to Random(1,1000,1)
If TrayGetMsg() = $iExit Then Quit()
If $bDebug Then ExitLoop
Sleep(100)
Next
; Show it
GUISetState()
WinMove($hGUI,"", $fh, $fv, $aGIFDimension[0], $aGIFDimension[1])
Else
WinMove($hGUI,"", $fh, $fv)
EndIf
WEnd
#FUNCTION# ==============================================================
Func _ReduceMemory()
Local $dll_mem = DllOpen(@SystemDir & "\psapi.dll")
Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1)
If @error Then Return SetError(@error, @error, 1)
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory
#FUNCTION# ==============================================================
Func Quit()
If $bTiger Then ProcessClose ($Pid )
Exit
EndFunc ;==>Quit