Jump to content

Some of Jerome Herr's processing code samples in AutoIt


 Share

Recommended Posts

I wrote this after seeing Jerome Herr's post on Tumblr and looking at the code here. A few Google searches later, I came up with these.

#include <GDIPlus.au3>
#include <Math.au3>
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7

Opt("GUIOnEventMode", 1)

Global Const $nPI = 3.1415926535897932384626433832795
Global Const $nTWOPI = $nPI * 2
Global $iNum = 25
Global $nStep, $nSz, $nTheta
$nStep = 20
Global $iMaxRad = ($iNum - 1) * $nStep

Global $fClose = False
Global $iW = $iMaxRad, $iH = $iMaxRad
Global $hGUI = GUICreate('"Wave" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH)
GUISetOnEvent(-3, "_Exit")

_GDIPlus_Startup()
Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt)
Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 3, 2)
Global $hTimer = TimerInit()
GUISetState()

While Not $fClose
    If TimerDiff($hTimer) >= 33 Then
        $hTimer = TimerInit()
        _Draw()
        _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0)
        ConsoleWrite(TimerDiff($hTimer) & @CRLF)
    EndIf
    Sleep(33 - TimerDiff($hTimer) - 1)
WEnd

_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hCtxt)
GUIDelete()

Func _Draw()
    _GDIPlus_GraphicsClear($hGraphics, 0xFF000000)
    Local $nArcEnd, $nOffset, $nDrawOffset
    For $i = 0 To $iNum - 1
        $nSz = $i * $nStep
        $nOffset = $nTWOPI / $iNum * $i
        $nDrawOffset = $iMaxRad / 2 - $nSz / 2
        $nArcEnd = _Degree(_Map(Sin($nTheta + $nOffset), -1, 1, $nPI, $nTWOPI) - $nPI)

        _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 0, $nArcEnd, $hPen)
        _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 180, $nArcEnd, $hPen)
    Next
    $nTheta += 0.0523
    If $nTheta > $nTWOPI Then
        $nTheta = Mod($nTheta, $nTWOPI)
    EndIf
EndFunc   ;==>_Draw

Func _Exit()
    $fClose = True
EndFunc   ;==>_Exit

Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2)
    Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1))
EndFunc   ;==>_Map

Playing with hue:

#include <GDIPlus.au3>
#include <Math.au3>
#include <WinAPIGdi.au3>

;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7

Opt("GUIOnEventMode", 1)

Global Const $nPI = 3.1415926535897932384626433832795
Global Const $nTWOPI = $nPI * 2
Global $iNum = 25
Global $nStep, $nSz, $nTheta
Global $iStHue = 0
$nStep = 20
Global $iMaxRad = ($iNum - 1) * $nStep

Global $fClose = False
Global $iW = $iMaxRad, $iH = $iMaxRad
Global $hGUI = GUICreate('"Wave" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH)
GUISetOnEvent(-3, "_Exit")

_GDIPlus_Startup()
Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt)
Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 3, 2)
Global $hTimer = TimerInit()
GUISetState()

While Not $fClose
    If TimerDiff($hTimer) >= 33 Then
        $hTimer = TimerInit()
        _Draw()
        _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0)
        ConsoleWrite("Draw: " & TimerDiff($hTimer) & @CRLF)
    EndIf
    Sleep(33 - TimerDiff($hTimer) - 1)
WEnd

_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hCtxt)
GUIDelete()

Func _Draw()
    _GDIPlus_GraphicsClear($hGraphics, 0x7F000000)
    Local $nArcEnd, $nOffset, $nDrawOffset
    For $i = 0 To $iNum - 1
        $nSz = $i * $nStep
        $nOffset = $nTWOPI / $iNum * $i
        $nDrawOffset = $iMaxRad / 2 - $nSz / 2
        $nArcEnd = _Degree(_Map(Sin($nTheta + $nOffset), -1, 1, $nPI, $nTWOPI) - $nPI)

        _GDIPlus_PenSetColor($hPen, "0xFF" & Hex(_WinAPI_ColorHLSToRGB($iStHue + $i, 120, 240), 6))
        _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 0, $nArcEnd, $hPen)
        _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 180, $nArcEnd, $hPen)
    Next
    $nTheta += 0.0523
    $iStHue += 0.5
    _ModIfGreater($nTheta, $nTWOPI)
    _ModIfGreater($iStHue, 239)
EndFunc   ;==>_Draw

Func _Exit()
    $fClose = True
EndFunc   ;==>_Exit

Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2)
    Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1))
EndFunc   ;==>_Map

Func _ModIfGreater(ByRef $nVar, $nMod)
    $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar)
EndFunc

>#6 - Trunk in space

>#7Lava Lamp

>#8Wavy Thing

Edited by DatMCEyeBall

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

Wow, indeed very nice short gfx demos over there. Coooooool... :lmao: 

Have fun  :thumbsup:

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I adapted the Wavy example to AutoIt:

;original java code by Jared "BlueThen" C. -> http://www.openprocessing.org/sketch/5671
;converted to AutoIt by UEZ 2014

#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3"
#pragma compile(UPX, False)
#pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Aut2Exe\Icons\AutoIt_Main_v10_48x48_RGB-A.ico")
#pragma compile(inputboxres, False)
#AutoIt3Wrapper_Run_After=upx.exe --best --lzma "%out%"

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global $ghGDIPDll = $__g_hGDIPDll
Global Const $iW = 500, $iH = 500, $sTitle = "GDI+ Wavy / FPS: "
Global Const $hGUI = GUICreate($sTitle & "0", $iW, $iH)
GUISetState()

Global Const $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
Global Const $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp)
_GDIPlus_BitmapDispose($hBmp)
Global Const $hDC  = _WinAPI_GetDC($hGUI)
Global Const $hDC_Backbuffer  = _WinAPI_CreateCompatibleDC($hDC)
Global Const $DC_Obj = _WinAPI_SelectObject($hDC_Backbuffer, $hHBITMAP)
Global Const $hGfxCtx = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxCtx, 2)
Global Const $hBrush = _GDIPlus_BrushCreateSolid(), $hBrushL = _GDIPlus_BrushCreateSolid(0xFF555555), $hBrushR = _GDIPlus_BrushCreateSolid(0xFFAAAAAA), $hPen = _GDIPlus_PenCreate(0xFF000000), $hPath = _GDIPlus_PathCreate()
GUISetOnEvent($GUI_EVENT_Close, "_Exit")

Global Const $halfw = $iW / 2, $halfh = $iH / 2, $iSquares = 14, $iSquareshalf = $iSquares / 2, $iHeight = 40, $iSize = 17, $iSizehalf = $iSize / 2, $iCount = 4
Global $x, $y, $z, $a = 9999998, $xm, $xt, $zm, $zt, $isox1, $isoy1, $isox2, $isoy2, $isox3, $isoy3, $isox4, $isoy4, $iColor, $iFPS = 0
Global $fSpeed = 0.1, $fPhase = 0.55, $fPerspective = 0.5, $fPower = 24
Global $tPoints = DllStructCreate("float coordinates[" & $iCount * 2 & "]")
Global Const $ghGDI32Dll = DllOpen("gdi32.dll")

AdlibRegister("ShowFPS", 1000)

Do
    $a -= $fSpeed
    DllCall($__g_hGDIPDll, "int", "GdipGraphicsClear", "handle", $hGfxCtx, "dword", 0xF0101010)
    For $x = -$iSquareshalf To $iSquareshalf - 1
        For $z = -$iSquareshalf To $iSquareshalf - 1
            $y = ($fPower * Sin($fPhase * Sqrt((0 - $x) * (0 - $x) + (0 - $z) * (0 - $z)) + $a))
            $xm = $x * $iSize - $iSizehalf
            $xt = $x * $iSize + $iSizehalf
            $zm = $z * $iSize - $iSizehalf
            $zt = $z * $iSize + $iSizehalf

            $isox1 = ($xm - $zm + $halfw)
            $isoy1 = (($xm + $zm) * $fPerspective + $halfh)
            $isox2 = ($xm - $zt + $halfw)
            $isoy2 = (($xm + $zt) * $fPerspective + $halfh)
            $isox3 = ($xt - $zt + $halfw)
            $isoy3 = (($xt + $zt) * $fPerspective + $halfh)
            $isox4 = ($xt - $zm + $halfw)
            $isoy4 = (($xt + $zm) * $fPerspective + $halfh)


            ;draw left side
            $tPoints.coordinates((1)) = $isox2
            $tPoints.coordinates((2)) = $isoy2 - $y
            $tPoints.coordinates((3)) = $isox3
            $tPoints.coordinates((4)) = $isoy3 - $y
            $tPoints.coordinates((5)) = $isox3
            $tPoints.coordinates((6)) = $isoy3 + $iHeight
            $tPoints.coordinates((7)) = $isox2
            $tPoints.coordinates((8)) = $isoy2 + $iHeight
            DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath)
            DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount)
;~          DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath)
            DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrushL, "handle", $hPath)


            ;draw right side
            $tPoints.coordinates((1)) = $isox3
            $tPoints.coordinates((2)) = $isoy3 - $y
            $tPoints.coordinates((3)) = $isox4
            $tPoints.coordinates((4)) = $isoy4 - $y
            $tPoints.coordinates((5)) = $isox4
            $tPoints.coordinates((6)) = $isoy4 + $iHeight
            $tPoints.coordinates((7)) = $isox3
            $tPoints.coordinates((8)) = $isoy3 + $iHeight
            DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath)
            DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount)
;~          DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath)
            DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrushR, "handle", $hPath)


            ;draw top rectangle
            $tPoints.coordinates((1)) = $isox1
            $tPoints.coordinates((2)) = $isoy1 - $y
            $tPoints.coordinates((3)) = $isox2
            $tPoints.coordinates((4)) = $isoy2 - $y
            $tPoints.coordinates((5)) = $isox3
            $tPoints.coordinates((6)) = $isoy3 - $y
            $tPoints.coordinates((7)) = $isox4
            $tPoints.coordinates((8)) = $isoy4 - $y
            $iColor = Int((4 + $y * 0.066666) * 48)
            $iColor = $iColor < 0x00 ? 0x00 : $iColor > 0xFF ? 0xFF : $iColor
            DllCall($__g_hGDIPDll, "int", "GdipSetSolidFillColor", "handle", $hBrush, "dword", 0xFF000000 + $iColor * 0x10000 + $iColor * 0x100 + $iColor)
            DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath)
            DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount)
;~          DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath)
            DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrush, "handle", $hPath)
        Next
    Next
    DllCall($ghGDI32Dll, "bool", "BitBlt", "ptr", $hDC, "int", 0, "int", 0, "int", $iW, "int", $iH, "ptr", $hDC_Backbuffer, "int", 0, "int", 0, "dword", $SRCCOPY)
    $iFPS += 1
Until False * Sleep(10)

Func ShowFPS()
    WinSetTitle($hGUI, "", $sTitle & $iFPS)
    $iFPS = 0
EndFunc

Func _Exit()
    AdlibUnRegister("ShowFPS")
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrushL)
    _GDIPlus_BrushDispose($hBrushR)
    _GDIPlus_PenDispose($hPen)
    _WinAPI_SelectObject($hDC_Backbuffer, $DC_Obj)
    _GDIPlus_GraphicsDispose($hGfxCtx)
    _WinAPI_DeleteObject($hHBITMAP)
    _WinAPI_ReleaseDC($hGUI, $hDC)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    DllClose($ghGDI32Dll)
    Exit
EndFunc

Edit1: optimized the code a little bit - now slightly faster.

Edit2: still some more optimizations which increases the fps speed

Edit3: squeezed still a few fps

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

"Trunk in space"

#include <GDIPlus.au3>
#include <Math.au3>
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7

Opt("GUIOnEventMode", 1)

Global Const $nPI = 3.1415926535897932384626433832795
Global Const $nTWOPI = $nPI * 2

Global $iSz = 300, $iNum = 40
Global $nTheta, $nAngle, $nRad = 200

Global $fClose = False
Global $iW = 500, $iH = 500
Global $hGUI = GUICreate('"Trunk in space" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH)
GUISetOnEvent(-3, "_Exit")

_GDIPlus_Startup()
Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt)
Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 6, 2)
Global $hBrush = _GDIPlus_BrushCreateSolid()
Global $hTimer = TimerInit()
GUISetState()

While Not $fClose
    If TimerDiff($hTimer) >= 33 Then
        $hTimer = TimerInit()
        _Draw()
        _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0)
        ConsoleWrite(TimerDiff($hTimer) & @CRLF)
    EndIf
    Sleep(33 - TimerDiff($hTimer) - 1)
WEnd

_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hCtxt)
GUIDelete()

Func _Draw()
    _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)
    $nAngle = 0
    Local $nX, $nY, $nS, $nScal
    Local $iF
    For $i = 0 To $iNum - 1
        $nX = $iW / 2 - $nRad / 2 + Cos($nAngle) * $nRad
        $nY = $iH / 2.5 + Sin($nAngle) * $nRad
        $nS = _Map(Sin($nTheta + $nTWOPI / $iNum * $i * 2), -1, 1, 1, 0.7)
        $nScal = 1 - 0.03 * $i
        $iF = Int(255 / $iNum * $i)
        _GDIPlus_BrushSetSolidColor($hBrush, "0xFF" & Hex(_WinAPI_ColorHLSToRGB($iF, 100, 160), 6))
        _GDIPlus_GraphicsFillDrawEllipse($hGraphics, 0, $nY, $iSz * $nScal * $nS, $iSz * $nScal * $nS, $hBrush, $hPen)
        $nAngle -= $nPI / $iNum
    Next
    $nTheta += 0.0523
    _ModIfGreater($nTheta, $nTWOPI)
EndFunc   ;==>_Draw

Func _GDIPlus_GraphicsFillDrawEllipse($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush = 0, $hPen = 0)
    _GDIPlus_GraphicsFillEllipse($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush)
    _GDIPlus_GraphicsDrawEllipse($hGraphics, $nX, $nY, $nWidth, $nHeight, $hPen)
    Return 1
EndFunc   ;==>_GDIPlus_GraphicsFillDrawEllipse

Func _Exit()
    $fClose = True
EndFunc   ;==>_Exit

Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2)
    Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1))
EndFunc   ;==>_Map

Func _ModIfGreater(ByRef $nVar, $nMod)
    $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar)
EndFunc   ;==>_ModIfGreater

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

"Lava Lamp"

#include <GDIPlus.au3>
#include <Math.au3>
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7

Opt("GUIOnEventMode", 1)

Global Const $nPI = 3.1415926535897932384626433832795
Global Const $nTWOPI = $nPI * 2

Global $iNum = 125
Global $aiMaxSize[$iNum]
Global $anOffset[$iNum]
Global $nTheta, $nSz, $nX
Global $aiPalette[] = [0x64F58F12, 0x640B9EE7, 0x644EA731, 0x64F4D910, 0x64F334E3]

For $i = 0 To $iNum - 1
    $aiMaxSize[$i] = Random(50, 120, 1)
    $anOffset[$i] = Random(0, $nTWOPI)
Next

Global $fClose = False
Global $iW = 500, $iH = 500
Global $hGUI = GUICreate('"Lava Lamp" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH)
GUISetOnEvent(-3, "_Exit")

_GDIPlus_Startup()
Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt)
Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
Global $hBrush = _GDIPlus_BrushCreateSolid()
Global $hTimer = TimerInit()
GUISetState()

While Not $fClose
    If TimerDiff($hTimer) >= 33 Then
        $hTimer = TimerInit()
        _Draw()
        _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0)
        ConsoleWrite(TimerDiff($hTimer) & @CRLF)
    EndIf
    Sleep(33 - TimerDiff($hTimer) - 1)
WEnd

_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hCtxt)
GUIDelete()

Func _Draw()
    _GDIPlus_GraphicsClear($hGraphics, 0xFF202020)

    For $i = 0 To $iNum - 1
        _GDIPlus_BrushSetSolidColor($hBrush, $aiPalette[Mod($i, 5)])
        $nX = _Map(Sin($nTheta + $anOffset[$i]), -1, 1, 150, 350 - $aiMaxSize[$i])
        _GDIPlus_GraphicsFillRect($hGraphics, $nX, $iH / $iNum * $i, $aiMaxSize[$i], 20, $hBrush)
    Next

    $nTheta += 0.0523 / 2
    _ModIfGreater($nTheta, $nTWOPI)
EndFunc   ;==>_Draw

Func _Exit()
    $fClose = True
EndFunc   ;==>_Exit

Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2)
    Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1))
EndFunc   ;==>_Map

Func _ModIfGreater(ByRef $nVar, $nMod)
    $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar)
EndFunc   ;==>_ModIfGreater

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

"Wavy Thing"

#include <GDIPlus.au3>
#include <Math.au3>
;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7

Opt("GUIOnEventMode", 1)

Global Const $nPI = 3.1415926535897932384626433832795
Global Const $nTWOPI = $nPI * 2

Global $iNum = 25
Global $anPosX[$iNum]
Global $nUnit, $nTheta, $nX, $nSzX, $nSzY

Global $fClose = False
Global $iW = 500, $iH = 300
Global $hGUI = GUICreate('"Wavy thing" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH)
GUISetBkColor(0)
GUISetOnEvent(-3, "_Exit")

$nUnit = ($iW - 50) / $iNum

_GDIPlus_Startup()
Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt)
Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFCD300)
Global $hPen = _GDIPlus_PenCreate(0xFF777777, 1)
Global $hTimer = TimerInit()
GUISetState()

While Not $fClose
    If TimerDiff($hTimer) >= 33 Then
        $hTimer = TimerInit()
        _Draw()
        _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0)
        ConsoleWrite(TimerDiff($hTimer) & @CRLF)
    EndIf
    Sleep(33 - TimerDiff($hTimer) - 1)
WEnd

_GDIPlus_PenDispose($hPen)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hCtxt)
GUIDelete()

Func _Draw()
    _GDIPlus_GraphicsClear($hGraphics, 0xBE000000)

    For $i = 0 To $iNum - 1
        $nSzX = _Map(Sin($nTheta + ($nTWOPI / $iNum) * $i), -1, 1, 5, 10)
        $nSzY = _Map(Sin($nTheta + ($nPI / $iNum) * $i), -1, 1, 30, $iH / 1.2)
        $nX = _Map(Sin($nTheta + ($nPI / $iNum / 2) * $i), -1, 1, $i * $nUnit, $iW / 2)

        _GDIPlus_GraphicsFillDrawRect($hGraphics, $nX + 25, _CenterPoint($nSzY, $iH), $nSzX, $nSzY, $hBrush, $hPen)
    Next

    $nTheta += 0.0523
    _ModIfGreater($nTheta, $nTWOPI)
EndFunc   ;==>_Draw

Func _Exit()
    $fClose = True
EndFunc   ;==>_Exit

Func _GDIPlus_GraphicsFillDrawRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush = 0, $hPen = 0)
    _GDIPlus_GraphicsFillRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $hBrush)
    _GDIPlus_GraphicsDrawRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $hPen)
    Return 1
EndFunc   ;==>_GDIPlus_GraphicsFillDrawRect

Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2)
    Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1))
EndFunc   ;==>_Map

Func _ModIfGreater(ByRef $nVar, $nMod)
    $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar)
EndFunc   ;==>_ModIfGreater

Func _CenterPoint($iCur, $iTotal)
    Return $iTotal / 2 - $iCur / 2
EndFunc   ;==>_CenterPoint

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

Thanks for the further examples!  :thumbsup:

Btw, http://www.openprocessing.org/ are many awesome gfx examples   :lmao:  Thx for the link!

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I'll have more up later today (some other examples that are not Jerome's).

Even more when I convert the S3d UDF to C++

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...