Skip to content

Commit 92dec87

Browse files
fix: Turtle.Pop output fix ( Fixes #264 )
Also adding docs to push and pop
1 parent cf6757f commit 92dec87

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Types/Turtle/Pop.ps1

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
if ($this.'.Stack' -isnot [Collections.Stack]) {
2-
return
3-
}
1+
<#
2+
.SYNOPSIS
3+
Pops the Turtle Stack
4+
.DESCRIPTION
5+
Pops the Turtle back to the last location and heading in the stack.
46
5-
if ($this.'.Stack'.Count -eq 0) {
6-
return
7-
}
7+
By pushing and popping, we can draw multiple branches.
8+
.EXAMPLE
9+
# Draws a T shape by pushing and popping
10+
turtle rotate -90 forward 42 push rotate 90 forward 21 pop rotate -90 forward 21 show
11+
#>
12+
if ($this.'.Stack' -isnot [Collections.Stack]) { return }
13+
14+
if ($this.'.Stack'.Count -eq 0) { return }
815

916
$popped = $this.'.Stack'.Pop()
10-
$this.PenUp().Goto($popped.Position.X, $popped.Position.Y).PenDown()
17+
$null = $this.PenUp().Goto($popped.Position.X, $popped.Position.Y).PenDown()
1118
$this.Heading = $popped.Heading
1219
return $this

Types/Turtle/Push.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
<#
2+
.SYNOPSIS
3+
Pushes the Turtle Stack
4+
.DESCRIPTION
5+
Pushes the current state of this Turtle onto a stack.
6+
7+
If this stack is popped, the Turtle will teleport back to the location where it was pushed.
8+
9+
By pushing and popping, we can draw multiple branches.
10+
#>
111
if (-not $this.'.Stack') {
212
$this | Add-Member NoteProperty '.Stack' ([Collections.Stack]::new()) -Force
313
}
4-
514
$this.'.Stack'.Push(@{
615
Position = [Ordered]@{X=$this.Position.X;Y=$this.Position.Y}
716
Heading = $this.Heading

0 commit comments

Comments
 (0)