Sign in to follow this  
Followers 0
oMBRa

gdi+ and ellipse

1 post in this topic

#1 ·  Posted (edited)

this is my script:

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

Opt("GuiOnEventMode", 1)
$size = 500
$hwnd = GUICreate("Test", $size, $size, -1, -1)
GUISetState()
GUISetOnEvent(-3, "close")
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($size, $size, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$pen = _GDIPlus_PenCreate(0xFF00FF00, 2)

_AntiAlias($backbuffer, 4)

Global $AsseMa = 200    ;bigger axis of the ellipse
Global $AsseMi = 140    ;shorter axis of the ellipse

Global $SAsseMa = $AsseMa / 2
Global $SAsseMi = $AsseMi / 2
Global $BaseX = $size / 2 - $SAsseMa
Global $BaseY = $size / 2 - $SAsseMi
Global $pi = 3.14159265358979
Global $F1 = Sqrt($SAsseMa ^ 2 - $SAsseMi ^ 2)
Global $F2 = -$F1
Global $a = Sqrt($F1 ^ 2 + $SAsseMi ^ 2)
Global $x = -$SAsseMa
Global $y = 0
Global $iFX = 10
Global $iFY = 1

Do

    _GDIPlus_GraphicsClear($backbuffer, 0xFF000000)
    _GDIPlus_GraphicsDrawEllipse($backbuffer, $BaseX, $BaseY, $SAsseMa * 2, $SAsseMi * 2, $pen)
    _GDIPlus_GraphicsDrawEllipse($backbuffer, $BaseX + $SAsseMa + $x, $BaseY + $SAsseMi + $y, 10, 10, $pen)
;~  _GDIPlus_GraphicsDrawEllipse($backbuffer, $BaseX + $SAsseMa + $F1, $BaseY + $SAsseMi, 1, 1, $pen)
;~  _GDIPlus_GraphicsDrawEllipse($backbuffer, $BaseX + $SAsseMa + $F2, $BaseY + $SAsseMi, 1, 1, $pen)
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $size, $size)
;~  MsgBox(0, '', $y&@CRLF&$X&@CR&$iFX)
        $x = $x + $iFX
    If $x >= $SAsseMa Then
        $iFX = -10
        $iFY = -1
    ElseIf $x <= -$SAsseMa Then
        $iFX = 10
        $iFY = 1
    EndIf
    $y = Sqrt((1 - (-$x ^ 2) / ($SAsseMa ^ 2)) * $SAsseMi ^ 2) * $iFY
    Sleep(10)
Until 0


Func close()
    _GDIPlus_GraphicsDispose($graphics)
    _WinAPI_DeleteObject($bitmap)
    _GDIPlus_PenDispose($pen)

    _GDIPlus_Shutdown()
    Exit
EndFunc ;==>close

Func _AntiAlias($hGraphics, $mode)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $mode)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_AntiAlias

the ''ball'' increases the speed when it reaches the end of the ellipse (and the beginning)...

how to solve this problem?

Edited by oMBra

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0