Skip to content

Commit ec813f3

Browse files
Merge pull request #382 from PowerShellWeb/turtle-reptile
Turtle 0.2.2
2 parents 127ae05 + 6153b23 commit ec813f3

File tree

125 files changed

+3174
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+3174
-771
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
## Turtle 0.2.2:
2+
3+
* New Shapes:
4+
* `Turtle.ArcFlower` ( #358 )
5+
* `Turtle.Arcygon` ( #359 )
6+
* `Turtle.ClosePath` ( #277 )
7+
* `Turtle.RightTriangle` ( #367 )
8+
* `Turtle.Rhombus` ( #372 )
9+
* `Turtle.StepCurve` ( #329 )
10+
* `Turtle.Triflower` ( #371 )
11+
* `Turtle.Lucky` draws a random shape (#366)
12+
* Font Settings:
13+
* `Turtle.FontWeight` ( Fixes #354, Fixes #381 )
14+
* `Turtle.FontVariant` ( Fixes #354, Fixes #380 )
15+
* `Turtle.FontStyle` ( Fixes #354, Fixes #379 )
16+
* `Turtle.FontSize` ( Fixes #354, Fixes #378 )
17+
* `Turtle.FontFamily` ( Fixes #354, Fixes #377 )
18+
* Improvements
19+
* Turtle.PathAnimation outputs XML (#374)
20+
* Get-Turtle speed boost (#368)
21+
* Move-Turtle uses the script (#351)
22+
* Randomizing most default parameters (#363)
23+
* Turtle defaults IDs to timestamp ( #362 )
24+
* Fill and Stroke improvement ( Fixes #360, Fixes #361, Fixes #369 )
25+
* Adding random support
26+
* Improving gradient support
27+
* Overwriting class if stroke is specified
28+
* Fixes
29+
* Turtle.History compatibility fix ( #373 )
30+
* Turtle works on PowerShell 5.1!
31+
* Moore Curve Fixes ( #370 )
32+
33+
---
34+
135
## Turtle 0.2.1:
236

337
* New Documentation:

Commands/Get-Turtle.ps1

Lines changed: 188 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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 `[]`
@@ -1089,7 +1256,7 @@ $(
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
}
@@ -1176,7 +1345,7 @@ $(
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

Commands/Move-Turtle.ps1

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ function Move-Turtle {
22
<#
33
.SYNOPSIS
44
Moves a turtle.
5-
.DESCRIPTION
5+
.DESCRIPTION
66
Moves a turtle by invoking a method with any number of arguments.
7+
8+
This represents a single movement of the turtle.
9+
10+
To move the turtle multiple times in one command, use `Get-Turtle`.
711
.EXAMPLE
812
New-Turtle |
913
Move-Turtle Forward 10 |
@@ -15,6 +19,10 @@ function Move-Turtle {
1519
Move-Turtle Forward 10 |
1620
Move-Turtle Right 90 |
1721
Save-Turtle "./Square.svg"
22+
.LINK
23+
Get-Turtle
24+
.LINK
25+
Set-Turtle
1826
#>
1927
[CmdletBinding(PositionalBinding=$false)]
2028
param(
@@ -64,7 +72,10 @@ function Move-Turtle {
6472
Write-Error "Method '$method' not found on Turtle object."
6573
return
6674
}
67-
68-
$inputMethod.Invoke($ArgumentList)
75+
76+
if ($inputMethod.Script) {
77+
$this = $InputObject
78+
& $inputMethod.Script @ArgumentList
79+
}
6980
}
7081
}

Examples/BoxFractal.svg

Lines changed: 1 addition & 1 deletion
Loading

Examples/BoxFractal.turtle.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#requires -Module Turtle
2-
$boxFractalTurtle = Move-Turtle BoxFractal 15 5 |
2+
$boxFractalTurtle = Turtle id BoxFractal-15-5 BoxFractal 15 5 |
33
Set-Turtle Stroke '#4488ff'
44
$boxFractalTurtle | Save-Turtle "./BoxFractal.svg"
55
$boxFractalTurtle | Save-Turtle "./BoxFractal.png" -Property PNG

0 commit comments

Comments
 (0)