Alex1986 Posted May 24, 2018 Share Posted May 24, 2018 (edited) Hello i have problem in the code code: expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> AutoItSetOption("MouseCoordMode", 2) AutoItSetOption("GUIOnEventMode", 1) Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0 Global Const $hGUI = GUICreate("", $iW, $iH) GUISetBkColor($iBgColor, $hGUI) GUISetState() _GDIPlus_Startup() Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global Const $hPen1 = _GDIPlus_PenCreate(0xFF0000FF) Global Const $hPen2 = _GDIPlus_PenCreate(0xFFFF0000) Global Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 5) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4) Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300 Global Const $fDeg = ACos(-1) / 180, $fRad = 180 / ACos(-1), $iWh = $iW / 2, $iHh = $iH / 2 Global $fDiameter1 = 30, $fRadius1 = $fDiameter1 / 2, _ ;circle 1 $fDiameter2 = 30, $fRadius2 = $fDiameter2 / 2, _ ;circle 2 $mpos, $mwx, $mwy, $pd GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Do _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor) _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen1) $iWidthh = @DesktopWidth $iHeighth = @DesktopHeight ; circle1 _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh - $fRadius1, $iHh - $fRadius1, $fDiameter1 , $fDiameter1 , $hPen1) _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh , $iHh , 1 , 1 , $hPen1) ; circle2 $mpos = MouseGetPos() ;get the mouse position $mwx = $mpos[0] - $iWh ;get the x coordinate $mwy = $iHh - $mpos[1] ;get the y coordinate $pd = Sqrt($iWh * $iHh + $mpos[0] * $mpos[1]) ;calculate the distance between mouse position and center $fAngle = 2 * -ATan($mwy / ($mwx + Sqrt($mwx * $mwx + $mwy * $mwy))) * $fRad ; calculate the angle between center and mouse position -> trigonometry ;-) $fDistance = $fRadius2 + $fRadius1 ;calculate the distance between both circles so that they always touch each other ;calculate x/y position of 2nd circle with a little adjustment $X1 = $iWh - $fRadius2 + Cos($fAngle * $fDeg) * ($fDistance + 1) $Y1 = $iHh - $fRadius2 + Sin($fAngle * $fDeg) * ($fDistance + 1) $hPos = MouseGetPos() $iWidthh = $iWh $iHeighth = $iHh $iMPosX = $hPos[0] < $iPosX ? $iPosX : $hPos[0] > $iPosX + $iWidthh ? $iPosX + $iWidthh : $hPos[0] $iMPosY = $hPos[1] < $iPosY ? $iPosY : $hPos[1] > $iPosY + $iHeighth ? $iPosY + $iHeighth : $hPos[1] $X1 = $iWh - $fRadius2 + Cos($fAngle * $fDeg) * ($fDistance + 1) $Y1 = $iHh - $fRadius2 + Sin($fAngle * $fDeg) * ($fDistance + 1) $X2 = $iWh - $fRadius1 + Cos($fAngle * $fDeg) * ($fDistance - $iMPosX) $Y2 = $iHh - $fRadius1 + Sin($fAngle * $fDeg) * ($fDistance - $iMPosY) _GDIPlus_GraphicsDrawEllipse($hCtxt , $X1 + $fRadius2, $Y1 + $fRadius2 , 1, 1, $hPen2) ;center of circle 2 _GDIPlus_GraphicsDrawEllipse($hCtxt , $X1 , $Y1 , $fDiameter2 , $fDiameter2 , $hPen2) ;circle 2 _GDIPlus_GraphicsDrawline($hCtxt , $X1 + $fRadius2 , $Y1 + $fRadius2 , $X2 + $fRadius2 , $Y2 + $fRadius2 , $hPen2) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) Until Not Sleep(30) Func _Exit() _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_PenDispose($hPen1) _GDIPlus_PenDispose($hPen2) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc I want to reflect the line inside the rectangle, and also the red line does not cut the mid-diameter of the blue circle well Edited May 25, 2018 by Alex1986 Link to comment Share on other sites More sharing options...
Alex1986 Posted May 24, 2018 Author Share Posted May 24, 2018 ,..... Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 24, 2018 Moderators Share Posted May 24, 2018 (edited) @Alex1986 please do not bump your post without waiting 24 hours. Everyone here is a volunteer, and the person best suited to answer the question may be on the other side of the world. This may be the most important thing in the world to you, but show some patience. Edited May 24, 2018 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Alex1986 Posted May 25, 2018 Author Share Posted May 25, 2018 (edited) No one wants to help me posted the topic 24 hours ago. this simple code , to make it easier for you to help me #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() Edited May 25, 2018 by Alex1986 Link to comment Share on other sites More sharing options...
Alex1986 Posted May 27, 2018 Author Share Posted May 27, 2018 up , 48 h Link to comment Share on other sites More sharing options...
seandisanti Posted May 27, 2018 Share Posted May 27, 2018 I'm sorry, I'm not really sure what you're asking. Are you getting an error with your code? What is it doing that it shouldn't be doing, or what do you need help with? Link to comment Share on other sites More sharing options...
LarsJ Posted May 27, 2018 Share Posted May 27, 2018 You can start with this: expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> AutoItSetOption("MouseCoordMode", 2) AutoItSetOption("GUIOnEventMode", 1) Global Const $iW = 400, $iH = 400, $iBgColor = 0xF0F0F0 Global Const $hGUI = GUICreate("", $iW, $iH) GUISetBkColor($iBgColor, $hGUI) GUISetState() _GDIPlus_Startup() Global Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global Const $hPen1 = _GDIPlus_PenCreate(0xFF0000FF) ; blå Global Const $hPen2 = _GDIPlus_PenCreate(0xFFFF0000) Global Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 5) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4) Global Const $iPosX = 50, $iPosY = 50, $iWidth = 300, $iHeight = 300 Global Const $fDeg = ACos(-1) / 180, $fRad = 180 / ACos(-1), $iWh = $iW / 2, $iHh = $iH / 2 Global $fDiameter = 30, $fRadius = $fDiameter / 2, _ ; circles $mpos, $mwx, $mwy, $pd GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Do _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor) _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hPen1) $iWidthh = @DesktopWidth $iHeighth = @DesktopHeight ; circle1 _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh - $fRadius, $iHh - $fRadius, $fDiameter , $fDiameter , $hPen1) _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh , $iHh , 1 , 1 , $hPen1) ; circle2 $mpos = MouseGetPos() ;get the mouse position $mwx = $mpos[0] - $iWh ;get the x coordinate $mwy = $iHh - $mpos[1] ;get the y coordinate $pd = Sqrt($iWh * $iHh + $mpos[0] * $mpos[1]) ;calculate the distance between mouse position and center $fAngle = 2 * -ATan($mwy / ($mwx + Sqrt($mwx * $mwx + $mwy * $mwy))) * $fRad ; calculate the angle between center and mouse position -> trigonometry ;-) $fDistance = $fDiameter ;calculate the distance between both circles so that they always touch each other ;calculate x/y position of 2nd circle with a little adjustment $x = $iWh - $fRadius + Cos($fAngle * $fDeg) * ($fDistance + 1) $y = $iHh - $fRadius + Sin($fAngle * $fDeg) * ($fDistance + 1) $hPos = MouseGetPos() $iWidthh = $iWh $iHeighth = $iHh $iMPosX = $hPos[0] < $iPosX ? $iPosX : $hPos[0] > $iPosX + $iWidthh ? $iPosX + $iWidthh : $hPos[0] $iMPosY = $hPos[1] < $iPosY ? $iPosY : $hPos[1] > $iPosY + $iHeighth ? $iPosY + $iHeighth : $hPos[1] $x = $iWh + Cos($fAngle * $fDeg) * ($fDistance + 1) $y = $iHh + Sin($fAngle * $fDeg) * ($fDistance + 1) _GDIPlus_GraphicsDrawEllipse($hCtxt , $x, $y, 1, 1, $hPen2) ;center of circle 2 _GDIPlus_GraphicsDrawEllipse($hCtxt , $x - $fRadius , $y - $fRadius , $fDiameter , $fDiameter , $hPen2) ;circle 2 ;_GDIPlus_GraphicsDrawline($hCtxt , $x, $y, 200 , 200 , $hPen2) $m = ( 200 - $y ) / ( 200 - $x ) ; slope $fSqrt = 4 * Sqrt( $fDiameter ) If $x < 200 - $fSqrt Then ; Right line section $x1 = $x $y1 = $m * $x1 - $m * 200 + 200 $x2 = 350 $y2 = $m * $x2 - $m * 200 + 200 _GDIPlus_GraphicsDrawline($hCtxt, $x1, $y1, $x2, $y2, $hPen2) _GDIPlus_GraphicsDrawline($hCtxt, $x2, $y2, $x1, $y2 + $y2 - $y1, $hPen2) ElseIf $x >= 200 - $fSqrt And $x <= 200 + $fSqrt Then If $y < 200 Then ; Bottom line section $y1 = $y $x1 = ( $y1 - 200 ) / $m + 200 $y2 = 350 $x2 = ( $y2 - 200 ) / $m + 200 _GDIPlus_GraphicsDrawline($hCtxt, $x1, $y1, $x2, $y2, $hPen2) _GDIPlus_GraphicsDrawline($hCtxt, $x2, $y2, $x2 + $x2 - $x1, $y1, $hPen2) Else ; Top line section $y1 = $y $x1 = ( $y1 - 200 ) / $m + 200 $y2 = 50 $x2 = ( $y2 - 200 ) / $m + 200 _GDIPlus_GraphicsDrawline($hCtxt, $x1, $y1, $x2, $y2, $hPen2) _GDIPlus_GraphicsDrawline($hCtxt, $x2, $y2, $x2 + $x2 - $x1, $y1, $hPen2) EndIf Else ; $x > 200 + $fSqrt ; Left line section $x1 = $x $y1 = $m * $x1 - $m * 200 + 200 $x2 = 50 $y2 = $m * $x2 - $m * 200 + 200 _GDIPlus_GraphicsDrawline($hCtxt, $x1, $y1, $x2, $y2, $hPen2) _GDIPlus_GraphicsDrawline($hCtxt, $x2, $y2, $x1, $y2 + $y2 - $y1, $hPen2) EndIf _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($hPen1) _GDIPlus_PenDispose($hPen2) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc Alex1986 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted May 28, 2018 Share Posted May 28, 2018 The zip file below contains small scripts that develops the code in five steps. The final GUI looks like this: When you move the mouse in a circle, the red circle rolls around the periphery of the blue circle. From the center of the red circle, a line is drawn through the center of the blue circle until it hits one of the edges of the square. Here the line is reflected until it hits a new edge and is reflected again. Note check for invalid angles this way: If $fAngle == "-1.#IND" Then You should try it. It looks pretty amazing. Alex1986, Interesting topic. Reflection.7z Alex1986 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Alex1986 Posted June 4, 2018 Author Share Posted June 4, 2018 (edited) Thank You LarsJ If the rectangular shape is how we do this Why is this number 200 repeated and 350 ? $m = ( 200 - $y ) / ( 200 - $x ) ; Slope If $x <= 200 - $fSqrt Or $x > 200 + $fSqrt Then ; Right/left line sections of square $x1 = $x $y1 = $m * $x1 - $m * 200 + 200 $x2 = $x < 200 ? 350 : 50 $y2 = $m * $x2 - $m * 200 + 200 _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) ElseIf $x > 200 - $fSqrt And $x <= 200 + $fSqrt Then ; Bottom/top line sections of square $y1 = $y $x1 = ( $y1 - 200 ) / $m + 200 $y2 = $y < 200 ? 350 : 50 $x2 = ( $y2 - 200 ) / $m + 200 _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) EndIf expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> AutoItSetOption( "GUIOnEventMode", 1 ) AutoItSetOption( "MouseCoordMode", 2 ) AutoItSetOption( "MustDeclareVars", 1 ) Global $iW = 600, $iH = 400, $iBgColor = 0xF0F0F0 Global $hGUI = GUICreate("", $iW, $iH) _GDIPlus_Startup() Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBlue = _GDIPlus_PenCreate(0xFF0000FF) ; Blue Global $hRed = _GDIPlus_PenCreate(0xFFFF0000) ; Red Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) Example() Func Example() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor($iBgColor, $hGUI) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 5) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4) Local $iPosX = 25, $iPosY = 50, $iWidth = 550, $iHeight = 300 Local $fDeg = ACos(-1) / 180, $fRad = 180 / ACos(-1), $iWh = $iW / 2, $iHh = $iH / 2 Local $fDiameter = 30, $fRadius = $fDiameter / 2, _ $mpos, $mwx, $mwy, $pd, $fAngle, $fDistance, $x, $y Local $m, $fSqrt = 4 * Sqrt( $fDiameter ), $x1, $y1, $x2, $y2 GUISetState() Do ; Square _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor) _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hBlue) ; Blue circle _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh - $fRadius, $iHh - $fRadius, $fDiameter , $fDiameter , $hBlue) _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh , $iHh , 1 , 1 , $hBlue) ; Red circle $mpos = MouseGetPos() ;get the mouse position $mwx = $mpos[0] - $iWh ;get the x coordinate $mwy = $iHh - $mpos[1] ;get the y coordinate $fAngle = 2 * -ATan($mwy / ($mwx + Sqrt($mwx * $mwx + $mwy * $mwy))) * $fRad ; calculate the angle between center and mouse position -> trigonometry ;-) $fDistance = $fRadius + $fRadius ;calculate the distance between both circles so that they always touch each other ; Center of red circle If $fAngle == "-1.#IND" Then $x = 169 $y = 200 Else $x = $iWh + Cos($fAngle * $fDeg) * ($fDistance + 1) $y = $iHh + Sin($fAngle * $fDeg) * ($fDistance + 1) EndIf _GDIPlus_GraphicsDrawEllipse( $hCtxt, $x, $y, 1, 1, $hRed ) ; Draw center of red circle _GDIPlus_GraphicsDrawEllipse( $hCtxt, $x - $fRadius, $y - $fRadius, $fDiameter, $fDiameter, $hRed ) ; Draw red circle ; Draw line from red center to square $m = ( 200 - $y ) / ( 200 - $x ) ; Slope If $x <= 200 - $fSqrt Or $x > 200 + $fSqrt Then ; Right/left line sections of square $x1 = $x $y1 = $m * $x1 - $m * 200 + 200 $x2 = $x < 200 ? 350 : 50 $y2 = $m * $x2 - $m * 200 + 200 _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) ElseIf $x > 200 - $fSqrt And $x <= 200 + $fSqrt Then ; Bottom/top line sections of square $y1 = $y $x1 = ( $y1 - 200 ) / $m + 200 $y2 = $y < 200 ? 350 : 50 $x2 = ( $y2 - 200 ) / $m + 200 _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) EndIf _GDIPlus_GraphicsDrawImageRect( $hGraphic, $hBitmap, 0, 0, $iW, $iH ) ; Draw square Until Not Sleep(10) EndFunc Func _Exit() _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_PenDispose($hBlue) _GDIPlus_PenDispose($hRed) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc Edited June 4, 2018 by Alex1986 Link to comment Share on other sites More sharing options...
LarsJ Posted June 6, 2018 Share Posted June 6, 2018 (edited) The coordinates of the circle center and the sides of the rectangle are used all the time and are therefore repeated many times. The zip file below contains small scripts that develops the code in five steps. This is the final code: expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> AutoItSetOption( "GUIOnEventMode", 1 ) AutoItSetOption( "MouseCoordMode", 2 ) AutoItSetOption( "MustDeclareVars", 1 ) Global $iW = 600, $iH = 400, $iBgColor = 0xF0F0F0 Global $hGUI = GUICreate("", $iW, $iH) _GDIPlus_Startup() Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBlue = _GDIPlus_PenCreate(0xFF0000FF) ; Blue Global $hRed = _GDIPlus_PenCreate(0xFFFF0000) ; Red Global $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) Example() Func Example() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor($iBgColor, $hGUI) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 5) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, 4) Local $iPosX = 25, $iPosY = 25, $iWidth = 550, $iHeight = 350, $fSlope = $iHeight / $iWidth Local $fDeg = ACos(-1) / 180, $fRad = 180 / ACos(-1), $iWh = $iW / 2, $iHh = $iH / 2 Local $fDiameter = 30, $fRadius = $fDiameter / 2, _ $mpos, $mwx, $mwy, $pd, $fAngle, $fDistance, $x, $y Local $m1, $m2, $x1, $y1, $x2, $y2, $i = 1 GUISetState() Do ; Square _GDIPlus_GraphicsClear($hCtxt, 0xFF000000 + $iBgColor) _GDIPlus_GraphicsDrawRect($hCtxt, $iPosX, $iPosY, $iWidth, $iHeight, $hBlue) ; Blue circle _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh - $fRadius, $iHh - $fRadius, $fDiameter , $fDiameter , $hBlue) _GDIPlus_GraphicsDrawEllipse($hCtxt , $iWh , $iHh , 1 , 1 , $hBlue) ; Red circle $mpos = MouseGetPos() ;get the mouse position $mwx = $mpos[0] - $iWh ;get the x coordinate $mwy = $iHh - $mpos[1] ;get the y coordinate $fAngle = 2 * -ATan($mwy / ($mwx + Sqrt($mwx * $mwx + $mwy * $mwy))) * $fRad ; calculate the angle between center and mouse position -> trigonometry ;-) $fDistance = $fRadius + $fRadius ;calculate the distance between both circles so that they always touch each other ; Center of red circle If $fAngle == "-1.#IND" Then $x = 269 $y = 200 Else $x = $iWh + Cos($fAngle * $fDeg) * ($fDistance + 1) $y = $iHh + Sin($fAngle * $fDeg) * ($fDistance + 1) EndIf _GDIPlus_GraphicsDrawEllipse( $hCtxt, $x, $y, 1, 1, $hRed ) ; Draw center of red circle _GDIPlus_GraphicsDrawEllipse( $hCtxt, $x - $fRadius, $y - $fRadius, $fDiameter, $fDiameter, $hRed ) ; Draw red circle ;_GDIPlus_GraphicsDrawline( $hCtxt, $x, $y, 300, 200, $hRed ) ; Draw line from red center to blue center #cs Formulas Slope for line through points a and b $m = ( $yb - $ya ) / ( $xb - $xa ) => $m * ( $xb - $xa ) = ( $yb - $ya ) => Calculate $xa if $ya is known $xb - $xa = ( $yb - $ya ) / $m => -$xa = ( $yb - $ya ) / $m - $xb => $xa = $xb - ( $yb - $ya ) / $m Calculate $ya if $xa is known $yb - $ya = $m * ( $xb - $xa ) => -$ya = $m * ( $xb - $xa ) - $yb => $ya = $yb - $m * ( $xb - $xa ) #ce ; Draw line from red center to rectangle $m1 = ( 200 - $y ) / ( 300 - $x ) ; Slope If $m1 > -$fSlope And $m1 < $fSlope Then ; Right/left line sections of rectangle $x1 = $x $y1 = $m1 * $x1 - $m1 * 300 + 200 $x2 = $x < 300 ? 575 : 25 $y2 = $m1 * $x2 - $m1 * 300 + 200 _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) ; Draw first reflection line (mirror line) ; The line starts in $x2, $y2 where the previous line stopped ; The end point $x1, $y2 + $y2 - $y1 is the reflection of the previous start point about the horizontal line $y = $y2 ;_GDIPlus_GraphicsDrawline( $hCtxt, $x2, $y2, $x1, $y2 + $y2 - $y1, $hRed ) ; Note that this part of the code is still about the red line from the center of the red circle to the right/left line sections of the rectangle ; The first reflection line we drew above is either too short or too long, it should end exactly on one of the four rectangle lines ; From the start and end points of the first reflection line we can calculate the slope of the line $m2 = ( $y2 - $y1 ) / ( $x1 - $x2 ) ; $m2 = ( $yb - $ya ) / ( $xb - $xa ) with a = ($x2, $y2) and b = ($x1, $y2 + $y2 - $y1) $y1 = $y2 + $y2 - $y1 $y1 = $y1 < 200 ? 25 : 375 ; $ya is known $x1 = $x2 - ( $y2 - $y1 ) / $m2 ; $xa = $xb - ( $yb - $ya ) / $m If $x1 < 25 Or $x1 > 575 Then $x1 = $x1 < 25 ? 25 : 575 ; $xa is known $y1 = $y2 - $m2 * ( $x2 - $x1 ) ; $ya = $yb - $m * ( $xb - $xa ) EndIf _GDIPlus_GraphicsDrawline( $hCtxt, $x2, $y2, $x1, $y1, $hRed ) ; Draw second reflection line, slope = $m1 If $y1 > 25 And $y1 < 375 Then $y2 = $y1 < 200 ? 25 : 375 ; $ya is known $x2 = $x1 - ( $y1 - $y2 ) / $m1 ; $xa = $xb - ( $yb - $ya ) / $m If $x2 < 25 Or $x2 > 575 Then $x2 = $x2 < 25 ? 25 : 575 ; $xa is known $y2 = $y1 - $m1 * ( $x1 - $x2 ) ; $ya = $yb - $m * ( $xb - $xa ) EndIf Else ; $y1 = 25 Or $y1 = 375 $x2 = $x < 300 ? 25 : 575 ; $xa is known $y2 = $y1 - $m1 * ( $x1 - $x2 ) ; $ya = $yb - $m * ( $xb - $xa ) EndIf _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) Else ; Bottom/top line sections of rectangle $y1 = $y $x1 = ( $y1 - 200 ) / $m1 + 300 $y2 = $y < 200 ? 375 : 25 $x2 = ( $y2 - 200 ) / $m1 + 300 _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) ;_GDIPlus_GraphicsDrawline( $hCtxt, $x2, $y2, $x2 + $x2 - $x1, $y1, $hRed ) $m2 = ( $y1 - $y2 ) / ( $x2 - $x1 ) ; $m2 = ( $yb - $ya ) / ( $xb - $xa ) with a = ($x2, $y2) and b = ($x2 + $x2 - $x1, $y1) $x1 = $x2 + $x2 - $x1 $x1 = $x1 < 300 ? 25 : 575 ; $xa is known $y1 = $y2 - $m2 * ( $x2 - $x1 ) ; $ya = $yb - $m * ( $xb - $xa ) If $y1 < 25 Or $y1 > 375 Then $y1 = $y1 < 25 ? 25 : 375 ; $ya is known $x1 = $x2 - ( $y2 - $y1 ) / $m2 ; $xa = $xb - ( $yb - $ya ) / $m EndIf _GDIPlus_GraphicsDrawline( $hCtxt, $x2, $y2, $x1, $y1, $hRed ) ; Draw second reflection line, slope = $m1 If $x1 > 25 And $x1 < 575 Then $x2 = $x1 < 300 ? 25 : 575 ; $xa is known $y2 = $y1 - $m1 * ( $x1 - $x2 ) ; $ya = $yb - $m * ( $xb - $xa ) If $y2 < 25 Or $y2 > 375 Then $y2 = $y2 < 25 ? 25 : 375 ; $ya is known $x2 = $x1 - ( $y1 - $y2 ) / $m1 ; $xa = $xb - ( $yb - $ya ) / $m EndIf Else ; $x1 = 25 Or $x1 = 575 $y2 = $y < 200 ? 25 : 375 ; $ya is known $x2 = $x1 - ( $y1 - $y2 ) / $m1 ; $xa = $xb - ( $yb - $ya ) / $m EndIf _GDIPlus_GraphicsDrawline( $hCtxt, $x1, $y1, $x2, $y2, $hRed ) EndIf _GDIPlus_GraphicsDrawImageRect( $hGraphic, $hBitmap, 0, 0, $iW, $iH ) ; Draw square Until Not Sleep(10) EndFunc Func _Exit() _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_PenDispose($hBlue) _GDIPlus_PenDispose($hRed) _GDIPlus_Shutdown() GUIDelete() Exit EndFunc ReflectionRect.7z Edited June 6, 2018 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
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