Skip to content

Commit 4592380

Browse files
feat: Turtle.Arcygon ( Fixes #359 )
1 parent 127ae05 commit 4592380

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

Types/Turtle/Arcygon.ps1

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<#
2+
.SYNOPSIS
3+
Draws an arcygon
4+
.DESCRIPTION
5+
Draws an arcygon.
6+
7+
An arcygon is a polygon with N sides, and an arc at each corner.
8+
9+
To draw a closed arcygon, provide a whole number of sides.
10+
11+
To draw an open arcygon, provide a fractial number of sides.
12+
13+
To draw a negative arcygon, provide a negative angle.
14+
.EXAMPLE
15+
# Arcygons have a side length, radius, and number of sides.
16+
turtle arcygon 42 21 3
17+
.EXAMPLE
18+
turtle arcygon 42 21 4
19+
.EXAMPLE
20+
turtle arcygon 21 42 4
21+
.EXAMPLE
22+
turtle arcygon 42 -21 4
23+
.EXAMPLE
24+
turtle arcygon -42 -21 4
25+
.EXAMPLE
26+
# we can make partial acygons
27+
turtle arcygon 42 42 4.2
28+
.EXAMPLE
29+
# we can morph partial acygons
30+
turtle arcygon 42 42 4.2 morph @(
31+
turtle arcygon 42 42 4.2
32+
turtle arcygon 42 42 4.999999
33+
)
34+
.EXAMPLE
35+
turtle arcygon 42 42 8
36+
.EXAMPLE
37+
turtle arcygon 42 3.001 morph @(
38+
turtle arcygon 42 42 3.001
39+
turtle arcygon 42 42 3.999
40+
turtle arcygon 42 42 3.001
41+
)
42+
.EXAMPLE
43+
turtle arcygon 42 4 morph @(
44+
turtle arcygon 42 42 4
45+
turtle arcygon 42 -42 4
46+
turtle arcygon 42 42 4
47+
)
48+
#>
49+
param(
50+
# The default size of each segment of the polygon
51+
[double]$Size = $(Get-Random -Min -42 -Max 42),
52+
53+
[double]$Radius = $(Get-Random -Min -42 -Max 42),
54+
# The number of sides in the polygon.
55+
# If this is not a whole number, the polygon will not be closed.
56+
[double]$SideCount = (Get-Random -Min 3 -Max 12)
57+
)
58+
59+
# Determine the absolute side count
60+
$absSideCount = [Math]::Abs($SideCount)
61+
# and, for each whole number between 1 and that side count
62+
$null = foreach ($n in 1..([Math]::Floor($absSideCount))) {
63+
# Rotate and move forward
64+
$this.
65+
CircleArc($radius, (360 / $SideCount)).
66+
Forward($Size).
67+
Rotate(360 / $SideCount)
68+
}
69+
# Determine if there was a remainder
70+
$remainder = $SideCount - [Math]::Floor($SideCount)
71+
# If there was not, return this polygon
72+
if (-not $remainder) { return $this }
73+
# Otherwise, we do one more partial rotation (multiplied by the remainder)
74+
# and draw one more line segment (multiplied by the remainder)
75+
# (the effect will be like watching a polygon close)
76+
$remainingAngle = (360 / $SideCount) * $remainder
77+
return $this.
78+
CircleArc($remainder * $Radius, $remainingAngle)
79+
Forward($remainder * $Size).
80+
Rotate($remainingAngle)
81+
# @('CircleArc',$radius, $angle, 'Forward', $length, 'Rotate', $angle * $n)
82+

0 commit comments

Comments
 (0)