Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## Turtle 0.1.9:

* Turtle Text Path Support
* `Turtle.get/set_Text` controls the text (#167)
* `Turtle.get/set_TextAttribute` sets text attributes (#168)
* `Turtle.get/set_TextAnimation` animates text attributes (#171)
* `Get-Turtle` parameter improvements (#169, #170)
* `Get-Turtle` tracks invocation info (#157)

---

## Turtle 0.1.8:

* Turtle Performance
Expand Down
40 changes: 32 additions & 8 deletions Commands/Get-Turtle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function Get-Turtle {
Each argument can be the name of a move of the turtle object.

After a member name is encountered, subsequent arguments will be passed to the member as parameters.

Any parameter that begins with whitespace will be split into multiple words.
.EXAMPLE
# We can write shapes as a series of steps
turtle "
Expand Down Expand Up @@ -370,6 +372,10 @@ function Get-Turtle {
$memberNames = $memberNames | Sort-Object @{Expression={ $_.Length };Descending=$true}, name
# Create a new turtle object in case we have no turtle input.
$currentTurtle = [PSCustomObject]@{PSTypeName='Turtle'}

$invocationInfo = $MyInvocation
$invocationInfo |
Add-Member ScriptProperty History {Get-History -Id $this.HistoryId} -Force
}

process {
Expand All @@ -381,21 +387,31 @@ function Get-Turtle {
return $PSBoundParameters.InputObject
}

if (-not $currentTurtle.Invocations) {
$currentTurtle | Add-Member NoteProperty Invocations -Force @(,$invocationInfo)
} elseif ($currentTurtle.Invocations -is [object[]]) {
$currentTurtle.Invocations += $invocationInfo
}


# First we want to split each argument into words.
# This way, it is roughly the same if you say:
# * `turtle 'forward 10'`
# * `turtle forward 10`
# * `turtle 'forward', 10`
$wordsAndArguments = @(foreach ($arg in $ArgumentList) {
# If the argument is a string, split it by whitespace.
# If the argument is a string, and it starts with whitespace
if ($arg -is [string]) {
$arg -split '\s{1,}'
if ($arg -match '^[\r\n\s]+') {
$arg -split '\s{1,}'
} else {
$arg
}
} else {
# otherwise, leave the argument alone.
$arg
}
})
})

# Now that we have a series of words, we can process them.
# We want to keep track of the current member,
Expand All @@ -406,7 +422,7 @@ function Get-Turtle {

# To do this in one pass, we will iterate through the words and arguments.
# We use an indexed loop so we can skip past claimed arguments.
for ($argIndex =0; $argIndex -lt $wordsAndArguments.Length; $argIndex++) {
for ($argIndex =0; $argIndex -lt $wordsAndArguments.Length; $argIndex++) {
$arg = $wordsAndArguments[$argIndex]
# If the argument is not in the member names list, we can complain about it.
if ($arg -notin $memberNames) {
Expand All @@ -415,7 +431,6 @@ function Get-Turtle {
}
continue
}


# If we have a current member, we can invoke it or get it.
$currentMember = $arg
Expand Down Expand Up @@ -478,7 +493,16 @@ function Get-Turtle {

# If we have any arguments,
if ($argList) {
# lets try to set it.
# Check to see if they are strongly typed
if ($memberInfo -is [Management.Automation.Runspaces.ScriptPropertyData]) {
$desiredType = $memberInfo.SetScriptBlock.Ast.ParamBlock.Parameters.StaticType
if ($desiredType -is [Type] -and
$argList.Length -eq 1 -and
$argList[0] -as $desiredType) {
$argList = $argList[0] -as $desiredType
}
}
# lets try to set it.
$currentTurtle.$currentMember = $argList
} else {
# otherwise, lets get the property
Expand All @@ -492,9 +516,9 @@ function Get-Turtle {
# Properties being returned will largely be strings or numbers, and these will always output directly.
if ($null -ne $stepOutput -and -not ($stepOutput.pstypenames -eq 'Turtle')) {
# Output the step
$stepOutput
$stepOutput
# and set the output turtle to false.
$outputTurtle = $false
$outputTurtle = $false
} elseif ($null -ne $stepOutput) {
# Set the current turtle to the step output.
$currentTurtle = $stepOutput
Expand Down
10 changes: 10 additions & 0 deletions Examples/TurtlesOnATextPath-ATurtleCircle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Examples/TurtlesOnATextPath-Morph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Examples/TurtlesOnATextPath.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Examples/TurtlesOnATextPath.turtle.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if ($PSScriptRoot) { Push-Location $PSScriptRoot}

$turtlesOnATextPath = turtle rotate 90 jump 50 rotate -90 ArcRight 50 60 text 'turtles on a text path' textattribute @{'font-size'=36}
$turtlesOnATextPath | Save-Turtle ./TurtlesOnATextPath.svg


$textPath2 = turtle rotate 90 jump 50 rotate -90 ArcRight 50 -60

$turtlesOnATextPath =
turtle rotate 90 jump 50 rotate -90 rotate -30 forward 200 text 'turtles on a text path' morph @(
turtle rotate 90 jump 50 rotate -90 rotate -10 forward 200
turtle rotate 90 jump 50 rotate -90 rotate -5 forward 200
turtle rotate 90 jump 50 rotate -90 rotate -10 forward 200
) textAnimation ([Ordered]@{
attributeName = 'fill' ; values = "#4488ff;#224488;#4488ff" ; repeatCount = 'indefinite'; dur = "4.2s"
},[Ordered]@{
attributeName = 'font-size' ; values = "1em;1.3em;1em" ; repeatCount = 'indefinite'; dur = "4.2s"
},[Ordered]@{
attributeName = 'textLength' ; values = "100%;1%;100%" ; repeatCount = 'indefinite'; dur = "4.2s"
},[Ordered]@{
attributeName = 'x' ; values = "-100%; 100%; -50%" ; repeatCount = 'indefinite'; dur = "4.2s"
})
$turtlesOnATextPath | Save-Turtle ./TurtlesOnATextPath-Morph.svg


turtle rotate -90 circle 42 text "a turtle circle" textattribute ([Ordered]@{
'x'='5%'
'dominant-baseline'='text-before-edge'
'letter-spacing'='.16em'
}) save ./TurtlesOnATextPath-ATurtleCircle.svg

if ($PSScriptRoot) { Pop-Location }
19 changes: 9 additions & 10 deletions Turtle.psd1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@{
# Version number of this module.
ModuleVersion = '0.1.8'
ModuleVersion = '0.1.9'
# Description of the module
Description = "Turtles in a PowerShell"
# Script module or binary module file associated with this manifest.
Expand Down Expand Up @@ -37,15 +37,14 @@
# A URL to the license for this module.
LicenseURI = 'https://github.com/PowerShellWeb/Turtle/blob/main/LICENSE'
ReleaseNotes = @'
## Turtle 0.1.8:

* Turtle Performance
* Improving `.Steps` performance (#159)
* Reducing Turtle Verbosity (#160)
* New Moves:
* Step (#161)
* Forward,Teleport, and GoTo now use Step (#161)
* New Reflection Examples (#162)
## Turtle 0.1.9:

* Turtle Text Path Support
* `Turtle.get/set_Text` controls the text (#167)
* `Turtle.get/set_TextAttribute` sets text attributes (#168)
* `Turtle.get/set_TextAnimation` animates text attributes (#171)
* `Get-Turtle` parameter improvements (#169, #170)
* `Get-Turtle` tracks invocation info (#157)

---

Expand Down
Loading
Loading