RosettaCode Sammelthread

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Forest_fire
    Beteiligte: name22
    Skript:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $hDll_GDI32 = DllOpen("gdi32.dll")

    [/autoit] [autoit][/autoit] [autoit]

    Global $iLength = 100
    Global $iColor_Tree = 0x00FF00, $iColor_Fire = 0x0000FF, $iColor_Empty = 0 ;Colors
    Global $fIgnition = 0.0001, $fGrowth = 0.01, $fTree = 0.55 ;Propabilities

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Forest Fire", $iLength, $iLength)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ;I use a second bitmap to contain the current pixel-states instead of a 2D-Array, sue me!
    $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)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Shutdown")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
    GUIRegisterMsg($WM_PAINT, "_DrawBuffer")

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetBkColor($hDC_Bitmap, $iColor_Empty)

    [/autoit] [autoit][/autoit] [autoit]

    For $iY = 0 To $iLength - 1
    For $iX = 0 To $iLength - 1
    If Random(0, 1) < $fTree Then _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Tree)
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
    _BitBlt($hDC_Bitmap, $hDC_Window)

    [/autoit] [autoit][/autoit] [autoit]

    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
    Next
    _BitBlt($hDC_Bitmap, $hDC_Window)
    _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetPixel(ByRef $hDC, $iX, $iY, $iColor)
    DllCall($hDll_GDI32, 'INT', 'SetPixelV', 'HWND', $hDC, 'INT', $iX, 'INT', $iY, 'DWORD', $iColor)
    EndFunc ;==>_SetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetPixel(ByRef $hDC, $iX, $iY)
    $aRet = DllCall($hDll_GDI32, 'DWORD', 'GetPixel', 'HWND', $hDC, 'INT', $iX, 'INT', $iY)
    Return $aRet[0]
    EndFunc ;==>_GetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawBuffer()
    _BitBlt($hDC_Bitmap, $hDC_Window)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    DllClose($hDll_GDI32)
    EndFunc ;==>_Shutdown

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    Exit
    EndFunc ;==>_Close

    [/autoit]

    Screenshots:

    Spoiler anzeigen
  • minx Danke. Ich finde die Moore-Neighbourhood lässt das ganze ein wenig.. rechteckig aussehen, aber es sollte mit den Vorgaben des Wikis übereinstimmen. Im Wikipedia Artikel ist allerdings von einer Neumann-Neighborhood die Rede ?( .

    Edit: Was findet ihr "besser"/"cooler", zeilenweises update der GUI oder Update nach jeder vollständigen Iteration?

    1. Variante (Original)
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $hDll_GDI32 = DllOpen("gdi32.dll")

    [/autoit] [autoit][/autoit] [autoit]

    Global $iLength = 100
    Global $iColor_Tree = 0x00FF00, $iColor_Fire = 0x0000FF, $iColor_Empty = 0 ;Colors
    Global $fIgnition = 0.0001, $fGrowth = 0.01, $fTree = 0.55 ;Propabilities

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Forest Fire", $iLength, $iLength)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ;I use a second bitmap to contain the current pixel-states instead of a 2D-Array, sue me!
    $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)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Shutdown")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
    GUIRegisterMsg($WM_PAINT, "_DrawBuffer")

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetBkColor($hDC_Bitmap, $iColor_Empty)

    [/autoit] [autoit][/autoit] [autoit]

    For $iY = 0 To $iLength - 1
    For $iX = 0 To $iLength - 1
    If Random(0, 1) < $fTree Then _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Tree)
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
    _BitBlt($hDC_Bitmap, $hDC_Window)

    [/autoit] [autoit][/autoit] [autoit]

    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
    Next
    _BitBlt($hDC_Bitmap, $hDC_Window)
    _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetPixel(ByRef $hDC, $iX, $iY, $iColor)
    DllCall($hDll_GDI32, 'INT', 'SetPixelV', 'HWND', $hDC, 'INT', $iX, 'INT', $iY, 'DWORD', $iColor)
    EndFunc ;==>_SetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetPixel(ByRef $hDC, $iX, $iY)
    $aRet = DllCall($hDll_GDI32, 'DWORD', 'GetPixel', 'HWND', $hDC, 'INT', $iX, 'INT', $iY)
    Return $aRet[0]
    EndFunc ;==>_GetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawBuffer()
    _BitBlt($hDC_Bitmap, $hDC_Window)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    DllClose($hDll_GDI32)
    EndFunc ;==>_Shutdown

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    Exit
    EndFunc ;==>_Close

    [/autoit]
    2. Variante (Zeilenweise)
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $hDll_GDI32 = DllOpen("gdi32.dll")

    [/autoit] [autoit][/autoit] [autoit]

    Global $iLength = 100
    Global $iColor_Tree = 0x00FF00, $iColor_Fire = 0x0000FF, $iColor_Empty = 0 ;Colors
    Global $fIgnition = 0.0001, $fGrowth = 0.01, $fTree = 0.55 ;Propabilities

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Forest Fire", $iLength, $iLength)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    ;I use a second bitmap to contain the current pixel-states instead of a 2D-Array, sue me!
    $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)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Shutdown")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
    GUIRegisterMsg($WM_PAINT, "_DrawBuffer")

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetBkColor($hDC_Bitmap, $iColor_Empty)

    [/autoit] [autoit][/autoit] [autoit]

    For $iY = 0 To $iLength - 1
    For $iX = 0 To $iLength - 1
    If Random(0, 1) < $fTree Then _SetPixel($hDC_Bitmap, $iX, $iY, $iColor_Tree)
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _BitBlt($hDC_Bitmap, $hDC_BitmapTmp)
    _BitBlt($hDC_Bitmap, $hDC_Window)

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetPixel(ByRef $hDC, $iX, $iY, $iColor)
    DllCall($hDll_GDI32, 'INT', 'SetPixelV', 'HWND', $hDC, 'INT', $iX, 'INT', $iY, 'DWORD', $iColor)
    EndFunc ;==>_SetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetPixel(ByRef $hDC, $iX, $iY)
    $aRet = DllCall($hDll_GDI32, 'DWORD', 'GetPixel', 'HWND', $hDC, 'INT', $iX, 'INT', $iY)
    Return $aRet[0]
    EndFunc ;==>_GetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawBuffer()
    _BitBlt($hDC_Bitmap, $hDC_Window)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    DllClose($hDll_GDI32)
    EndFunc ;==>_Shutdown

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    Exit
    EndFunc ;==>_Close

    [/autoit]
  • Spoiler anzeigen


    Das Problem ist, dass bei Q(30) der Rekursionslevel selbst auch so ungefähr bei 30 liegt, also noch sehr niedrig. Daraus folgt, dass man wahrscheinlich mehrere Stunden auf das Ergebnis warten könnte, nur um dann einen Rekursionsfehler zu erhalten...

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Substring/Top_and_tail
    Beteiligte: teamnoobPDB
    Script:

    Spoiler anzeigen
    [autoit]

    $Str = "upraisers"

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite($Str & @CRLF); Full String
    ConsoleWrite(StringTrimRight($Str,1) & @CRLF); Removed last char
    ConsoleWrite(StringTrimLeft($Str,1) & @CRLF); Removed first char
    ConsoleWrite(StringTrimRight($Str,2) & @CRLF); Removed last 2 chars
    ConsoleWrite(StringTrimLeft($Str,2) & @CRLF); Removed first 2 char

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Animate_a_pendulum
    Beteiligte: name22
    Skript:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hWnd, $hDC_Window, $hDC_Bitmap, $hBitmap, $hOldObj, $hGraphics, _
    $hBrush_Ball, $hPen_String

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $fPi = ACos(-1)
    Global Const $iWidth = 400, $iHeight = 250 ;GUI Size
    Global Const $iRadius_Ball = 10, $iWidth_String = 2 ;Object Sizes
    Global Const $iColor_BG = 0xFFFFFFFF, $iColor_String = 0xFF000000, $iColor_Ball = 0xFF0000FF ;Colors
    Global Const $iLength = 180, $fGravity = 0.1 ;Physical Properties

    [/autoit] [autoit][/autoit] [autoit]

    Global $fAngle = $fPi / 2, $fSpeed = 0, $fAccel = 0, $fX_Ball, $fY_Ball

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Pendulum", $iWidth, $iHeight)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Shutdown")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
    GUIRegisterMsg($WM_PAINT, "_DrawBuffer")

    [/autoit] [autoit][/autoit] [autoit]

    $hDC_Window = _WinAPI_GetDC($hWnd)
    $hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iWidth, $iHeight)
    $hOldObj = _WinAPI_SelectObject($hDC_Bitmap, $hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)

    [/autoit] [autoit][/autoit] [autoit]

    $hBrush_Ball = _GDIPlus_BrushCreateSolid($iColor_Ball)
    $hPen_String = _GDIPlus_PenCreate($iColor_String, $iWidth_String)

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    _GDIPlus_GraphicsClear($hGraphics, $iColor_BG)
    $fAccel = -$fGravity / $iLength * Sin($fAngle)
    $fSpeed += $fAccel
    $fAngle += $fSpeed
    $fX_Ball = Cos($fAngle + $fPi / 2) * $iLength + $iWidth / 2
    $fY_Ball = Sin($fAngle + $fPi / 2) * $iLength + 50
    _GDIPlus_GraphicsDrawLine($hGraphics, $iWidth / 2, 50, $fX_Ball, $fY_Ball, $hPen_String)
    _GDIPlus_GraphicsFillEllipse($hGraphics, $fX_Ball - $iRadius_Ball, $fY_Ball - $iRadius_Ball, $iRadius_Ball * 2, $iRadius_Ball * 2, $hBrush_Ball)
    _WinAPI_BitBlt($hDC_Window, 0, 0, $iWidth, $iHeight, $hDC_Bitmap, 0, 0, $SRCCOPY)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawBuffer()
    _WinAPI_BitBlt($hDC_Window, 0, 0, $iWidth, $iHeight, $hDC_Bitmap, 0, 0, $SRCCOPY)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Shutdown()
    _WinAPI_SelectObject($hDC_Bitmap, $hOldObj)
    _WinAPI_ReleaseDC($hWnd, $hDC_Window)
    _WinAPI_DeleteDC($hDC_Bitmap)
    _WinAPI_DeleteObject($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BrushDispose($hBrush_Ball)
    _GDIPlus_PenDispose($hPen_String)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    Exit
    EndFunc

    [/autoit]

    Screenshot:

    Spoiler anzeigen


    Die Simulation folgt keiner sinnvollen/genauen Zeitachse. Wenn ich da mein standardmäßiges FPS management mit reingepackt hätte, wäre es irgendwie zu kompliziert finde ich.

  • #20 (Überarbeitet wegen _FileCountLines und der Verwendung von FileReadLine in einer Schleife mit Erhöhung des line Parameters.)

    Spoiler anzeigen
    [autoit]

    Local $File, $Line

    [/autoit] [autoit][/autoit] [autoit]

    $File = FileOpen("file.txt")
    Do
    $Line = FileReadLine($File)
    If @error Then ExitLoop
    ConsoleWrite($Line & @CRLF)
    Until False
    FileClose($File)

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Keyboard_macros
    Beteiligte: teamnoobPDB
    Skript:

    Spoiler anzeigen
    [autoit]

    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $Pressed = 0

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ENTER}","_Enter"); Set ENTER as application-specific Hotkey

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Sleep(10)
    Until $Pressed = 1

    [/autoit] [autoit][/autoit] [autoit]

    Func _Enter()
    MsgBox(64,"HotKey","You Pressed ENTER" & @CRLF & "set as application-specific HotKey.")
    $Pressed = 1
    EndFunc

    [/autoit]
  • _IsPressed hat nichts mit HotKeys zu tun und setzt auch keinen "Systemweiten Hotkey". _IsPressed prüft, ob (allein) im geprüften Zeitpunkt ein bestimmter Input zu verzeichnen war. Das ist kein HotKey.

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/GUI_enabl…ing_of_controls
    Beteiligte: teamnoobPDB
    Skript:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate("MyGui",300,100)

    [/autoit] [autoit][/autoit] [autoit]

    $hInput = GUICtrlCreateInput("0",10,10,280,20)
    $hAdd = GUICtrlCreateButton("Increment",10,40,130,30)
    $hDel = GUICtrlCreateButton("Decrement",160,40,130,30)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(10)
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $hAdd
    $Input = Int(GUICtrlRead($hInput))
    If $Input < 10 Then
    $Input += 1
    EndIf
    If $Input <> 0 Then
    GUICtrlSetState($hInput,$GUI_DISABLE)
    Else
    GUICtrlSetState($hInput,$GUI_ENABLE)
    EndIf
    GUICtrlSetData($hInput,$Input)
    Case $hDel
    $Input = Int(GUICtrlRead($hInput))
    If $Input > 0 Then
    $Input -= 1
    EndIf
    If $Input <> 0 Then
    GUICtrlSetState($hInput,$GUI_DISABLE)
    Else
    GUICtrlSetState($hInput,$GUI_ENABLE)
    EndIf
    GUICtrlSetData($hInput,$Input)
    EndSwitch
    WEnd

    [/autoit]
  • Zitat

    Hat jemand eine Idee, warum James Skript keinen AutoIt-Error hervorruft?
    Schon ab Q(30) geht fast nichts mehr.

    habe mal den Rekursionslevel und die Gesamtanzahl der Funktionsaufrufe protokolliert.

    Spoiler anzeigen
    [autoit]

    Global $r = 0, $v = 0

    [/autoit] [autoit][/autoit] [autoit]

    ;~ For $n = 1 To 20
    ;~ msgbox(0,0,"Q(" & $n & ") = " & Q($n) & @CRLF,1)
    ;~ Next
    MsgBox(0, 0, "Q(1000) = " & Q(30) & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Func Q($n)
    $v += 1 ;anzahl gesamt aufrufe
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $v = ' & $v & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    $r += 1 ;rekursionstiefe
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $r = ' & $r & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

    [/autoit] [autoit][/autoit] [autoit]

    If ($n = 1) Or ($n = 2) Then
    $r -= 1
    Return 1
    EndIf
    $t = Q($n - Q($n - 1)) + Q($n - Q($n - 2))
    $r -= 1
    Return $t
    EndFunc

    [/autoit]


    Die Rekursionstiefe ist imho nicht das Problem, die bleibt im Rahmen, aber so wie ich das sehe, wird bei jedem Funktionsaufruf für die Locals jeweils neu Speicher angefordert, das sieht man schön im Taskmanager bzw Debugger, jede Sekunde werden 2 zusätzliche MB "verbraten"
    Bei höheren Startwerten bspw Q(200) bekomme ich somit einen AutoIterror wg Speicherüberlauf.

  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Entropy
    Beteiligte: James1337
    Skript:

    Spoiler anzeigen
    [autoit]

    ConsoleWrite(ShannonEntropy("1223334444") & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Func ShannonEntropy($s)
    Local $l = StringLen($s)
    Local $f[256], $i
    For $i = 0x00 To 0xFF
    $f[$i] = 0
    Next
    For $i = 1 To $l
    $f[Asc(StringMid($s, $i, 1))] += 1
    Next
    Local $e = 0
    For $i = 0x00 To 0xFF
    If ($f[$i] > 0) Then
    $e -= ($f[$i]/$l) * Log($f[$i]/$l)/Log(2)
    EndIf
    Next
    Return $e
    EndFunc

    [/autoit]
  • Art: Neu-Implementierung
    Task: http://rosettacode.org/wiki/Greatest_subsequential_sum
    Beteiligte: TheLuBu
    Skript:

    Spoiler anzeigen
    [autoit]

    Local $iArray[11] = [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]
    GREAT_SUB($iArray)
    Local $iArray[5] = [-1, -2, -3, -4, -5]
    GREAT_SUB($iArray)
    Local $iArray[15] = [7, -6, -8, 5, -2, -6, 7, 4, 8, -9, -3, 2, 6, -4, -6]
    GREAT_SUB($iArray)

    [/autoit] [autoit][/autoit] [autoit]

    Func GREAT_SUB($iArray)
    Local $iSUM = 0, $iBEGIN_MAX = 0, $iEND_MAX = -1, $iMAX_SUM = 0
    For $i = 0 To UBound($iArray) -1
    $iSUM = 0
    For $k = $i To UBound($iArray) -1
    $iSUM += $iArray[$k]
    If $iSUM > $iMAX_SUM Then
    $iMAX_SUM = $iSUM
    $iEND_MAX = $k
    $iBEGIN_MAX = $i
    EndIf
    Next
    Next
    ConsoleWrite("Array: [")
    For $i = 0 To UBound($iArray) -1
    If $iArray[$i] > 0 THen ConsoleWrite("+")
    ConsoleWrite($iArray[$i])
    If $i <> UBound($iArray) -1 Then ConsoleWrite(",")
    Next
    ConsoleWrite("]"&@CRLF&"+>Maximal subsequence: [")
    $iSUM = 0
    For $i = $iBEGIN_MAX To $iEND_MAX
    $iSUM += $iArray[$i]
    If $iArray[$i] > 0 THen ConsoleWrite("+")
    ConsoleWrite($iArray[$i])
    If $i <> $iEND_MAX Then ConsoleWrite(",")
    Next
    ConsoleWrite("]"&@CRLF&"!>SUM of subsequence: "&$iSUM & @CRLF)
    EndFunc

    [/autoit]