Skip to content

Commit 2ea3c9a

Browse files
feat: Turtle.Spirolateral ( Fixes #120 )
Tracking total turn instead of heading
1 parent 77e04a4 commit 2ea3c9a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Types/Turtle/Spirolateral.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,27 @@ $LeftTurnSteps
4040

4141
$stepNumber = 1
4242
$majorStepCount = 0
43+
$totalTurn = 0
4344
do {
4445
$null = for ($stepNumber = 1; $stepNumber -le [Math]::Abs($StepCount); $stepNumber++) {
4546
$null = $this.Forward($side * $stepNumber)
4647
if ($LeftTurnSteps) {
4748
if ($LeftTurnSteps -contains $stepNumber) {
49+
$totalTurn -= $angle
4850
$this.Left($angle)
4951
} else {
52+
$totalTurn += $angle
5053
$this.Right($angle)
5154
}
5255
} else {
56+
$totalTurn += $angle
5357
$this.Right($angle)
5458
}
5559
}
5660
$majorStepCount++
5761
} until (
58-
(-not ([Math]::Round($this.Heading, 5) % 360 )) -or
59-
$majorStepCount -gt $StepCount
62+
(-not ([Math]::Round($totalTurn, 5) % 360 )) -and
63+
$majorStepCount -le [Math]::Abs($StepCount)
6064
)
6165

6266
return $this

0 commit comments

Comments
 (0)