@@ -56,6 +56,129 @@ function Get-Turtle {
5656 . EXAMPLE
5757 # If we only provide the first parameter, we get a golden rectangle
5858 turtle rectangle 42
59+ . EXAMPLE
60+ ### Right Triangles
61+ # We can draw right triangles
62+ turtle RightTriangle 3 4
63+ . EXAMPLE
64+ # Right triangles take two sides
65+ # either can be negative
66+ turtle RightTriangle 3 4
67+ turtle RightTriangle -3 4
68+ turtle RightTriangle -3 -4
69+ turtle RightTriangle 3 -4
70+ . EXAMPLE
71+ # We can draw a random right triangle
72+ turtle RightTriangle
73+ . EXAMPLE
74+ # We can a right triangle by a random degree
75+ turtle rotate RightTriangle
76+ . EXAMPLE
77+ # We can easily rotate and repeat right triangles
78+ turtle @(
79+ 'RightTriangle',3,-4,'rotate', 90 * 4
80+ )
81+ . EXAMPLE
82+ # Right triangles are easy to morph
83+ turtle @(
84+ 'RightTriangle',3,-4,'rotate', 90 * 4
85+ ) morph @(
86+ turtle ('RightTriangle',3,-4,'rotate', 90 * 4)
87+ turtle ('RightTriangle',3,4,'rotate', 90 * 4)
88+ turtle ('RightTriangle',3,-4,'rotate', 90 * 4)
89+ )
90+ . EXAMPLE
91+ # We can create a parallax by repeating and reflecting triangles
92+ turtle @(
93+ 'RightTriangle', 1,-4
94+ 'RightTriangle', 2,-4
95+ 'RightTriangle', 3,-4
96+ 'RightTriangle', 4,-4
97+ 'RightTriangle', -4,-4
98+ 'RightTriangle', -3,-4
99+ 'RightTriangle', -2,-4
100+ 'RightTriangle', -1,-4
101+ )
102+ . EXAMPLE
103+ # This can also be morphed to produce a beautiful illusion
104+ turtle morph @(
105+ turtle @(
106+ 'RightTriangle', 1,-4
107+ 'RightTriangle', 2,-4
108+ 'RightTriangle', 3,-4
109+ 'RightTriangle', 4,-4
110+ 'RightTriangle', -4,-4
111+ 'RightTriangle', -3,-4
112+ 'RightTriangle', -2,-4
113+ 'RightTriangle', -1,-4
114+ )
115+ turtle @(
116+ 'RightTriangle', -1,-4
117+ 'RightTriangle', -2,-4
118+ 'RightTriangle', -3,-4
119+ 'RightTriangle', -4,-4
120+ 'RightTriangle', 4,-4
121+ 'RightTriangle', 3,-4
122+ 'RightTriangle', 2,-4
123+ 'RightTriangle', 1,-4
124+ )
125+ turtle @(
126+ 'RightTriangle', 1,-4
127+ 'RightTriangle', 2,-4
128+ 'RightTriangle', 3,-4
129+ 'RightTriangle', 4,-4
130+ 'RightTriangle', -4,-4
131+ 'RightTriangle', -3,-4
132+ 'RightTriangle', -2,-4
133+ 'RightTriangle', -1,-4
134+ )
135+ )
136+ . EXAMPLE
137+ # Two sets of right triangles that grow in different directions
138+ # produce what looks like a parallax illusion curve
139+ turtle id ParallaxCorner @(foreach ($n in 1..10) {
140+ 'RightTriangle',(10 - $n),$n
141+ 'RightTriangle',$n,(10-$n)
142+ })
143+ . EXAMPLE
144+ # We can rotate and repeat this to make a Parallax Astroid
145+ turtle id ParallaxAstroid (@(
146+ @(foreach ($n in 1..10) {
147+ 'RightTriangle',(10 - $n),$n
148+ 'RightTriangle',$n,(10-$n)
149+ })
150+ 'rotate', 90
151+ ) * 4)
152+ . EXAMPLE
153+ # We can make a pair of parallax astroids and morph them.
154+ $parallaxAstroid = turtle id ParallaxAstroid (
155+ @(
156+ foreach ($n in 1..10) {
157+ 'RightTriangle',(10 - $n),$n
158+ 'RightTriangle',$n,(10-$n)
159+ }
160+ 'rotate', 90
161+ ) * 4
162+ )
163+
164+ $parallaxAstroid2 = turtle id ParallaxAstroid (
165+ @(
166+ foreach ($n in 1..10) {
167+ 'RightTriangle',(10 - $n),($n*-1)
168+ 'RightTriangle',($n*-1),(10-$n)
169+ }
170+ 'rotate', 90
171+ ) * 4
172+ )
173+
174+ $parallaxAstroid | turtle morph @(
175+ $parallaxAstroid
176+ $parallaxAstroid2
177+ $parallaxAstroid
178+ ) @(
179+ 'pathclass','foreground-stroke foreground-fill'
180+ 'fillrule','evenodd'
181+ )
59182 . EXAMPLE
60183 #### Circles
61184 # We can draw a circle
@@ -139,7 +262,7 @@ function Get-Turtle {
139262 # Let's do the same thing, but with a smaller angle
140263 turtle ('polygon', 23, 6, 'rotate', -40 * 9)
141264 . EXAMPLE
142- #### Flowers
265+ ### Flowers
143266 # A flower is a series of repeated polygons and rotations
144267 turtle Flower
145268 . EXAMPLE
@@ -200,6 +323,13 @@ function Get-Turtle {
200323 $flowerPetals2,
201324 $flowerPetals
202325 )
326+ . EXAMPLE
327+ ### Triflowers
328+ # We can make Flowers out of Right Triangles
329+ # We call these triflowers
330+ turtle triflower 42 15 21 24
331+ . EXAMPLE
332+ turtle triflower
203333 . EXAMPLE
204334 #### Arcs and Suns
205335 # We can arc right or left
@@ -367,11 +497,11 @@ function Get-Turtle {
367497 )
368498 . EXAMPLE
369499 #### Spirolaterals
370- turtle spirolateral
500+ turtle spirolateral 10 90 10
371501 . EXAMPLE
372502 turtle spirolateral 50 60 10
373503 . EXAMPLE
374- turtle spirolateral 50 120 6 @(1,3)
504+ turtle spirolateral 50 120 6 @(1,3)
375505 . EXAMPLE
376506 turtle spirolateral 23 144 8
377507 . EXAMPLE
@@ -818,9 +948,22 @@ function Get-Turtle {
818948 . EXAMPLE
819949 # The SierpinskiArrowHead Curve is pretty
820950 turtle SierpinskiArrowheadCurve 42 4
951+ . EXAMPLE
952+ # So is the SierpinskiCurve
953+ turtle SierpinskiCurve 42 4
954+ . EXAMPLE
955+ # The SierpinskiCurveSquare curve fills a from a corner
956+ turtle SierpinskiSquareCurve 42 4
957+ . EXAMPLE
958+ # If we put four of these next to each other
959+ # and turn left, we get a square made of square curves.
960+ turtle @('SierpinskiSquareCurve', -42, 4, 'Rotate', -90 * 4)
961+ . EXAMPLE
962+ # If we turn right instead, we get a diamond with an empty square at the center
963+ turtle @('SierpinskiSquareCurve', -42, 4, 'Rotate', 90 * 4)
821964 . EXAMPLE
822965 # The SierpinskiTriangle is a Fractal classic
823- turtle SierpinskiTriangle 42 4
966+ turtle SierpinskiTriangle 42 4
824967 . EXAMPLE
825968 # We can morph with no parameters to try to draw step by step
826969 #
@@ -849,9 +992,13 @@ function Get-Turtle {
849992 turtle @('rotate', 30, 'SierpinskiTriangle',42,4 * 12)
850993 . EXAMPLE
851994 turtle @('rotate', 45, 'SierpinskiTriangle',42,4 * 24)
995+ . LINK
996+ https://psturtle.com/Commands/Get-Turtle
997+ . LINK
998+ https://psturtle.com/History/
852999 #>
8531000 [CmdletBinding (PositionalBinding = $false )]
854- [Alias (' turtle' )]
1001+ [Alias (' turtle' , ' 🐢 ' )]
8551002 param (
8561003 # The arguments to pass to turtle.
8571004 [ArgumentCompleter ({
@@ -975,10 +1122,24 @@ function Get-Turtle {
9751122 # If we wanted to run a background job
9761123 if ($PSBoundParameters.AsJob ) {
9771124 # remove the -AsJob variable from our parameters
978- $null = $PSBoundParameters.Remove (' AsJob' )
1125+ $null = $PSBoundParameters.Remove (' AsJob' )
1126+
1127+
1128+ $jobCommand =
1129+ $threadJob =
1130+ $ExecutionContext.SessionState.InvokeCommand.GetCommand (' Start-ThreadJob' , ' Cmdlet' )
9791131
1132+ if (-not $threadJob ) {
1133+ $jobCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand (' Start-Job' , ' Cmdlet' )
1134+ }
1135+
1136+ if (-not $jobCommand ) {
1137+ Write-Error " No Job Command found. Start-ThreadJob or Start-Job must be loaded"
1138+ return
1139+ }
1140+
9801141 # and then start a thread job that will import the module and run the command.
981- return Start-ThreadJob - ScriptBlock {
1142+ return & $jobCommand - ScriptBlock {
9821143 param ([Collections.IDictionary ]$IO )
9831144 Import-Module - Name $io.ModulePath
9841145 $argList = @ ($IO.ArgumentList )
@@ -1036,7 +1197,13 @@ function Get-Turtle {
10361197 # and keep track of when it became unbalanced.
10371198 $unbalancedAt = $null
10381199 foreach ($match in [Regex ]::Matches(
1039- ($wordsAndArguments -join ' ' ), ' [\[\]]'
1200+ (@ (
1201+ foreach ($arg in $wordsAndArguments ) {
1202+ if ($arg -is [string ]) {
1203+ $arg
1204+ }
1205+ }
1206+ ) -join ' ' ), ' [\[\]]'
10401207 )
10411208 ) {
10421209 # To do this, we increment or decrement depth for brackets `[]`
10891256 for ($argIndex = 0 ; $argIndex -lt $wordsAndArguments.Length ; $argIndex ++ ) {
10901257 $arg = $wordsAndArguments [$argIndex ]
10911258 # If the argument is not in the member names list, we can complain about it.
1092- if ($arg -notin $memberNames ) {
1259+ if ($arg -is [ string ] -and $arg - notin $memberNames ) {
10931260 if (
10941261 # (we might not want to, if it starts with a bracket)
10951262 -not $currentMember -and $arg -is [string ] -and
@@ -1140,13 +1307,12 @@ $(
11401307 if (" $bracket " -eq ' [' ) { $bracketDepth ++ }
11411308 if (" $bracket " -eq ' ]' ) { $bracketDepth -- }
11421309 }
1143- }
1144- # If the next word is a method name, and our brackets are balanced
1145- if ( $wordsAndArguments [ $methodArgIndex ] -in $memberNames -and -not $bracketDepth ) {
1146- # break out of the loop.
1147- break
1310+ # If the next word is a method name, and our brackets are balanced
1311+ if ( $wordsAndArguments [ $methodArgIndex ] -in $memberNames - and -not $bracketDepth ) {
1312+ # break out of the loop.
1313+ break
1314+ }
11481315 }
1149-
11501316 }
11511317 # Now we know how far we had to look to get to the next member name.
11521318
@@ -1164,7 +1330,10 @@ $(
11641330 $HelpWanted = $true
11651331 continue
11661332 }
1167- if ($HelpWanted -and $word -in ' example' , ' examples' , ' parameter' , ' parameters' , ' online' ) {
1333+ if ($HelpWanted -and
1334+ $word -is [string ] -and
1335+ $word -in ' example' , ' examples' , ' parameter' , ' parameters' , ' online'
1336+ ) {
11681337 if ($word -in ' example' , ' examples' ) {
11691338 $switches [' Examples' ] = $true
11701339 }
11761345 }
11771346 continue
11781347 }
1179- if ($word -match ' ^[-/]+?[\D-[\.]]' ) {
1348+ if ($word -is [ string ] -and $word - match ' ^[-/]+?[\D-[\.]]' ) {
11801349 $switchInfo = $word -replace ' ^[-/]+'
11811350 $switchName , $switchValue = $switchInfo -split ' :' , 2
11821351 if ($null -eq ($switchName -as [double ])) {
@@ -1190,12 +1359,12 @@ $(
11901359 }
11911360 }
11921361 # If the word started with a bracket, and we haven't removed any
1193- if (" $word " .StartsWith(' [' ) -and -not $debracketCount ) {
1362+ if ($word -is [ string ] -and $word .StartsWith (' [' ) -and -not $debracketCount ) {
11941363 $word = $word -replace ' ^\[' # remove it
11951364 $debracketCount ++ # and increment our removal counter.
11961365 }
11971366 # If the word ended with a bracket, and we have debracketed once
1198- if (" $word " .EndsWith(' ]' ) -and $debracketCount -eq 1 ) {
1367+ if ($word -is [ string ] -and $word .EndsWith (' ]' ) -and $debracketCount -eq 1 ) {
11991368 # remove the closing bracket
12001369 $word = $word -replace ' \]$'
12011370 # and increment our removal counter
0 commit comments