Sign in to follow this  
Followers 0
Nirvana6

GDI+ questions

4 posts in this topic

I did some research regarding GDI+ but I still have some questions.

-I am looking for a way to animate drawn elements separately ;

e.g. rotate a line by 180 degrees step by step. Any suggestions other than keeping the first pair of coords (x1,y1) fixed , and use Posted Image?

Thank you.


Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Something like that here?

#include <gdiplus.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global Const $iW = 800
Global Const $iH = 500
Global Const $hGui = GUICreate("GDI+ Simple Line Rotation", $iW, $iH)
GUISetState()

_GDIPlus_Startup()
Global Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global Const $hPen = _GDIPlus_PenCreate(0xFFF0F0F0, 1)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
GUISetOnEvent(-3, "_Exit")

Global Const $fRadians = ACos(-1) / 180
Global Const $iRadius = 200
Global Const $iStart_deg = Random(-180, 180, 1)
Global $iSpeed = Random(-3, 3, 1)
Global Const $iCenterX = $iW / 2
Global Const $iCenterY = $iH / 2

AdlibRegister("Animate", 30)

While Sleep(1000)
WEnd

Func Animate()
    Local Static $degree = $iStart_deg
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    _GDIPlus_GraphicsDrawLine($hContext, $iCenterX, $iCenterY, _
                                                        $iCenterX + Cos($degree * $fRadians) * $iRadius, _
                                                        $iCenterY + Sin($degree * $fRadians) * $iRadius, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
    $degree = Mod($degree + $iSpeed, 180)
    If Not $degree Then
        $iSpeed *= -1
    EndIf
EndFunc

Func _Exit()
    AdlibUnRegister("Animate")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Something like that here?

#include <gdiplus.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global Const $iW = 800
Global Const $iH = 500
Global Const $hGui = GUICreate("GDI+ Simple Line Rotation", $iW, $iH)
GUISetState()

_GDIPlus_Startup()
Global Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global Const $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Global Const $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global Const $hPen = _GDIPlus_PenCreate(0xFFF0F0F0, 1)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
_GDIPlus_GraphicsClear($hContext, 0xFF000000)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
GUISetOnEvent(-3, "_Exit")

Global Const $fRadians = ACos(-1) / 180
Global Const $iRadius = 200
Global Const $iStart_deg = Random(-180, 180, 1)
Global $iSpeed = Random(-3, 3, 1)
Global Const $iCenterX = $iW / 2
Global Const $iCenterY = $iH / 2

AdlibRegister("Animate", 30)

While Sleep(1000)
WEnd

Func Animate()
    Local Static $degree = $iStart_deg
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    _GDIPlus_GraphicsDrawLine($hContext, $iCenterX, $iCenterY, _
                                                        $iCenterX + Cos($degree * $fRadians) * $iRadius, _
                                                        $iCenterY + Sin($degree * $fRadians) * $iRadius, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
    $degree = Mod($degree + $iSpeed, 180)
    If Not $degree Then
        $iSpeed *= -1
    EndIf
EndFunc

Func _Exit()
    AdlibUnRegister("Animate")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

Br,

UEZ

Perfect , thank you !

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