Skip to content

Commit 03ebafe

Browse files
feat: Turtle.ArcLeft/ArcRight ( Fixes #118 )
1 parent 0f6656c commit 03ebafe

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

Types/Turtle/Alias.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
MoveTo = 'Teleport'
1717
Back = 'Backward'
1818
bk = 'Backward'
19+
ArcR = 'ArcRight'
20+
ArcL = 'ArcLeft'
1921
}

Types/Turtle/ArcLeft.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<#
2+
.SYNOPSIS
3+
Arcs the turtle to the left
4+
.DESCRIPTION
5+
Arcs the turtle to the left (counter-clockwise) a number of degrees.
6+
7+
For each degree, the turtle will move forward and rotate.
8+
.NOTES
9+
The amount moved forward will be the portion of the circumference.
10+
#>
11+
param(
12+
# The radius of a the circle, were it to complete the arc.
13+
[double]
14+
$Radius = 10,
15+
16+
# The angle of the arc
17+
[double]
18+
$Angle = 60
19+
)
20+
21+
# Rather than duplicate logic, we will simply reverse the angle
22+
$angle *= -1
23+
# and arc to the "right".
24+
return $this.ArcRight($Radius, $Angle)

Types/Turtle/ArcRight.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<#
2+
.SYNOPSIS
3+
Arcs the turtle to the right
4+
.DESCRIPTION
5+
Arcs the turtle to the right (clockwise) a number of degrees.
6+
7+
For each degree, the turtle will move forward and rotate.
8+
.NOTES
9+
The amount moved forward will be the portion of the circumference.
10+
#>
11+
param(
12+
# The radius of a the circle, were it to complete the arc.
13+
[double]
14+
$Radius = 10,
15+
16+
# The angle of the arc
17+
[double]
18+
$Angle = 60
19+
)
20+
21+
22+
# Determine the absolute angle, for this
23+
$absAngle = [Math]::Abs($angle)
24+
$circumferenceStep = ([Math]::PI * 2 * $Radius) / $absAngle
25+
26+
$iteration = $angle / [Math]::Floor($absAngle)
27+
$angleDelta = 0
28+
$null = while ([Math]::Abs($angleDelta) -lt $absAngle) {
29+
$this.Forward($circumferenceStep)
30+
$this.Rotate($iteration)
31+
$angleDelta+=$iteration
32+
}
33+
34+
return $this

0 commit comments

Comments
 (0)