Alles anzeigenOptimierung von Code am Beispiel des Tunnelfluges
Wer das Beispiel im vorherigen Post durchgegangen ist, der hat wahrscheinlich den Kopf geschüttelt ob so viel Unfähigkeit des Programmierers^^
Warum?
Nun, wir (ich) haben ein AutoItScript nach Assembler portiert, aber dieses gemacht, OHNE NACHZUDENKEN!
Allein das AutoItScript hat reichlich Kürzungs- und Optimierungsbedarf!
Selbst mit geringen mathematischen Kenntnissen, kommt man auf folgendes Script:Spoiler anzeigen
[autoit];Idea taken from http://js1k.com/demo/462
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
;Ported to AutoIt by UEZ Build 2010-08-20
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "Star Burst_Obfuscated.au3"
#AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%"
;~ #AutoIt3Wrapper_Run_After=upx.exe --best "%out%"
#include
#include
;Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)Local $hGUI, $hGraphics, $hBackbuffer, $hBitmap
[/autoit] [autoit][/autoit] [autoit]
Local $H = 332, $W = 332
; Initialize GDI+
_GDIPlus_Startup()$hGUI = GUICreate("GDI+ Test", $W, $H)
[/autoit] [autoit][/autoit] [autoit]
GUISetState()$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
[/autoit] [autoit][/autoit] [autoit]
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($W, $H, $hGraphics)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap); Using antialiasing
[/autoit] [autoit][/autoit] [autoit]
;~ _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 0)
; Create a Brush object
Local $hBrush = _GDIPlus_BrushCreateSolid()GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
[/autoit] [autoit][/autoit] [autoit]adlibregister("_fps",1000)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]global $pi = ACos(-1), $pi2 = 2 * $pi, $pi05 = ACos(-1) * 0.5, $fps
[/autoit] [autoit][/autoit] [autoit]
Local $HW = $H * 0.5, $HH = $W * 0.5
Local $A0 = 0, $A1 = 0, $A2 = 0, $A3 = 0
Local $ox = 0, $oy = 0, $0z = 0
Local $tu = 0, $tv = 0
Local $speed = 2
Local $i, $j, $x, $y, $o
Local $cc, $ss, $z, $col
Local $dx, $dy, $dz, $rd, $A, $B, $C, $R, $t1, $tu, $tv, $q, $g, $l
Local $d[$W + 1]$zwonulldrei=203.718330632686
[/autoit] [autoit][/autoit] [autoit]
$nulldrei=0.390625
;$a1=0.07While 1;Sleep(10)
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBackbuffer, 0xFF000000)For $i = 0 To $H Step $speed
[/autoit] [autoit][/autoit] [autoit]
For $j = 0 To $W Step $speed
$dx=($j/$W)-0.5;
$dy=($i/$H)-0.5;
$tu=int($zwonulldrei*ATan2($dy,$dx))
$tv=($nulldrei/sqrt($dx*$dx+$dy*$dy))+$A1
$tv=int($tv*256)
$g = Hex(bitand(Bitxor($tu , $tv), 0xFF), 2)
$col = "0xFF" & $g & $g & $g
_GDIPlus_BrushSetSolidColor($hBrush, $col)
_GDIPlus_GraphicsFillRect($hBackbuffer, $j, $i, $speed, $speed, $hBrush)Next
[/autoit] [autoit][/autoit] [autoit]
Next
$A1 += 0.07_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $W, $H)
[/autoit] [autoit][/autoit] [autoit]
$fps+=1
; ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $A1 = ' & $A1 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
WEndfunc _FPS()
[/autoit] [autoit][/autoit] [autoit]
winsettitle($hgui,"",$FPS)
$FPS=0
endfuncFunc Rotate($t)
[/autoit] [autoit][/autoit] [autoit]
$cc = Cos($t)
$ss = Sin($t)
$z = $x * $cc - $y * $ss
$y = $x * $ss + $y * $cc
$x = $z
EndFuncfunc atan2($y,$x)
[/autoit] [autoit][/autoit] [autoit]
return (2*atan($y/($x+sqrt($x*$x+$y*$y))))
endfuncFunc ATan2_UEZ($y,$x)
[/autoit] [autoit][/autoit] [autoit]
Switch $x
Case ($x > 0)
Return ATan($y / $x)
Case ($x < 0 And $y >= 0)
Return ATan($y / $x + $pi)
Case ($x < 0 And $y < 0)
Return ATan($y / $x - $pi)
Case ($x = 0 And $y > 0)
Return $pi05
Case ($x = 0 And $y < 0)
Return -$pi05
Case ($x = 0 And $y = 0)
Return 0
EndSwitch
EndFuncFunc _Exit()
[/autoit] [autoit][/autoit] [autoit]
; Clean up
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics); Uninitialize GDI+
[/autoit]
_GDIPlus_Shutdown()
Exit
EndFuncDas sieht schon anders aus!
Viele Variablen sind verschwunden und jede Menge Rechnerei auch!
Dafür fehlt jetzt aber die Rotation ![]()
Gruß,
UEZ