AU3两圆切示例
```#include <GUIConstantsEx.au3>
#include <GDIPLus.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
Global $gui, $pic, $circ1x, $circ1y, $circ1r, $s4, $s5, $circ2r, $msg
$gui = GUICreate("圆 测试", 800, 600)
$pic = GUICtrlCreatePic("", 0, 0, 600, 600)
GUICtrlCreateLabel("圆 1 x", 630, 35)
$circ1x = GUICtrlCreateSlider(600, 50, 200, 50)
GUICtrlSetLimit(-1, 600, 10)
GUICtrlSetData(-1, 400)
GUICtrlCreateLabel("圆 1 y", 630, 135)
$circ1y = GUICtrlCreateSlider(600, 150, 200, 50)
GUICtrlSetLimit(-1, 600, 10)
GUICtrlSetData(-1, 300)
GUICtrlCreateLabel("圆 1 半径", 630, 235)
$circ1r = GUICtrlCreateSlider(600, 250, 200, 50)
GUICtrlSetLimit(-1, 300, 10)
GUICtrlSetData(-1, 75)
GUICtrlCreateLabel("圆 2 x", 630, 335)
$circ2x = GUICtrlCreateSlider(600, 350, 200, 50)
GUICtrlSetLimit(-1, 600, 10)
GUICtrlSetData(-1, 300)
GUICtrlCreateLabel("圆 2 y", 630, 435)
$circ2y = GUICtrlCreateSlider(600, 450, 200, 50)
GUICtrlSetLimit(-1, 600, 10)
GUICtrlSetData(-1, 200)
GUICtrlCreateLabel("圆 2 半径", 630, 535)
$circ2r = GUICtrlCreateSlider(600, 550, 200, 50)
GUICtrlSetLimit(-1, 300, 10)
GUICtrlSetData(-1, 175)
GUISetState()
test($pic, 400, 300, 75, 300, 200, 175)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $circ1x, $circ1y, $circ1r, $circ2x, $circ2y, $circ2r
refresh()
EndSwitch
WEnd
Func refresh()
consolewrite("blarb" & @crlf)
Local $c1x, $c1y, $c1r, $c2x, $c2y, $c2r
$c1x = GUICtrlRead($circ1x)
$c1y = GUICtrlRead($circ1y)
$c1r = GUICtrlRead($circ1r)
$c2x = GUICtrlRead($circ2x)
$c2y = GUICtrlRead($circ2y)
$c2r = GUICtrlRead($circ2r)
$image = test($pic, $c1x, $c1y, $c1r, $c2x, $c2y, $c2r)
return $image
EndFunc
Func test($ctrl, $circ1x, $circ1y, $circ1r, $circ2x, $circ2y, $circ2r)
Local $hBmp, $hPen, $hBitmap1, $hGraphic, $hBitmap2, $OldBmp, $one, $two
$hBmp = _WinAPI_CreateBitmap(600, 600, 1, 32)
_GDIPlus_Startup()
$hPen = _GDIPlus_PenCreate(0xFFFFFFFF)
;~ ConsoleWrite("0x" & Hex(200 / $lines + 55,2) & "FFFFFF" & @crlf)
$hBitmap1 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4)
_GDIPlus_GraphicsDrawEllipse($hGraphic, $circ1x - ($circ1r), $circ1y - ($circ1r), $circ1r*2, $circ1r*2, $hPen)
_GDIPlus_GraphicsDrawEllipse($hGraphic, $circ2x - ($circ2r), $circ2y - ($circ2r), $circ2r*2, $circ2r*2, $hPen)
$var = intcircles($circ1x, $circ1y, $circ1r, $circ2x, $circ2y, $circ2r)
_GDIPlus_GraphicsDrawEllipse($hGraphic,$var[0] - 5,$var[1] - 5,10,10,$hPen)
_GDIPlus_GraphicsDrawEllipse($hGraphic,$var[2] - 5,$var[3] - 5,10,10,$hPen)
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
$oldbmp = GUICtrlSendMsg($ctrl, 0x0172, 0, $hBitmap2)
If $OldBmp Then _WinAPI_DeleteObject($OldBmp)
_WinAPI_DeleteObject($hBitmap2)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hBitmap1)
_GDIPlus_PenDispose($hPen)
_GDIPlus_Shutdown()
_WinAPI_DeleteObject($hBmp)
EndFunc ;==>fracircle
Func Angle($x1, $y1, $Ang, $Length, $round = 0)
If $Ang >= 360 Then $Ang -= 360
Local $Return[2]
$Return[0] = $x1 + ($Length * Cos($Ang / 180 * 3.14159265358979))
$Return[1] = $y1 - ($Length * Sin($Ang / 180 * 3.14159265358979))
If $round = 1 Then
$Return[0] = Round($Return[0])
$Return[1] = Round($Return[1])
EndIf
Return $Return
EndFunc ;==>Angle
func intcircles($x0,$y0,$r1,$x1,$y1,$r2)
Local $xp2, $yp2, $dx, $dy, $d
Local $return[4]
$dx = $x1 - $x0;
$dy = $y1 - $y0;
$d = sqrt(($x1 - $x0)^2 + ($y1 - $y0)^2)
If ($d > ($r1 + $r2)) or ($d < ($r1 - $r2)) Then
SetError(1);unsaluveable
Return $return
EndIf
;Determine the distance from point 0 to point 2.
$a = ($r1^2 - $r2^2 + $d^2) / (2.0 * $d)
;Determine the coordinates of point 2. */
$x2 = $x0 + ($dx * $a/$d);
$y2 = $y0 + ($dy * $a/$d);
;Determine the distance from point 2 to either of the intersection points.
$h = sqrt(($r1*$r1) - ($a*$a))
; Now determine the offsets of the intersection points from point 2.
$rx = -$dy * ($h/$d);
$ry = $dx * ($h/$d);
; Determine the absolute intersection points. ;
$return[0] = ($x2 + $rx);+($d/2)
$return[2] = ($x2 - $rx);+($d/2)
$return[1] = ($y2 + $ry);-($d/2)
$return[3] = ($y2 - $ry);-($d/2)
ConsoleWrite("$a = " & $a & @crlf)
ConsoleWrite("$d = " & $d & @crlf)
ConsoleWrite("$dx = " & $dx & @crlf)
ConsoleWrite("$dy = " & $dy & @crlf)
ConsoleWrite("$return 1 = " & $return[0] & @crlf)
ConsoleWrite("$return 2 = " & $return[1] & @crlf)
ConsoleWrite("$return 3 = " & $return[2] & @crlf)
ConsoleWrite("$return 4 = " & $return[3] & @crlf)
return $return
EndFunc
```
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!