Die Überschrift sagt eigentlich schon alles.
Danke an UEZ, der mich auf die Idee gebracht hat!
Die Scripte sind auch ausreichend kommentiert, für die, die sich weniger auskennen.
GDI+Beispiel: Drehende Dreiecke
#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1); Setzt das Script in den OnEventModus
[/autoit] [autoit][/autoit] [autoit]Global $hGraphic, $bitmap, $backbuffer, $Pen, $brush
Global $rotation1 = 0, $rotation2 = 0, $rotation3 = 0, $rotation4 = 0, $rotation5 = 0
Global $Pi = 3.14159
$hwnd = GUICreate("GDI+ Beispiel: Drehende Dreiecke", 450, 450, -1, -1); Erstellt ein Fenster
GUISetBkColor(0x000000); Setzt die Hintergrundfarbe der GUI auf schwarz
GUISetOnEvent(-3, "_Close"); Die Funktion '_Close' wird ausgeführt, wenn das Fenster geschlossen wird
GUISetState(@SW_SHOW, $hwnd); Macht das Fenster sichtbar
_GDIPlus_Startup(); Ladet die GDI+ dll
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwnd) ; Erstelle GDI+ Objekt von der GUI (Grafik)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(450, 450, $hGraphic) ; Erstelle Bitmap von der Grafik
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ; Erstelle Grafik Kontext von der Bitmap (dient für die Doppeltbufferung der Grafik, damit die Bewegungen flüssiger aussehen
$pen = _GDIPlus_PenCreate(0, 1) ; Erstelle Stift mit der Stärke 1 Pixels
_GDIPlus_PenSetColor($Pen, 0xFF00FF00) ; Setze Stiftfarbe
$brush = _GDIPlus_BrushCreateSolid(0x10000000); Erstellt ein vollfarbiges Pinselobjekt
While 1
_GDIPlus_GraphicsFillRect($backbuffer, 0, 0, 450, 450, $brush); Überzeichnet den Buffer mit einem transparentem schwarz
; Ab hier werden die Dreiecke im Buffer gezeichnet und berechnet
$rotation1 += $Pi / 200
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation1 + $Pi / 2) * 200 + 450 / 2, Sin($rotation1 + $Pi / 2) * 200 + 450 / 2, Cos($rotation1 + $Pi / 2 + (2 * $Pi) / 3) * 200 + 450 / 2, Sin($rotation1 + $Pi / 2 + (2 * $Pi) / 3) * 200 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation1 + $Pi / 2 + (2 * $Pi) / 3) * 200 + 450 / 2, Sin($rotation1 + $Pi / 2 + (2 * $Pi) / 3) * 200 + 450 / 2, Cos($rotation1 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 200 + 450 / 2, Sin($rotation1 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 200 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation1 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 200 + 450 / 2, Sin($rotation1 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 200 + 450 / 2, Cos($rotation1 + $Pi / 2) * 200 + 450 / 2, Sin($rotation1 + $Pi / 2) * 200 + 450 / 2, $pen)
$rotation2 -= $Pi / 100
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation2 + $Pi / 2) * 100 + 450 / 2, Sin($rotation2 + $Pi / 2) * 100 + 450 / 2, Cos($rotation2 + $Pi / 2 + (2 * $Pi) / 3) * 100 + 450 / 2, Sin($rotation2 + $Pi / 2 + (2 * $Pi) / 3) * 100 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation2 + $Pi / 2 + (2 * $Pi) / 3) * 100 + 450 / 2, Sin($rotation2 + $Pi / 2 + (2 * $Pi) / 3) * 100 + 450 / 2, Cos($rotation2 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 100 + 450 / 2, Sin($rotation2 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 100 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation2 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 100 + 450 / 2, Sin($rotation2 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 100 + 450 / 2, Cos($rotation2 + $Pi / 2) * 100 + 450 / 2, Sin($rotation2 + $Pi / 2) * 100 + 450 / 2, $pen)
$rotation3 += $Pi / 50
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation3 + $Pi / 2) * 50 + 450 / 2, Sin($rotation3 + $Pi / 2) * 50 + 450 / 2, Cos($rotation3 + $Pi / 2 + (2 * $Pi) / 3) * 50 + 450 / 2, Sin($rotation3 + $Pi / 2 + (2 * $Pi) / 3) * 50 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation3 + $Pi / 2 + (2 * $Pi) / 3) * 50 + 450 / 2, Sin($rotation3 + $Pi / 2 + (2 * $Pi) / 3) * 50 + 450 / 2, Cos($rotation3 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 50 + 450 / 2, Sin($rotation3 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 50 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation3 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 50 + 450 / 2, Sin($rotation3 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 50 + 450 / 2, Cos($rotation3 + $Pi / 2) * 50 + 450 / 2, Sin($rotation3 + $Pi / 2) * 50 + 450 / 2, $pen)
$rotation4 -= $Pi / 25
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation4 + $Pi / 2) * 25 + 450 / 2, Sin($rotation4 + $Pi / 2) * 25 + 450 / 2, Cos($rotation4 + $Pi / 2 + (2 * $Pi) / 3) * 25 + 450 / 2, Sin($rotation4 + $Pi / 2 + (2 * $Pi) / 3) * 25 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation4 + $Pi / 2 + (2 * $Pi) / 3) * 25 + 450 / 2, Sin($rotation4 + $Pi / 2 + (2 * $Pi) / 3) * 25 + 450 / 2, Cos($rotation4 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 25 + 450 / 2, Sin($rotation4 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 25 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation4 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 25 + 450 / 2, Sin($rotation4 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 25 + 450 / 2, Cos($rotation4 + $Pi / 2) * 25 + 450 / 2, Sin($rotation4 + $Pi / 2) * 25 + 450 / 2, $pen)
$rotation5 += $Pi / 12.5
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation5 + $Pi / 2) * 12.5 + 450 / 2, Sin($rotation5 + $Pi / 2) * 12.5 + 450 / 2, Cos($rotation5 + $Pi / 2 + (2 * $Pi) / 3) * 12.5 + 450 / 2, Sin($rotation5 + $Pi / 2 + (2 * $Pi) / 3) * 12.5 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation5 + $Pi / 2 + (2 * $Pi) / 3) * 12.5 + 450 / 2, Sin($rotation5 + $Pi / 2 + (2 * $Pi) / 3) * 12.5 + 450 / 2, Cos($rotation5 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 12.5 + 450 / 2, Sin($rotation5 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 12.5 + 450 / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, Cos($rotation5 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 12.5 + 450 / 2, Sin($rotation5 + $Pi / 2 + ((2 * $Pi) / 3) * 2) * 12.5 + 450 / 2, Cos($rotation5 + $Pi / 2) * 12.5 + 450 / 2, Sin($rotation5 + $Pi / 2) * 12.5 + 450 / 2, $pen)
; Ende der Zeichnungen und Berechnungen
_GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 0, 0, 450, 450) ; Das Zeichnen hat im Buffer stattgefunden. Damit das Ganze sichtbar wird, wird das Ganze in die Graphik kopiert
Sleep(10)
WEnd
Func _Close()
_GDIPlus_BrushDispose($brush); Löst das Pinselobjekt auf
_GDIPlus_PenDispose($pen); Löst den Pinsel auf
_GDIPlus_GraphicsDispose($backbuffer); Löst den Buffer auf
_GDIPlus_BitmapDispose($bitmap); Löst die Bitmap auf
_GDIPlus_GraphicsDispose($hGraphic); Löst die Graphic auf
_GDIPlus_Shutdown(); Schließt die GDI+ dll
WinClose($hwnd); Schließt das Fenster
Exit; Beendet das Script
EndFunc
GDI+Beispiel: Drehende Quadrate
#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1); Setzt das Script in den OnEventModus
[/autoit] [autoit][/autoit] [autoit]Global $hGraphic, $bitmap, $backbuffer, $Pen, $brush
Global $rotation1 = 0, $rotation2 = 0, $rotation3 = 0, $rotation4 = 0, $rotation5 = 0
Global $Pi = 3.14159, _
$pi_Div_180 = 4 * ATan(1) / 180, _
$width = 450, _
$height = 450
Global $Size
[/autoit] [autoit][/autoit] [autoit]Global $x1, $x2, $x3, $x4, _
$y1, $y2, $y3, $y4
$hwnd = GUICreate("GDI+ Beispiel: Drehende Dreiecke", $width, $height, -1, -1); Erstellt ein Fenster
GUISetBkColor(0x000000); Setzt die Hintergrundfarbe der GUI auf schwarz
GUISetOnEvent(-3, "_Close"); Die Funktion '_Close' wird ausgeführt, wenn das Fenster geschlossen wird
GUISetState(@SW_SHOW, $hwnd); Macht das Fenster sichtbar
_GDIPlus_Startup(); Ladet die GDI+ dll
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwnd) ; Erstelle GDI+ Objekt von der GUI (Grafik)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(450, 450, $hGraphic) ; Erstelle Bitmap von der Grafik
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ; Erstelle Grafik Kontext von der Bitmap (dient für die Doppeltbufferung der Grafik, damit die Bewegungen flüssiger aussehen
$pen = _GDIPlus_PenCreate(0, 1) ; Erstelle Stift mit der Stärke 1 Pixels
_GDIPlus_PenSetColor($Pen, 0xFF00FF00) ; Setze Stiftfarbe
$brush = _GDIPlus_BrushCreateSolid(0x10000000); Erstellt ein vollfarbiges Pinselobjekt
While 1
_GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $width, $height, $brush); Überzeichnet den Buffer mit einem transparentem schwarz
; Ab hier werden die Quadrate im Buffer gezeichnet und berechnet
$Size = 200; Setzt die Größe des Quadrates
; $rotation1 += $Pi / 5; Berechnet den Rotationswinkel
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos($rotation1 * $pi_Div_180) + $width / 2, $Size * Sin($rotation1 * $pi_Div_180) + $height / 2, $Size * Cos(($rotation1 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation1 + 90) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation1 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation1 + 90) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation1 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation1 + 180) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation1 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation1 + 180) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation1 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation1 + 270) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation1 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation1 + 270) * $pi_Div_180) + $height / 2, $Size * Cos($rotation1 * $pi_Div_180) + $width / 2, $Size * Sin($rotation1 * $pi_Div_180) + $height / 2, $pen)
$Size = 140; Setzt die Größe des Quadrates
$rotation2 -= $Pi / 3.75; Berechnet den Rotationswinkel
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos($rotation2 * $pi_Div_180) + $width / 2, $Size * Sin($rotation2 * $pi_Div_180) + $height / 2, $Size * Cos(($rotation2 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation2 + 90) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation2 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation2 + 90) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation2 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation2 + 180) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation2 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation2 + 180) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation2 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation2 + 270) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation2 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation2 + 270) * $pi_Div_180) + $height / 2, $Size * Cos($rotation2 * $pi_Div_180) + $width / 2, $Size * Sin($rotation2 * $pi_Div_180) + $height / 2, $pen)
$Size = 100; Setzt die Größe des Quadrates
$rotation3 += $Pi / 2.8125; Berechnet den Rotationswinkel
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos($rotation3 * $pi_Div_180) + $width / 2, $Size * Sin($rotation3 * $pi_Div_180) + $height / 2, $Size * Cos(($rotation3 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation3 + 90) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation3 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation3 + 90) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation3 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation3 + 180) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation3 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation3 + 180) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation3 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation3 + 270) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation3 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation3 + 270) * $pi_Div_180) + $height / 2, $Size * Cos($rotation3 * $pi_Div_180) + $width / 2, $Size * Sin($rotation3 * $pi_Div_180) + $height / 2, $pen)
$Size = 70; Setzt die Größe des Quadrates
$rotation4 -= $Pi / 2.109375; Berechnet den Rotationswinkel
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos($rotation4 * $pi_Div_180) + $width / 2, $Size * Sin($rotation4 * $pi_Div_180) + $height / 2, $Size * Cos(($rotation4 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation4 + 90) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation4 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation4 + 90) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation4 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation4 + 180) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation4 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation4 + 180) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation4 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation4 + 270) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation4 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation4 + 270) * $pi_Div_180) + $height / 2, $Size * Cos($rotation4 * $pi_Div_180) + $width / 2, $Size * Sin($rotation4 * $pi_Div_180) + $height / 2, $pen)
$Size = 50; Setzt die Größe des Quadrates
$rotation5 += $Pi / 1.58203125; Berechnet den Rotationswinkel
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos($rotation5 * $pi_Div_180) + $width / 2, $Size * Sin($rotation5 * $pi_Div_180) + $height / 2, $Size * Cos(($rotation5 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation5 + 90) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation5 + 90) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation5 + 90) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation5 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation5 + 180) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation5 + 180) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation5 + 180) * $pi_Div_180) + $height / 2, $Size * Cos(($rotation5 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation5 + 270) * $pi_Div_180) + $height / 2, $pen)
_GDIPlus_GraphicsDrawLine($backbuffer, $Size * Cos(($rotation5 + 270) * $pi_Div_180) + $width / 2, $Size * Sin(($rotation5 + 270) * $pi_Div_180) + $height / 2, $Size * Cos($rotation5 * $pi_Div_180) + $width / 2, $Size * Sin($rotation5 * $pi_Div_180) + $height / 2, $pen)
; Ende der Zeichnungen und Berechnungen
_GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 0, 0, 450, 450) ; Das Zeichnen hat im Buffer stattgefunden. Damit das Ganze sichtbar wird, wird das Ganze in die Graphik kopiert
Sleep(10)
WEnd
Func _Close()
_GDIPlus_BrushDispose($brush); Löst das Pinselobjekt auf
_GDIPlus_PenDispose($pen); Löst den Pinsel auf
_GDIPlus_GraphicsDispose($backbuffer); Löst den Buffer auf
_GDIPlus_BitmapDispose($bitmap); Löst die Bitmap auf
_GDIPlus_GraphicsDispose($hGraphic); Löst die Graphic auf
_GDIPlus_Shutdown(); Schließt die GDI+ dll
WinClose($hwnd); Schließt das Fenster
Exit; Beendet das Script
EndFunc
PS:
Bei den Berechnungen hat mir mein Dad geholfen.
Edit1:
Pi ist jetzt eine Variable.
Edit2:
Hab jetzt auch noch ein Bispiel mit rotierenden Quadraten hinzugefügt. Danke an UEZ für seine Hilfe.