Created
February 20, 2012 12:30
-
-
Save maul-esel/1869007 to your computer and use it in GitHub Desktop.
Polygon - calculate the coordinates of a polygon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Function: Polygon | |
calculates the coordinates for a polygon | |
Parameters: | |
count - the number of corners the polygon should have | |
radius - the radius of the polygon | |
[opt, byRef] x - receives an array of the x-coordinates. Omit this if not needed. | |
[opt, byRef] y - receives an array of the y-coordinates. Omit this if not needed. | |
[opt] xoffset - an optional x-offset to add to the coordinates | |
[opt] yoffset - an optional y-offset to add to the coordinates | |
[opt] rotate - by default, the polygon is aligned so that one of the corners is the highest point. Change this by setting this param to the amount (in degree) to rotate the polygon. | |
Returns: | |
coords - a string containing the coordinates as x-y pairs, separated by a space. This is the form taken by the "WinSet Region" command. | |
*/ | |
Polygon(count, radius, byRef x := 0, byRef y := 0, xoffset := 0, yoffset := 0, rotate := 0) | |
{ | |
pi := 4 * ATan(1) | |
x := [], y := [], list := "" | |
Loop count | |
{ | |
arc := ((A_Index-1)/count + rotate/360) * (2 * pi) | |
x[A_Index] := round(radius + cos(arc)*radius + xoffset) | |
y[A_Index] := round(radius - sin(arc)*radius + yoffset) | |
list .= x[A_Index] . "-" . y[A_Index] . A_Space | |
} | |
return list . x[1] . "-" . y[1] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance force | |
Loop 20 | |
{ | |
Gui g%A_Index%: +LastFound +ToolWindow +AlwaysOnTop -Caption | |
width := A_Index * 20 | |
WinSet, Region, % Polygon(360, A_Index * 20) A_Space Polygon(360, width - 5,,, 5, 5) | |
Gui g%A_Index%: Color, % A_Index * 0x00FFFF | |
Gui g%A_Index%: Show, % "w" A_Index * 45 " h" A_Index * 45 " center" | |
} | |
Esc::ExitApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance force | |
Gui outer: +LastFound +ToolWindow +AlwaysOnTop -Caption | |
WinSet, Region, % Polygon(6, 200,,,,,30) A_Space Polygon(6, 190,,, 10, 10, 30) | |
Gui outer: Color, 0 | |
Gui outer: Show, w400 h400 center | |
Gui inner: +LastFound +ToolWindow +AlwaysOnTop -Caption | |
WinSet, Region, % Polygon(3, 165,,,35,35,-30) A_Space Polygon(3, 165,,, 35, 35, 30) | |
Gui inner: Color, 0 | |
Gui inner: Show, w400 h400 center | |
Esc::ExitApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Function: Polygon | |
calculates the coordinates for a polygon | |
Parameters: | |
count - the number of corners the polygon should have | |
radius - the radius of the polygon | |
[opt, byRef] x - receives an array of the x-coordinates. Omit this if not needed. | |
[opt, byRef] y - receives an array of the y-coordinates. Omit this if not needed. | |
[opt] xoffset - an optional x-offset to add to the coordinates | |
[opt] yoffset - an optional y-offset to add to the coordinates | |
[opt] rotate - by default, the polygon is aligned so that one of the corners is the highest point. Change this by setting this param to the amount (in degree) to rotate the polygon. | |
Returns: | |
coords - a string containing the coordinates as x-y pairs, separated by a space. This is the form taken by the "WinSet Region" command. | |
*/ | |
Polygon(count, radius, byRef x = 0, byRef y = 0, xoffset = 0, yoffset = 0, rotate = 0) | |
{ | |
pi := 4 * ATan(1) | |
x := [], y := [], list := "" | |
Loop % count | |
{ | |
arc := ((A_Index-1)/count + rotate/360) * (2 * pi) | |
x[A_Index] := round(radius + cos(arc)*radius + xoffset) | |
y[A_Index] := round(radius - sin(arc)*radius + yoffset) | |
list .= x[A_Index] . "-" . y[A_Index] . A_Space | |
} | |
return list . x[1] . "-" . y[1] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment