Jump to content

About Drawing Help


 Share

Recommended Posts

Hi

i need draw line in a rectangle , without leaving line out the rectangle

+ i need Line connects with the Mouse pointer without repeatint

this my code but there is problem :

#include <GDIplus.au3>

$hGUI = GUICreate("" , 400 ,400)
GUISetState()

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawRect($hGraphic , 1 + 400/7 , 1 + 400/7 , 300 , 300 , _gdiplus_pencreate())

Do
$hPos = GUIGetCursorInfo($hGUI)
ToolTip("X : " & $hPos[0] & " Y : " & $hPos[1] , 5 , 5)
if $hPos[0] > 358 Then
 $hPos[0] = 358
Elseif $hPos[0] < 58 Then
$hPos[0] = 58
Elseif $hPos[1] > 358 Then
$hPos[1] = 358
ElseIf $hPos[1] < 58 Then
$hPos[1] = 58
EndIf
_GDIPlus_GraphicsDrawline($hGraphic , 200 ,200 , $hPos[0] , $hPos[1],_gdiplus_pencreate())
until GuiGetmsg() = -3

_GDIPlus_GraphicsDispose($hGraphic)

 

Link to comment
Share on other sites

Try this:

#include <GDIplus.au3>

AutoItSetOption("MouseCoordMode", 0)

Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0
Global Const $hGUI = GUICreate("", $iW, $iH)
GUISetBkColor($iBgColor, $hGUI)
GUISetState()

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 4)

Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300

Global $iMPosX, $iMPosY
Do
    _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor)
    _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen)
    $hPos = GUIGetCursorInfo($hGUI)
    $iMPosX = $hPos[0] < $iPosX ? $iPosX : $hPos[0] > $iPosX + $iWidth ? $iPosX + $iWidth : $hPos[0]
    $iMPosY = $hPos[1] < $iPosY ? $iPosY : $hPos[1] > $iPosY + $iHeight ? $iPosY + $iHeight : $hPos[1]
    _GDIPlus_GraphicsDrawLine($hCtxt, $iW / 2, $iH / 2, $iMPosX, $iMPosY, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
Until GUIGetMsg() = -3

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hCtxt)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_PenDispose($hPen)
_GDIPlus_Shutdown()
GUIDelete()

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

thank you UEZ

excuse me , plz fix this code :

#include <GDIplus.au3>

AutoItSetOption("MouseCoordMode", 0)

Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0
Global Const $hGUI = GUICreate("", $iW, $iH)
GUISetBkColor($iBgColor, $hGUI)
GUISetState()

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 4)

Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300

Global $iMPosX, $iMPosY

Local Const $fDeg = ACos(-1) / 180, $iRadius = 20, $iWh1 = $iW / 2, $iHh1 = $iH / 2
    Local $fAngle = 0
Do
    _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor)
    _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen)
    $hPos = GUIGetCursorInfo($hGUI)
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iW / 2 , $iH / 2 , 1 ,1 , _GDIPlus_PenCreate(0x99FF0000 , 2))

    ; circle1
    _GDIPlus_GraphicsDrawEllipse($hCtxt , 400/2 - 20   , 400/2 - 20   , 30 , 30 , $hPen)
    ; circle2
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 + Cos($fAngle * $fDeg) * $iRadius   ,$iHh1 + Sin($fAngle * $fDeg) * $iRadius , 30 , 30 , $hPen)

    $fAngle += 1

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
Until GUIGetMsg() = -3

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hCtxt)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_PenDispose($hPen)
_GDIPlus_Shutdown()
GUIDelete()

 

- How to put the circle1 in the middle

- How to Make the circle1 moving connected with the circle2

Link to comment
Share on other sites

Don't use

_GDIPlus_GraphicsDrawEllipse($hCtxt , $iW / 2 , $iH / 2 , 1 ,1 , _GDIPlus_PenCreate(0x99FF0000 , 2))

in a loop. This will cause a memory leak because a pen object will be created permantely!

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>

AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("GUIOnEventMode", 1)

Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0
Global Const $hGUI = GUICreate("", $iW, $iH)
GUISetBkColor($iBgColor, $hGUI)
GUISetState()

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
$hPen2 = _GDIPlus_PenCreate(0xFFFF0000, 2)
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 4)
_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4)

Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300

Global $iMPosX, $iMPosY

Local Const $fDeg = ACos(-1) / 180, $iRadius = 32, $iWh1 = $iW / 2, $iHh1 = $iH / 2
Local $fAngle = 0
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
    _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor)
    _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen)
;~  _GDIPlus_GraphicsDrawLine($hCtxt, 0, 0, $iW, $iH, $hPen)
;~  _GDIPlus_GraphicsDrawLine($hCtxt, $iW, 0, 0, $iH, $hPen)
    $hPos = GUIGetCursorInfo($hGUI)

    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1, $iHh1 , 1 ,1, $hPen2 )

    ; circle1
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 - 15, $iHh1 - 15, 30 , 30 , $hPen)
    ; circle2
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 - 15 + Cos($fAngle * $fDeg) * $iRadius   ,$iHh1 + - 15 + Sin($fAngle * $fDeg) * $iRadius , 30 , 30 , $hPen)

    $fAngle += 3

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
Until Not Sleep(10)

Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

How to Make the length of line the longest , while maintaining the balance between the line1 and line2

Untitled48e3.jpg

look this

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>

AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("GUIOnEventMode", 1)

Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0
Global Const $hGUI = GUICreate("", $iW, $iH)
GUISetBkColor($iBgColor, $hGUI)
GUISetState()

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
$hPen2 = _GDIPlus_PenCreate(0xFFFF0000, 2)
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 4)
_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4)

Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300

Global $iMPosX, $iMPosY

Local Const $fDeg = ACos(-1) / 180, $iRadius = 31, $iWh1 = $iW / 2, $iHh1 = $iH / 2
Local $fAngle = 0 , $fAngle2 = 155 , $fAngle3 =333

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
    _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor)
    _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen)
    $hPos = GUIGetCursorInfo($hGUI)

    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1, $iHh1 , 1 ,1, $hPen2 )

    ; circle1
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 - 15, $iHh1 - 15, 30 , 30 , $hPen)
    ; circle2
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 - 15 + Cos($fAngle * $fDeg) * $iRadius   ,$iHh1 + - 15 + Sin($fAngle * $fDeg) * $iRadius , 30 , 30 , $hPen)
    ;Line1
    _GDIPlus_GraphicsDrawLine($hCtxt, $iWh1 + Cos($fAngle3 * $fDeg) * $iRadius, $iHh1 +  Sin($fAngle3 * $fDeg) * $iRadius, _
    $iWh1 + Cos($fAngle3 * $fDeg + 180) * $iRadius, $iHh1 + Sin($fAngle3 * $fDeg + 180) * $iRadius, $hPen)
    ;line2
    _GDIPlus_GraphicsDrawLine($hCtxt, $iWh1 + Cos($fAngle2 * $fDeg) * $iRadius, $iHh1 + Sin($fAngle2 * $fDeg) * $iRadius, _
    $iWh1 + Cos($fAngle2 * $fDeg + 180) * $iRadius, $iHh1 + Sin($fAngle2  * $fDeg + 180) * $iRadius, $hPen)

    $fAngle += 1
    $fAngle2 += 1
    $fAngle3 += 1

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
Until Not Sleep(10)

Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

 

Edited by Alex1986
Link to comment
Share on other sites

Alex, please wait at least 24 hours before bumping a thread. This is no 24/7/365 service hotline ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>

AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("GUIOnEventMode", 1)

Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0
Global Const $hGUI = GUICreate("", $iW, $iH)
GUISetBkColor($iBgColor, $hGUI)
GUISetState()

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate()
$hPen2 = _GDIPlus_PenCreate(0xFFFF0000, 2)
$hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
$hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hCtxt, 4)
_GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4)

Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300

Global $iMPosX, $iMPosY

Local Const $fDeg = ACos(-1) / 180, $iRadius = 31, $iRadius2 = $iWidth / 2, $iWh1 = $iW / 2, $iHh1 = $iH / 2
Local $fAngle = 0 , $fAngle2 = 155 , $fAngle3 =333, $i = 0

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
    _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor)
    _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen)
    $hPos = GUIGetCursorInfo($hGUI)

    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1, $iHh1 , 1 ,1, $hPen2 )

    ; circle1
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 - 15, $iHh1 - 15, 30 , 30 , $hPen)
    ; circle2
    _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh1 - 15 + Cos($fAngle * $fDeg) * $iRadius   ,$iHh1 - 15 + Sin($fAngle * $fDeg) * $iRadius , 30 , 30 , $hPen)

    $iX1 = $iWh1 + Cos($fAngle3 * $fDeg) * $iRadius
    $iY1 = $iHh1 + Sin($fAngle3 * $fDeg) * $iRadius
    $iX2 = $iWh1 + Cos($fAngle3 * $fDeg + 180) * $iRadius
    $iY2 = $iHh1 + Sin($fAngle3 * $fDeg + 180) * $iRadius

    ;tangent1
    $i = 0.1 ;value depends on $iRadius2!
    $iX1 = $iWh1 + Cos($fAngle * $fDeg + $i) * $iRadius2
    $iY1 = $iHh1 + Sin($fAngle * $fDeg + $i) * $iRadius2
    $iX2 = $iWh1 + Cos((180 + $fAngle) * $fDeg - $i) * $iRadius2
    $iY2 = $iHh1 + Sin((180 + $fAngle) * $fDeg - $i) * $iRadius2
    _GDIPlus_GraphicsDrawLine($hCtxt, $iX1, $iY1, $iX2, $iY2, $hPen)

    ;tangent2
    $i = -0.1 ;value depends on $iRadius2!
    $iX1 = $iWh1 + Cos($fAngle * $fDeg + $i) * $iRadius2
    $iY1 = $iHh1 + Sin($fAngle * $fDeg + $i) * $iRadius2
    $iX2 = $iWh1 + Cos((180 + $fAngle) * $fDeg - $i) * $iRadius2
    $iY2 = $iHh1 + Sin((180 + $fAngle) * $fDeg - $i) * $iRadius2

    _GDIPlus_GraphicsDrawLine($hCtxt, $iX1, $iY1, $iX2, $iY2, $hPen)


    $fAngle += 1
    $fAngle2 += 1
    $fAngle3 += 1

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
Until Not Sleep(10)

Func _Exit()
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...