Mit GDI+ um einen Punkt Striche Zeichnen

  • Hallo,

    ich habe gerade einen Script geschrieben. Es erstellt eine GUI mit einem Punkt in der Mitte. Vom Punkt aus sollen dann Striche bis zum Rand gezogen werden und das einmal ganz rundherum.
    Doch irgendwie macht der nur 1/4 statt alles. Woran kann das genau liegen? Ich blicke da nicht mehr ganz durch :wacko:

    Code:

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

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

    AutoIt Version: 3.3.0.0
    Author: myName

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

    Script Function:
    Template AutoIt script.

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

    #ce ----------------------------------------------------------------------------

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

    ; Script Start - Add your code below here

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

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

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

    Global $index, $hPen
    Global $x1, $y1, $x2, $y2
    Global Const $Pi = 4 * ATan(1)
    Global $radians = 180 * 2.50
    Global $x = 1024
    Global $i

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

    $GUI_Handle = GUICreate("GDI+", 1024, 768)
    GUISetBkColor(0x000000)
    GUISetState(@SW_SHOW)
    $hWnd = WinGetHandle($GUI_Handle)

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

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4) ; AntiAlias

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

    Line_Color()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Quit()

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

    EndSwitch

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

    _GDIPlus_GraphicsDrawLine($hGraphic, $x1, $y1, $x2, $y2, $hPen) ;draw line
    _GDIPlus_PenDispose($hPen)
    _Test()
    Line_Color()

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

    $i += 1

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

    ;~ Sleep(10)
    WEnd

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

    Func _Test()

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

    $x1 = 1024 / 2
    $y1 = 768 / 2
    $x2 = $i
    $y2 = 0

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

    TrayTip("", $x2, 5, 1)

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

    EndFunc ;==>_Test

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

    Func Line_Color() ;thanks to monoceres for the code
    Local $RedM = 1, $BlueM = 1.25, $GreenM = 1.50
    $index += 0.0075
    $color = "0x2F" & Hex(255 * ((Sin($index * $RedM) + 1) / 2), 2) & Hex(255 * ((Sin($index * $GreenM) + 1) / 2), 2) & Hex(255 * ((Sin($index * $BlueM) + 1) / 2), 2)
    $hPen = _GDIPlus_PenCreate($color)
    EndFunc ;==>Line_Color

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

    Func Quit() ; exit program
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>Quit

    [/autoit]
  • Das kann ja nicht gehen, wenn du nur eine Variable veränderst!

    Spoiler anzeigen
    [autoit]

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

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

    Global $index, $hPen
    Global Const $Pi = 4 * ATan(1)
    Global $x1 = @DesktopWidth / 2
    Global $y1 = @DesktopHeight / 2
    Global $x2 = 0, $y2 = 0
    Global $radians = 180 * 2.50
    Global $i

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

    $GUI_Handle = GUICreate("GDI+", 1024, 768)
    GUISetBkColor(0x000000)
    GUISetState(@SW_SHOW)
    $hWnd = WinGetHandle($GUI_Handle)

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

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4) ; AntiAlias

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

    Line_Color()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Quit()

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

    EndSwitch

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

    _GDIPlus_GraphicsDrawLine($hGraphic, $x1, $y1, $x2, $y2, $hPen) ;draw line
    _GDIPlus_PenDispose($hPen)
    Line_Color()

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

    If $x2 < @DesktopWidth And $y2 = 0 Then
    $x2 += 1
    ElseIf $x2 = @DesktopWidth And $y2 < @DesktopHeight Then
    $y2 +=1
    ElseIf $y2 = @DesktopHeight And $x2 > 0 Then
    $x2 -= 1
    Else
    $y2 -=1
    EndIf

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

    ;~ Sleep(10)
    WEnd

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

    Func Line_Color() ;thanks to monoceres for the code
    Local $RedM = 1, $BlueM = 1.25, $GreenM = 1.50
    $index += 0.0075
    $color = "0x2F" & Hex(255 * ((Sin($index * $RedM) + 1) / 2), 2) & Hex(255 * ((Sin($index * $GreenM) + 1) / 2), 2) & Hex(255 * ((Sin($index * $BlueM) + 1) / 2), 2)
    $hPen = _GDIPlus_PenCreate($color)
    EndFunc ;==>Line_Color

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

    Func Quit() ; exit program
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>Quit

    [/autoit]
  • Hier mein Vorschlag:

    Spoiler anzeigen


    ;code by UEZ
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>


    Global Const $width = 800
    Global Const $height = 800
    Global $graphics, $backbuffer, $bitmap, $hPen, $i, $pi_div_180 = 4 * ATan(1) / 180, $index, $color
    Global $radius_x = ($width * 0.5) * 0.90, $radius_y = ($height * 0.5) * 0.90
    Global $title = "GDI+ Beispiel"

    Opt("GUIOnEventMode", 1)
    $hwnd = GUICreate($title, $width, $height, -1, -1, BitOR($WS_SYSMENU,$WS_DLGFRAME,$WS_POPUP))
    GUISetOnEvent($GUI_EVENT_CLOSE, "close")
    GUISetState()

    _GDIPlus_Startup()
    $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 8)
    _GDIPlus_GraphicsClear($backbuffer)
    Do
    Line_Color()
    ;~ _GDIPlus_GraphicsClear($backbuffer)
    ;~ _GDIPlus_GraphicsDrawEllipse($backbuffer, $width * 0.5 + Cos($i * $pi_div_180) * $radius_x, $height * 0.5 + Sin($i * $pi_div_180) * $radius_y, 1, 1, $hPen)
    _GDIPlus_GraphicsDrawLine($backbuffer, $width / 2, $height / 2, $width * 0.5 + Cos($i * $pi_div_180) * $radius_x, $height * 0.5 + Sin($i * $pi_div_180) * $radius_y, $hPen)
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    $i += 1
    If $i >= 360 Then $i = 0
    Sleep(10)
    Until False

    Func Line_Color()
    Local $RedM = 1, $BlueM = 1.25, $GreenM = 1.50
    $index += 0.075
    $color = "0xFF" & Hex(255 * ((Sin($index * $RedM) + 1) / 2), 2) & Hex(255 * ((Sin($index * $GreenM) + 1) / 2), 2) & Hex(255 * ((Sin($index * $BlueM) + 1) / 2), 2)
    _GDIPlus_PenSetColor($hPen, $color)
    EndFunc ;==>Line_Color

    Func close()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    WinClose($hwnd)
    Exit
    EndFunc

    Das Problem ist hier in meinem Bsp. nicht GDI+, sondern die Mathematik (Trigonometrie) :D

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    4 Mal editiert, zuletzt von UEZ (3. September 2009 um 20:39)