用鼠标动态画圆

已知圆心坐标O(x,y),圆上一点的坐标A(xA,yA),用鼠标从A点顺时针方向画指定的度数。

需要注意,X轴的正方向是→,Y轴的正方向是↓,按顺时针方向画圆实际上角度是越来越小。

解题思路:画圆可以将圆的360°角划分为N等分,这里就划分为360等分,再获取每个度数所对应的圆上的点的坐标来画点,由点连成一个圆。

原理是利用圆的参数方程:
横坐标X=圆心横坐标+半径*Cos(弧度)
横坐标Y=圆心纵坐标+半径*Sin(弧度)

autoit代码如下:

Run("mspaint.exe")



Sleep(2000) WinActivate("[class:MSPaintApp]") WinSetState("[class:MSPaintApp]", "", @SW_MAXIMIZE)
;以上是调起画图工具,在画图工具上画圆 _DrawCircleByPoint(400,400,500,300) Func _DrawCircleByPoint($iCenterX, $iCenterY, $iOnCircleX, $iOnCircleY, $iDegree = 360, $iDelay = 10, $iSpeed = 0, $pi = 3.14159265358979) Dim $iRadius = Sqrt(($iCenterX - $iOnCircleX) * ($iCenterX - $iOnCircleX) + ($iCenterY - $iOnCircleY) * ($iCenterY - $iOnCircleY)) ;get the radius If $iOnCircleX <= $iCenterX Then $doubleStartDegree = $pi - ACos(($iCenterX - $iOnCircleX)/$iRadius);二象限 If $iOnCircleY > $iCenterY Then $doubleStartDegree = ACos(($iCenterX - $iOnCircleX)/$iRadius) + $pi ;三象限 EndIf Else $doubleStartDegree = ACos(($iOnCircleX - $iCenterX)/$iRadius);一象限 If $iOnCircleY > $iCenterY Then $doubleStartDegree = 2*$pi - $doubleStartDegree;四象限 EndIf EndIf $doubleStartDegree = $doubleStartDegree * 180 /$pi ;get the degree _DrawCircle($iCenterX, $iCenterY, $iRadius, $doubleStartDegree, $iDegree, $iDelay, $iSpeed, $pi) EndFunc #cs $iCenterY = 圆心纵坐标 $iCenterX = 圆心横坐标 $iRadius = 圆半径 $iDegree = 圆弧度数,缺省为360° $iDelay = 鼠标移动延时,单位为毫秒,缺省为 10 $iSpeed = 鼠标移动速度,范围为 1(最快)-100(最慢),缺省为 0 $pi = 圆周率 pi,缺省为 3.14159265358979 eg:_Circle(@DesktopWidth / 2, @DesktopHeight / 2, 200, 180) #ce Func _DrawCircle($iCenterX, $iCenterY, $iRadius, $doubleStartDegree, $iDegree = 360, $iDelay = 10, $iSpeed = 0, $pi = 3.14159265358979) Local $iMouseX, $iMouseY For $i = $doubleStartDegree To $doubleStartDegree - $iDegree Step -1 $iMouseX = $iCenterX + $iRadius * Cos($i * $pi / 180) $iMouseY = $iCenterY - $iRadius * Sin($i * $pi / 180) ConsoleWrite($i & @CRLF) Sleep($iDelay) MouseMove($iMouseX, $iMouseY, $iSpeed) MouseDown("left") Next MouseUp("left") EndFunc ;==>_Circle

你可能感兴趣的:(动态)