Animierte prozedurale Landschaft aus impliziten Gleichungen

  • Andy hat gestern Quick'n'Dirty das hier in AutoIt umgesetzt.

    Was hab ich noch verbessert:

    • Bitmap Frames statt SetPixel
    • Animiertes Wasser
    • Animierte Sonne
    • Ambientes Licht durch Stand der Sonne
    • Direktionales Licht durch Position der Sonne

    Baumstämme: [Blockierte Grafik: http://r21.img-up.net/trunks665e.gif]

    Helle Baumkronen: [Blockierte Grafik: http://e76.img-up.net/leavded6e.gif]

    Dunkle Baumkronen: [Blockierte Grafik: http://k12.img-up.net/leavh0f27.gif]

    Boden: [Blockierte Grafik: http://g00.img-up.net/ground19fa.gif]

    Wasser: [Blockierte Grafik: http://r14.img-up.net/water239a.gif]

    Kreis der Sonne: [Blockierte Grafik: http://j11.img-up.net/suneb32.gif]

    Bewegung der Sonne auf der Parabel: [Blockierte Grafik: http://h12.img-up.net/sun2eb42.gif]

    Rot-Sättigung der Pixel durch die Sonne (Andy): [Blockierte Grafik: http://i82.img-up.net/srs2dee.gif]

    Berechnung der Farbwerte:
    [Blockierte Grafik: http://g13.img-up.net/trunkrgb1ee0.gif]

    [Blockierte Grafik: http://g36.img-up.net/llrgb3852.gif]

    [Blockierte Grafik: http://i78.img-up.net/dlrgb29a3.gif]

    [Blockierte Grafik: http://d61.img-up.net/eqw908c.gif]

    [Blockierte Grafik: http://u82.img-up.net/ebwre7b3.gif]

    [Blockierte Grafik: http://o83.img-up.net/avbwjbwc73b.gif]

    Das Skripte muss die Szene berechnen, dazu braucht es etwa 5 Minuten.

    Spoiler anzeigen
    [autoit]

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

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

    Opt("WinTitleMatchMode", 2)
    Global $nFrames = 60
    Global $nFPS = 30
    If $nFrames < $nFPS Then $nFrames = $nFPS
    Global $aBitmaps[$nFrames][4]
    For $i = 0 To $nFrames - 1
    $aBitmaps[$i][2] = _WinAPI_CreateCompatibleDC(0)
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, 2, 400)
    DllStructSetData($tBMI, 3, 400)
    DllStructSetData($tBMI, 4, 1)
    DllStructSetData($tBMI, 5, 32)
    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $aBitmaps[$i][1] = $aDIB[0]
    $aBitmaps[$i][0] = $aDIB[4]
    _WinAPI_SelectObject($aBitmaps[$i][2], $aBitmaps[$i][1])
    $aBitmaps[$i][3] = DllStructCreate("dword[160000]", $aBitmaps[$i][0])
    Next
    Global $fPi = 4 * ATan(1)
    $hGUI = GUICreate("Animated Landscape")
    $hDC = _WinAPI_GetDC($hGUI)
    GUISetState()
    For $iFrame = 1 To $nFrames
    $SunX = -14 + ((39 / ($nFrames - 1)) * ($iFrame - 1))
    $SunY = -(27 / 380) * $SunX ^ 2 + (297 / 380) * $SunX + (945 / 38)
    $fAmbientLight = ($SunY / 27)
    $iFrameTimer = TimerInit()
    $iSunRedSaturation = Int(0.111 * $iFrame ^ 2 - 6.667 * $iFrame + 100)
    For $fy = 0 To 400
    $y = -15 + $fy * 0.125
    For $fx = 0 To 400
    $x = -20 + $fx * 0.125
    $fDirectionalLight = Int((Abs($SunX - ($x + 6)) / 39) * 60)
    $iColorARGB = RGB(2 * $iSunRedSaturation, 200 - $iSunRedSaturation, 200 - $iSunRedSaturation)
    If $y > Sin($x) And $y > Cos($x) And $y < Tan($x) And $y < Sin($fPi * $x) + 7 And $x < 9 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 0, 0)
    ElseIf ((Mod(Abs($x) - $fPi / 2, 2 * $fPi) - $fPi) ^ 2 + ($y - 8.5 + $x ^ 2 / 250) ^ 2) < 5 And $x < 8 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 87 + Int(87 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf ((Mod(Abs($x) + $fPi / 2, 2 * $fPi) - $fPi) ^ 2 + ($y - 7.5 + $x ^ 2 / 280) ^ 2) < 5 And $x < 11 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 41 + Int(41 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf $y <= ATan(10 - $x) Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 87 + Int(87 * ($fAmbientLight)) - $fDirectionalLight, 0)
    ElseIf $y < ($iFrame / 75) * Sin($x * 2) ^ 2 + 0.5 And $y < $x - 9 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 0, 87 + Int(87 * $fAmbientLight) - $fDirectionalLight)
    ElseIf Abs(30 - ($x - $SunX) ^ 2 - ($y - $SunY) ^ 2) = 30 - ($x - $SunX) ^ 2 - ($y - $SunY) ^ 2 Then
    $iColorARGB = RGB(0xFF, 0xFF - 2 * $iSunRedSaturation, 0);0x00FFFF00
    EndIf
    DllStructSetData($aBitmaps[$iFrame - 1][3], 1, $iColorARGB, $fy * 400 + $fx + 1)
    Next
    Next
    WinSetTitle("Animated Landscape", "", "Animated Landscape Frame " & $iFrame & "/" & $nFrames & " (" & Round((TimerDiff($iFrameTimer) / 1000) * ($nFrames - $iFrame)) & "s remaining)")
    _WinAPI_BitBlt($hDC, 0, 0, 400, 400, $aBitmaps[$iFrame - 1][2], 0, 0, $srccopy)
    Next
    AdlibRegister("DrawScene", 1000 / $nFPS)
    $iFrame = 0
    $iAnimator = 1

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

    While GUIGetMsg() <> -3
    WEnd

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

    Func RGB($R, $G, $B)
    If $R <= 0 Then $R = 0
    If $G <= 0 Then $G = 0
    If $B <= 0 Then $B = 0
    Return '0x00' & Hex($R, 2) & Hex($G, 2) & Hex($B, 2)
    EndFunc ;==>RGB

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

    Func DrawScene()
    $iFrame += $iAnimator
    If $iFrame = $nFrames - 1 Or $iFrame = 0 Then $iAnimator *= -1
    _WinAPI_BitBlt($hDC, 0, 0, 400, 400, $aBitmaps[$iFrame][2], 0, 0, $srccopy)
    EndFunc ;==>DrawScene

    [/autoit]

    6 Mal editiert, zuletzt von minx (3. Januar 2014 um 22:06)

  • Nette Animation, für sowenig Code bemerkenswert

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • [autoit]

    DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, 2, 400)
    DllStructSetData($tBMI, 3, 400)
    DllStructSetData($tBMI, 4, 1)
    DllStructSetData($tBMI, 5, 32)

    [/autoit]

    Made my day :rofl: , wer braucht schon Konstanten, die vielleicht doch wieder geändert werden :thumbup:

  • Ich habe das nur getan um mit der aktuellen "Stable" kompatibel zu bleiben. Ansonsten würde mir das nie in den Sinn kommen (Es ist übrigens: Width, -Height, .., Bits) ;)

  • Gerendertes Bild hinzugefügt.

    Wer die Frames selbst speichern möchte:

    [autoit]

    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($aBitmaps[$iFrame-1][1])
    _GDIPlus_ImageSaveToFile($hImage, @MyDocumentsDir & "\Landscape_Frame_" & $iFrame-1 & ".bmp")

    [/autoit]
  • Wie hast du das GIF mit GDI+ erstellt?

    Apropos prozedurale Landschaft. Wer hat Lust das Ding hier nach AutoIt zu portieren?

    JavaScript:

    Spoiler anzeigen

    Einfach als JavaScript.htm speichern und starten.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Wieso starten wir nicht einfach ein Gemeinschaftsprojekt, an dem JEDER AutoIt-User mitarbeiten kann?

    Die "Engine" zum Berechnen einzelner Frames haben wir ja :D , die Handvoll Formeln ganz zum Schluss in eine C/C++/PowerBasic-Dll zu Giessen ist dann nur noch der letzte Schritt!
    Bis dahin könnte aber jeder, der Interesse hat, einzelne "Bauteile" beisteuern.

    Anbei ein weiterer Schritt in Sachen "Landscape", beim Sonnenauf- und Untergang werden die Farben angepasst

    Spoiler anzeigen
    [autoit]

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

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

    Global $nFrames = 60
    Global $nFPS = 30
    If $nFrames < $nFPS Then $nFrames = $nFPS
    Global $aBitmaps[$nFrames][4]
    For $i = 0 To $nFrames - 1
    $aBitmaps[$i][2] = _WinAPI_CreateCompatibleDC(0)
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, 2, 400)
    DllStructSetData($tBMI, 3, 400)
    DllStructSetData($tBMI, 4, 1)
    DllStructSetData($tBMI, 5, 32)
    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $aBitmaps[$i][1] = $aDIB[0]
    $aBitmaps[$i][0] = $aDIB[4]
    _WinAPI_SelectObject($aBitmaps[$i][2], $aBitmaps[$i][1])
    $aBitmaps[$i][3] = DllStructCreate("dword[160000]", $aBitmaps[$i][0])
    Next
    Global $fPi = 4 * ATan(1)
    $hGUI = GUICreate("Animated Landscape")
    $hDC = _WinAPI_GetDC($hGUI)
    $hStatusLabel = GUICtrlCreateLabel("0/" & $nFrames, 0, 400 / 2 - 7, 400, 14, 1)
    $hProgressLabel = GUICtrlCreateLabel("", 50, 400 / 2 + 15, 1, 2)
    GUICtrlSetBkColor(-1, 0x00FF00)
    $hStepLabel = GUICtrlCreateLabel("", 50, 400 / 2 + 20, 1, 2)
    GUICtrlSetBkColor(-1, 0x00FF00)
    GUISetState()
    For $iFrame = 1 To $nFrames
    $SunX = -14 + ((39 / ($nFrames - 1)) * ($iFrame - 1))
    $SunY = -(27 / 380) * $SunX ^ 2 + (297 / 380) * $SunX + (945 / 38)
    $fAmbientLight = ($SunY / 27)
    $iFrameTimer = TimerInit()
    $sun_redcol = Int(0.111 * $iFrame ^ 2 - 6.667 * $iFrame + 100) ;100-0-100 ;farbe der sonne, morgens+abends rot, mittags gelb
    ConsoleWrite(" " & $iFrame & ' $sun_redcol = ' & $sun_redcol & @CRLF)

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

    For $fy = 0 To 400
    $y = -15 + $fy * 0.125
    For $fx = 0 To 400
    $x = -20 + $fx * 0.125
    $fDirectionalLight = Int((Abs($SunX - ($x + 6)) / 39) * 60)
    $iColorARGB = RGB(2 * $sun_redcol, 200 - $sun_redcol, 200 - $sun_redcol)
    If $y > Sin($x) And $y > Cos($x) And $y < Tan($x) And $y < Sin($fPi * $x) + 7 And $x < 9 Then
    $iColorARGB = RGB(2 * $sun_redcol, 0, 0)
    ElseIf ((Mod(Abs($x) - $fPi / 2, 2 * $fPi) - $fPi) ^ 2 + ($y - 8.5 + $x ^ 2 / 250) ^ 2) < 5 And $x < 8 Then
    $iColorARGB = RGB(2 * $sun_redcol, 87 + Int(87 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf ((Mod(Abs($x) + $fPi / 2, 2 * $fPi) - $fPi) ^ 2 + ($y - 7.5 + $x ^ 2 / 280) ^ 2) < 5 And $x < 11 Then
    $iColorARGB = RGB(2 * $sun_redcol, 41 + Int(41 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf $y <= ATan(10 - $x) Then
    $iColorARGB = RGB(2 * $sun_redcol, 87 + Int(87 * ($fAmbientLight)) - $fDirectionalLight, 0)
    ElseIf $y < ($iFrame / 75) * Sin($x * 2) ^ 2 + 0.5 And $y < $x - 9 Then
    $iColorARGB = RGB(2 * $sun_redcol, 0, 87 + Int(87 * $fAmbientLight) - $fDirectionalLight)
    ElseIf Abs(30 - ($x - $SunX) ^ 2 - ($y - $SunY) ^ 2) = 30 - ($x - $SunX) ^ 2 - ($y - $SunY) ^ 2 Then
    $iColorARGB = RGB(0xFF, 0xFF - 2 * $sun_redcol, 0);0x00FFFF00
    EndIf
    DllStructSetData($aBitmaps[$iFrame - 1][3], 1, $iColorARGB, $fy * 400 + $fx + 1)
    Next
    GUICtrlSetPos($hStepLabel, 50, 400 / 2 + 20, 300 * ($fy / 400), 2)
    Next
    GUICtrlSetData($hStatusLabel, "Loading Scene, Frame " & $iFrame & "/" & $nFrames & " (" & Round((TimerDiff($iFrameTimer) / 1000) * ($nFrames - $iFrame)) & "s remaining)")
    GUICtrlSetPos($hProgressLabel, 50, 400 / 2 + 15, 300 * ($iFrame / $nFrames), 2)
    _WinAPI_BitBlt($hDC, 0, 0, 400, 400, $aBitmaps[$iFrame - 1][2], 0, 0, $srccopy)
    Next
    AdlibRegister("DrawScene", 1000 / $nFPS)
    $iFrame = 0
    $iAnimator = 1

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

    While GUIGetMsg() <> -3
    WEnd

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

    Func RGB($R, $G, $B)
    If $R <= 0 Then $R = 0
    If $G <= 0 Then $G = 0
    If $B <= 0 Then $B = 0
    Return '0x00' & Hex($R, 2) & Hex($G, 2) & Hex($B, 2)
    EndFunc ;==>RGB

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

    Func DrawScene()
    $iFrame += $iAnimator
    If $iFrame = $nFrames - 1 Or $iFrame = 0 Then $iAnimator *= -1
    _WinAPI_BitBlt($hDC, 0, 0, 400, 400, $aBitmaps[$iFrame][2], 0, 0, $srccopy)
    EndFunc ;==>DrawScene

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

    Weiterhin wird jetzt jeder gerenderte Frame angezeigt.

    Um das mal jetzt weiterzuspinnen, die Bäume könnten Schatten abhängig vom Sonnenstand bekommen, richtiges "Gras" bzw. "Strand" könnte eingefügt werden, Wolken, Schiff fährt in den Sonnenuntergang, Tiere laufen durch den Wald uswusf.
    Prozeduraler Sound?!
    Jeder einzelne dieser "Bausteine" kann von jeweils einem Programmierer unabhängig vom Rest beigesteuert werden.
    Es ist einfach nur die "Prozedur" für den jeweiligen Baustein zu erstellen, welcher dann einfach ins Script eingefügt werden kann...

    Würde euch so etwas interessieren?
    Jedenfalls würde man sehr viel über Mathematik erfahren :rock:

    UEZ,
    man könnte sich das Gras und die Bäume abschauen ^^

  • //1: Dann lassen wir die fancy Ladebalken gleich weg, sonst siehts sch**** aus ;)
    //2: Sinnvolle Variablen-Namen

    Spoiler anzeigen
    [autoit]

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

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

    Opt("WinTitleMatchMode", 2)
    Global $nFrames = 60
    Global $nFPS = 30
    If $nFrames < $nFPS Then $nFrames = $nFPS
    Global $aBitmaps[$nFrames][4]
    For $i = 0 To $nFrames - 1
    $aBitmaps[$i][2] = _WinAPI_CreateCompatibleDC(0)
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, 2, 400)
    DllStructSetData($tBMI, 3, 400)
    DllStructSetData($tBMI, 4, 1)
    DllStructSetData($tBMI, 5, 32)
    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $aBitmaps[$i][1] = $aDIB[0]
    $aBitmaps[$i][0] = $aDIB[4]
    _WinAPI_SelectObject($aBitmaps[$i][2], $aBitmaps[$i][1])
    $aBitmaps[$i][3] = DllStructCreate("dword[160000]", $aBitmaps[$i][0])
    Next
    Global $fPi = 4 * ATan(1)
    $hGUI = GUICreate("Animated Landscape")
    $hDC = _WinAPI_GetDC($hGUI)
    GUISetState()
    For $iFrame = 1 To $nFrames
    $SunX = -14 + ((39 / ($nFrames - 1)) * ($iFrame - 1))
    $SunY = -(27 / 380) * $SunX ^ 2 + (297 / 380) * $SunX + (945 / 38)
    $fAmbientLight = ($SunY / 27)
    $iFrameTimer = TimerInit()
    $iSunRedSaturation = Int(0.111 * $iFrame ^ 2 - 6.667 * $iFrame + 100)
    For $fy = 0 To 400
    $y = -15 + $fy * 0.125
    For $fx = 0 To 400
    $x = -20 + $fx * 0.125
    $fDirectionalLight = Int((Abs($SunX - ($x + 6)) / 39) * 60)
    $iColorARGB = RGB(2 * $iSunRedSaturation, 200 - $iSunRedSaturation, 200 - $iSunRedSaturation)
    If $y > Sin($x) And $y > Cos($x) And $y < Tan($x) And $y < Sin($fPi * $x) + 7 And $x < 9 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 0, 0)
    ElseIf ((Mod(Abs($x) - $fPi / 2, 2 * $fPi) - $fPi) ^ 2 + ($y - 8.5 + $x ^ 2 / 250) ^ 2) < 5 And $x < 8 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 87 + Int(87 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf ((Mod(Abs($x) + $fPi / 2, 2 * $fPi) - $fPi) ^ 2 + ($y - 7.5 + $x ^ 2 / 280) ^ 2) < 5 And $x < 11 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 41 + Int(41 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf $y <= ATan(10 - $x) Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 87 + Int(87 * ($fAmbientLight)) - $fDirectionalLight, 0)
    ElseIf $y < ($iFrame / 75) * Sin($x * 2) ^ 2 + 0.5 And $y < $x - 9 Then
    $iColorARGB = RGB(2 * $iSunRedSaturation, 0, 87 + Int(87 * $fAmbientLight) - $fDirectionalLight)
    ElseIf Abs(30 - ($x - $SunX) ^ 2 - ($y - $SunY) ^ 2) = 30 - ($x - $SunX) ^ 2 - ($y - $SunY) ^ 2 Then
    $iColorARGB = RGB(0xFF, 0xFF - 2 * $iSunRedSaturation, 0);0x00FFFF00
    EndIf
    DllStructSetData($aBitmaps[$iFrame - 1][3], 1, $iColorARGB, $fy * 400 + $fx + 1)
    Next
    Next
    WinSetTitle("Animated Landscape", "", "Animated Landscape Frame " & $iFrame & "/" & $nFrames & " (" & Round((TimerDiff($iFrameTimer) / 1000) * ($nFrames - $iFrame)) & "s remaining)")
    _WinAPI_BitBlt($hDC, 0, 0, 400, 400, $aBitmaps[$iFrame - 1][2], 0, 0, $srccopy)
    Next
    AdlibRegister("DrawScene", 1000 / $nFPS)
    $iFrame = 0
    $iAnimator = 1

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

    While GUIGetMsg() <> -3
    WEnd

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

    Func RGB($R, $G, $B)
    If $R <= 0 Then $R = 0
    If $G <= 0 Then $G = 0
    If $B <= 0 Then $B = 0
    Return '0x00' & Hex($R, 2) & Hex($G, 2) & Hex($B, 2)
    EndFunc ;==>RGB

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

    Func DrawScene()
    $iFrame += $iAnimator
    If $iFrame = $nFrames - 1 Or $iFrame = 0 Then $iAnimator *= -1
    _WinAPI_BitBlt($hDC, 0, 0, 400, 400, $aBitmaps[$iFrame][2], 0, 0, $srccopy)
    EndFunc ;==>DrawScene

    [/autoit]
  • Faszinierend, was man mit diesen "billigen" Formeln alles machen kann...
    Da würde ich mich gerne nochmal in eine Vorlesung setzen und einige Wochen Tips, Tricks und Kniffe abschauen.
    Hat jemand einen guten Tip für etwas lesbare, also verständliche Kost abseits von Differentialrechnung (kann das zwar noch einigermassen, aber das ist soooo mühselig...:( )

  • Ich habe mal versucht, das Skript ein bisschen zu beschleunigen.

    Spoiler anzeigen
    [autoit]


    #include <WindowsConstants.au3>
    #include <WinAPIGdi.au3>

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

    Opt("WinTitleMatchMode", 2)
    Global $nFrames = 60
    Global $nFPS = 30
    Global Const $iWidth = 400, $iHeight = $iWidth, $iStep = 4
    If $nFrames < $nFPS Then $nFrames = $nFPS
    Global $aBitmaps[$nFrames][4]
    For $i = 0 To $nFrames - 1
    $aBitmaps[$i][2] = _WinAPI_CreateCompatibleDC(0)
    $tBMI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4)
    DllStructSetData($tBMI, 2, $iWidth)
    DllStructSetData($tBMI, 3, $iHeight)
    DllStructSetData($tBMI, 4, 1)
    DllStructSetData($tBMI, 5, 32)
    $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $aBitmaps[$i][1] = $aDIB[0]
    $aBitmaps[$i][0] = $aDIB[4]
    _WinAPI_SelectObject($aBitmaps[$i][2], $aBitmaps[$i][1])
    $aBitmaps[$i][3] = DllStructCreate("dword[" & $iWidth * $iHeight & "]", $aBitmaps[$i][0])
    Next
    Global $fPi = 4 * ATan(1)
    $hGUI = GUICreate("Animated Landscape", $iWidth, $iHeight)
    $hDC = _WinAPI_GetDC($hGUI)
    GUISetState()

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

    Global $f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8, $f9, $f10, $f20

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

    For $iFrame = 1 To $nFrames
    $SunX = -14 + ((39 / ($nFrames - 1)) * ($iFrame - 1))
    $SunY = -(27 / 380) * $SunX * $SunX + (297 / 380) * $SunX + (945 / 38)
    $fAmbientLight = ($SunY / 27)
    $iFrameTimer = TimerInit()
    $iSunRedSaturation = Int(0.111 * $iFrame * $iFrame - 6.667 * $iFrame + 100)
    For $fy = 0 To $iHeight Step $iStep
    $y = -15 + $fy * 0.125
    For $fx = 0 To $iWidth Step $iStep
    $x = -20 + $fx * 0.125
    $fDirectionalLight = Int((Abs($SunX - ($x + 6)) / 39) * 60)
    $f1 = 30 - ($x - $SunX) * ($x - $SunX) - ($y - $SunY) * $y - $SunY
    $f2 = $x * $x
    $f3 = Abs($x)
    $f4 = $fPi / 2
    $f5 = 2 * $fPi
    $f6 = 2 * $iSunRedSaturation
    $f7 = Mod($f3 - $f4, $f5)
    $f8 = Mod($f3 + $f4, $f5)
    $f9 = Int(87 * $fAmbientLight)
    $f10 = $x * 2
    $iColorARGB = RGB($f6, 200 - $iSunRedSaturation, 200 - $iSunRedSaturation)
    If $y > Sin($x) And $y > Cos($x) And $y < Tan($x) And $y < Sin($fPi * $x) + 7 And $x < 9 Then
    $iColorARGB = RGB($f6, 0, 0)
    ElseIf (($f7 - $fPi) * ($f7 - $fPi) + ($y - 8.5 + $f2 / 250) * ($y - 8.5 + $f2 / 250)) < 5 And $x < 8 Then
    $iColorARGB = RGB($f6, 87 + $f9 - $fDirectionalLight, 0)
    ElseIf (($f8 - $fPi) * ($f8 - $fPi) + ($y - 7.5 + $f2 / 280) * ($y - 7.5 + $f2 / 280)) < 5 And $x < 11 Then
    $iColorARGB = RGB($f6, 41 + Int(41 * $fAmbientLight) - $fDirectionalLight, 0)
    ElseIf $y <= ATan(10 - $x) Then
    $iColorARGB = RGB($f6, 87 + Int(87 * ($fAmbientLight)) - $fDirectionalLight, 0)
    ElseIf $y < ($iFrame / 75) * Sin($f10) * Sin($f10) + 0.5 And $y < $x - 9 Then
    $iColorARGB = RGB($f6, 0, 87 + $f9 - $fDirectionalLight)
    ElseIf Abs($f1) = $f1 Then
    $iColorARGB = RGB(0xFF, 0xFF - $f6, 0);0x00FFFF00
    EndIf
    DllStructSetData($aBitmaps[$iFrame - 1][3], 1, $iColorARGB, ($fy / $iStep) * $iHeight + ($fx / $iStep) + 1)
    Next
    Next
    WinSetTitle("Animated Landscape", "", "Animated Landscape Frame " & $iFrame & "/" & $nFrames & " (" & Round((TimerDiff($iFrameTimer) / 1000) * ($nFrames - $iFrame)) & "s remaining)")
    ;~ _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $aBitmaps[$iFrame - 1][2], 0, 0, $srccopy)
    $f20 = $iHeight / $iStep
    _WinAPI_StretchBlt($hDC, 0, 0, $iWidth, $iHeight, $aBitmaps[$iFrame - 1][2], 0, $iHeight - ($f20), $iWidth / $iStep, $f20, $SRCCOPY)
    Next
    AdlibRegister("DrawScene", 1000 / $nFPS)
    $iFrame = 0
    $iAnimator = 1

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

    While GUIGetMsg() <> -3
    WEnd

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

    Func RGB($R, $G, $B)
    If $R < 0 Then
    $R = 0
    EndIf
    If $G < 0 Then
    $G = 0
    EndIf
    If $B < 0 Then
    $B = 0
    EndIf
    Return '0x' & Hex($r * 0x10000 + $g * 0x100 + $b, 6)
    EndFunc ;==>RGB

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

    Func DrawScene()
    $iFrame += $iAnimator
    If $iFrame = $nFrames - 1 Or $iFrame = 0 Then
    $iAnimator *= -1
    EndIf
    ;~ _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $aBitmaps[$iFrame][2], 0, 0, $srccopy)
    $f20 = $iHeight / $iStep
    _WinAPI_StretchBlt($hDC, 0, 0, $iWidth, $iHeight, $aBitmaps[$iFrame][2], 0, $iHeight - ($f20), $iWidth / $iStep, $f20, $SRCCOPY)
    EndFunc ;==>DrawScene

    [/autoit]

    Ich habe ein bisschen "getürkt". :D

    Ich habe es nicht mit der minx'schen Version gebencht, also keine Ahnung, ob das was gebracht hat. Theoretisch ja...

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Macht bei mir keinen Unterschied :?:

    Ich habe übrigens Width und Height ganz bewusst entfernt, da in den Formeln viele konstante Zahlen sind, die von 400 als festen Wert ausgehen.

    Der Deal hier ist wohl eher die Mathematik. ASM empfiehlt sich :D

  • Zitat

    Der Deal hier ist wohl eher die Mathematik. ASM empfiehlt sich

    so ist es, dann kann man nämlich auch komplett die sin(), cos() und tan()-Funktionen durch konstanten ersetzen, da diese sowieso aufeinanderfolgen.
    Allerdings bringt diese Beschleunigung in AutoIt garnichts, da der Interpreter in etwa dieselbe Zeit für ein v1+v2 braucht wie für ein sin().
    In einer Compilersprache bringt das Faktor 20-30 an Geschwindigkeit! /
    Ich such mir gerade nen Wolf....
    //EDIT gefunden Ersetzen von Sinus in einer Schleife, beschleunigt den code um Faktor 30 8o

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    2 Mal editiert, zuletzt von Andy (4. Januar 2014 um 00:47)

  • Ich such mir gerade nen Wolf....

    Wir brauchen Mond & Sterne. Mond ist Sonne in weiß + Halo aus einem anderen weißen Kreis, der radial transparenter wird. Sterne müssen auch blinken ^^

    Eine LUT empfiehlt sich zumindest (pre-generiert, nicht hard-gecodet). Damit kann man schon 400*60 Berechnungen sparen, wenn man nur ein sin(x) ersetzt.