GDI+ Raumgitter

  • Hi,

    das ist mein erstes veröffentlichtes Script; mit GDI+ (mag ich am meisten).

    Das ist ein Gitter(wie bei einer Art Map), das man mit den Pfeiltasten bewegen kann.

    Hier ist der Quellcode:


    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <Misc.au3>
    Opt("GUIOnEventMode",1)
    Opt("MouseCoordMode",2)
    Global $iWidth = 700
    Global $iHeight = 700
    Global $alpha = 0
    Global $xax = 175
    Global $xay = 175
    Global $zx = 1
    Global $zy = 1
    MsgBox(0,"Anleitung","Zum drehen des Gitters LINKS und RECHTS verwenden. Zum Kippen HOCH und RUNTER verwenden.")
    $hWnd = GUICreate("Raumgitter",$iWidth,$iHeight,-1,-1)
    GUISetState(@SW_SHOW)
    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth,$iHeight,$hGraphics)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBuffer,2)
    $hPenrot = _GDIPlus_PenCreate(0xFFFF0000)
    $hPengruen = _GDIPlus_PenCreate(0xFF00FF00)
    $hPenblau = _GDIPlus_PenCreate(0xFF0000FF)
    $hBrushhellblau = _GDIPlus_BrushCreateSolid(0xFF0077FF)
    $hBrushgruen = _GDIPlus_BrushCreateSolid(0xFF00FF00)

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

    GUISetOnEvent(-3,"_exit")
    AdlibRegister("_draw",10)

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

    While 1
    WEnd
    Func _draw()
    _GDIPlus_GraphicsClear($hBuffer,0xFF000000)

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

    _GDIPlus_GraphicsDrawEllipse($hBuffer,$iWidth/2 - 2,$iHeight/2 - 2,4,4,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha)*$xay * $zy,$iWidth/2 + Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax/5 * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/5 * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 - Cos($alpha+67.5)*$xax/5 * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/5 * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax/2.5 * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/2.5 * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 - Cos($alpha+67.5)*$xax/2.5 * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/2.5 * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax/(5/3) * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/(5/3) * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 - Cos($alpha+67.5)*$xax/(5/3) * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/(5/3) * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax/1.25 * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/1.25 * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 - Cos($alpha+67.5)*$xax/1.25 * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay/1.25 * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy + Sin($alpha)*$xay * $zy,$hPenrot)

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

    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 + Cos($alpha+67.5)*$xax/5 * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/5 * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax/5 * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/5 * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 + Cos($alpha+67.5)*$xax/2.5 * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/2.5 * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax/2.5 * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/2.5 * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 + Cos($alpha+67.5)*$xax/(5/3) * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/(5/3) * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax/(5/3) * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/(5/3) * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 + Cos($alpha+67.5)*$xax/1.25 * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/1.25 * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax/1.25 * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay/1.25 * $zy + Sin($alpha)*$xay * $zy,$hPenrot)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx - Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy - Sin($alpha)*$xay * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx + Cos($alpha)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy + Sin($alpha)*$xay * $zy,$hPenrot)

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

    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/5 * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/5 * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/5 * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/5 * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/2.5 * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/2.5 * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/2.5 * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/2.5 * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/(5/3) * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/(5/3) * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/(5/3) * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/(5/3) * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/1.25 * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/1.25 * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax)/1.25 * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay)/1.25 * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax) * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay) * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx - (Cos($alpha)*$xax) * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy - (Sin($alpha)*$xay) * $zy,$hPengruen)

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

    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/5 * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/5 * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/5 * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/5 * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/2.5 * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/2.5 * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/2.5 * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/2.5 * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/(5/3) * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/(5/3) * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/(5/3) * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/(5/3) * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/1.25 * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/1.25 * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax)/1.25 * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay)/1.25 * $zy,$hPengruen)
    _GDIPlus_GraphicsDrawLine($hBuffer,$iWidth/2 - Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax) * $zx,$iHeight/2 - Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay) * $zy,$iWidth/2 + Cos($alpha+67.5)*$xax * $zx + (Cos($alpha)*$xax) * $zx,$iHeight/2 + Sin($alpha+67.5)*$xay * $zy + (Sin($alpha)*$xay) * $zy,$hPengruen)

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

    _GDIPlus_GraphicsDrawImageRect($hGraphics,$hBitmap,0,0,$iWidth,$iHeight)

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

    If _IsPressed("25") Then
    $alpha -= 0.02
    EndIf

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

    If _IsPressed("27") Then
    $alpha += 0.02
    EndIf

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

    If _IsPressed("26") Then
    $xay -= 1

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

    If $xay <= 0 Then $xay = 0
    EndIf

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

    If _IsPressed("28") Then
    $xay += 1

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

    If $xay >= $iHeight/4 Then $xay = $iHeight/4
    EndIf
    If _IsPressed("55") Then
    $zx *= 1.1
    $zy *= 1.1

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

    If $zx >= $iWidth Then
    $zx = $iWidth
    EndIf
    If $zy >= $iWidth Then
    $zy = $iWidth
    EndIf
    EndIf

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

    If _IsPressed("49") Then
    $zx /= 1.1
    $zy /= 1.1

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

    If $zx <= 1 Then
    $zx = 1
    EndIf
    If $zy <= 1 Then
    $zy = 1
    EndIf
    EndIf
    EndFunc
    Func _exit()
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)

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

    _GDIPlus_PenDispose($hPenrot)
    _GDIPlus_PenDispose($hPengruen)
    _GDIPlus_PenDispose($hPenblau)

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

    _GDIPlus_BrushDispose($hBrushhellblau)
    _GDIPlus_BrushDispose($hBrushgruen)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]
  • Die Perspektive ist nicht mit Fluchtpunkten, sondern mit einem "gedrückten" Kreis (dank 11.Klasse Mathe aufgepasst). Daher kann es ein bisschen komisch aussehen. Ich find auch des sieht ein bisschen wie ein leicht gebogenes Blatt aus.

    MfG mazZ


    P.S.: Genießt das Wochenende. 8)