Skip to content

Commit 1aed035

Browse files
StartAutomatingStartAutomating
authored andcommitted
feat: Turtle.StepSpiral ( Fixes #122 )
1 parent 2a50438 commit 1aed035

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Turtle.types.ps1xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,56 @@ foreach ($n in 1..$Points) {
13201320
$this.Rotate($Angle)
13211321
}
13221322

1323+
</Script>
1324+
</ScriptMethod>
1325+
<ScriptMethod>
1326+
<Name>StepSpiral</Name>
1327+
<Script>
1328+
&lt;#
1329+
.SYNOPSIS
1330+
Draws a step spiral
1331+
.DESCRIPTION
1332+
Draws a spiral as a series of steps.
1333+
1334+
Each step will draw a line, rotate, and increment the length of the next step.
1335+
1336+
By default, this creates an outward spiral.
1337+
1338+
To create an inward spiral, use a negative StepSize or StepCount.
1339+
#&gt;
1340+
param(
1341+
# The length of the first step
1342+
[double]$Length = 1,
1343+
# The angle to rotate after each step
1344+
[double]$Angle = 90,
1345+
# The amount of change per step
1346+
[double]$StepSize = 1,
1347+
# The number of steps.
1348+
[int]$StepCount = 20
1349+
)
1350+
1351+
# If the step size or count is negative
1352+
if (
1353+
($stepSize -lt 0 -or $stepCount -lt 0) -and
1354+
$Length -in 0,1 # and the length is either the default or zero
1355+
) {
1356+
# set the length to the correct maximim step size, so we can make an inward spiral.
1357+
$Length = ([Math]::Abs($stepSize) * [Math]::Abs($stepCount))
1358+
}
1359+
elseif ($length -eq 0) {
1360+
# If the length is empty, default it to the step size
1361+
$Length = $StepSize
1362+
}
1363+
1364+
# Perform the appropriate steps
1365+
foreach ($n in 1..([Math]::Abs($StepCount))) {
1366+
$this = $this.Forward($length).Rotate($angle)
1367+
$length += $stepSize
1368+
}
1369+
# and return ourself.
1370+
return $this
1371+
1372+
13231373
</Script>
13241374
</ScriptMethod>
13251375
<ScriptMethod>

0 commit comments

Comments
 (0)