Skip to content

Commit 2a50438

Browse files
feat: Turtle.StepSpiral ( Fixes #122 )
1 parent 7fe0460 commit 2a50438

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Types/Turtle/StepSpiral.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<#
2+
.SYNOPSIS
3+
Draws a step spiral
4+
.DESCRIPTION
5+
Draws a spiral as a series of steps.
6+
7+
Each step will draw a line, rotate, and increment the length of the next step.
8+
9+
By default, this creates an outward spiral.
10+
11+
To create an inward spiral, use a negative StepSize or StepCount.
12+
#>
13+
param(
14+
# The length of the first step
15+
[double]$Length = 1,
16+
# The angle to rotate after each step
17+
[double]$Angle = 90,
18+
# The amount of change per step
19+
[double]$StepSize = 1,
20+
# The number of steps.
21+
[int]$StepCount = 20
22+
)
23+
24+
# If the step size or count is negative
25+
if (
26+
($stepSize -lt 0 -or $stepCount -lt 0) -and
27+
$Length -in 0,1 # and the length is either the default or zero
28+
) {
29+
# set the length to the correct maximim step size, so we can make an inward spiral.
30+
$Length = ([Math]::Abs($stepSize) * [Math]::Abs($stepCount))
31+
}
32+
elseif ($length -eq 0) {
33+
# If the length is empty, default it to the step size
34+
$Length = $StepSize
35+
}
36+
37+
# Perform the appropriate steps
38+
foreach ($n in 1..([Math]::Abs($StepCount))) {
39+
$this = $this.Forward($length).Rotate($angle)
40+
$length += $stepSize
41+
}
42+
# and return ourself.
43+
return $this
44+

0 commit comments

Comments
 (0)