Nirvana6 Posted May 6, 2012 Posted May 6, 2012 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 ?Thank you.
Kip Posted May 6, 2012 Posted May 6, 2012 Sin/Cos/Tan ? MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API.
Solution UEZ Posted May 6, 2012 Solution Posted May 6, 2012 (edited) Something like that here? expandcollapse popup#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 May 6, 2012 by UEZ Nirvana6 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Nirvana6 Posted May 6, 2012 Author Posted May 6, 2012 On 5/6/2012 at 5:50 PM, 'UEZ said: Something like that here? expandcollapse popup#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 !
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now