@@ -98,6 +98,26 @@ $Distance = 10
98
98
99
99
$this.Forward($Distance * -1)
100
100
101
+ </Script >
102
+ </ScriptMethod >
103
+ <ScriptMethod >
104
+ <Name >BinaryTree</Name >
105
+ <Script >
106
+ param(
107
+ [double]$Size = 20,
108
+ [int]$Order = 4,
109
+ [double]$Angle = 45
110
+ )
111
+ return $this.Rotate(-90).LSystem('0', [Ordered]@{
112
+ '1' = '11'
113
+ '0' = '1[0]0'
114
+ }, $Order, [Ordered]@{
115
+ '[01]' = { $this.Forward($Size) }
116
+ '\[' = { $this.Rotate($Angle * -1).Push() }
117
+ '\]' = { $this.Pop().Rotate($Angle) }
118
+ })
119
+
120
+
101
121
</Script >
102
122
</ScriptMethod >
103
123
<ScriptMethod >
@@ -285,6 +305,26 @@ if ($This.IsPenDown) {
285
305
return $this
286
306
</Script >
287
307
</ScriptMethod >
308
+ <ScriptMethod >
309
+ <Name >FractalPlant</Name >
310
+ <Script >
311
+ param(
312
+ [double]$Size = 20,
313
+ [int]$Order = 4,
314
+ [double]$Angle = 25
315
+ )
316
+ return $this.Rotate(-90).LSystem('-X', [Ordered]@{
317
+ 'X' = 'F+[[X]-X]-F[-FX]+X'
318
+ 'F' = 'FF'
319
+ }, $Order, [Ordered]@{
320
+ 'F' = { $this.Forward($Size) }
321
+ '\[' = { $this.Rotate($Angle * -1).Push() }
322
+ '\]' = { $this.Pop().Rotate($Angle) }
323
+ })
324
+
325
+
326
+ </Script >
327
+ </ScriptMethod >
288
328
<ScriptMethod >
289
329
<Name >GosperCurve</Name >
290
330
<Script >
@@ -352,7 +392,7 @@ if ($this.IsPenDown) {
352
392
} else {
353
393
$this.Steps += " m $deltaX $deltaY"
354
394
}
355
- $this.Position = $x , $y
395
+ $this.Position = $deltaX , $deltaY
356
396
return $this
357
397
</Script >
358
398
</ScriptMethod >
@@ -365,10 +405,10 @@ return $this
365
405
[double]$Angle = 90
366
406
)
367
407
368
- return $this.LSystem('A', @{
408
+ return $this.LSystem('A', [Ordered] @{
369
409
A = '+BF-AFA-FB+'
370
410
B = '-AF+BFB+FA-'
371
- }, $Order, @{
411
+ }, $Order, [Ordered] @{
372
412
'F' = { $this.Forward($Size) }
373
413
'\+' = { $this.Rotate($Angle) }
374
414
'\-' = { $this.Rotate($Angle * -1) }
@@ -682,6 +722,12 @@ $null = foreach ($character in $finalState.ToCharArray()) {
682
722
}
683
723
}
684
724
}
725
+ $this.PathAttribute = [Ordered]@{
726
+ "data-l-order" = $N
727
+ "data-l-axiom" = $Axiom
728
+ "data-l-rules" = ConvertTo-Json $Rule
729
+ "data-l-expanded" = $finalState
730
+ }
685
731
return $this
686
732
687
733
</Script >
@@ -798,6 +844,37 @@ $null = foreach ($n in 1..$SideCount) {
798
844
$this.Forward($Size)
799
845
$this.Rotate(360 / $SideCount)
800
846
}
847
+ return $this
848
+ </Script >
849
+ </ScriptMethod >
850
+ <ScriptMethod >
851
+ <Name >Pop</Name >
852
+ <Script >
853
+ if ($this.'.Stack' -isnot [Collections.Stack]) {
854
+ return
855
+ }
856
+
857
+ if ($this.'.Stack'.Count -eq 0) {
858
+ return
859
+ }
860
+
861
+ $popped = $this.'.Stack'.Pop()
862
+ $this.PenUp().Goto($popped.Position.X, $popped.Position.Y).PenDown()
863
+ $this.Heading = $popped.Heading
864
+ return $this
865
+ </Script >
866
+ </ScriptMethod >
867
+ <ScriptMethod >
868
+ <Name >Push</Name >
869
+ <Script >
870
+ if (-not $this.'.Stack') {
871
+ $this | Add-Member NoteProperty '.Stack' ([Collections.Stack]::new()) -Force
872
+ }
873
+
874
+ $this.'.Stack'.Push(@{
875
+ Position = [Ordered]@{X=$this.Position.X;Y=$this.Position.Y}
876
+ Heading = $this.Heading
877
+ })
801
878
return $this
802
879
</Script >
803
880
</ScriptMethod >
1057
1134
$deltaX = $x - $this.X
1058
1135
$deltaY = $y - $this.Y
1059
1136
$this.Steps += "m $deltaX $deltaY"
1060
- $this.Position = $x , $y
1137
+ $this.Position = $deltaX , $deltaY
1061
1138
return $this
1062
1139
</Script >
1063
1140
</ScriptMethod >
@@ -1104,6 +1181,14 @@ return $this.LSystem('F', [Ordered]@{
1104
1181
1105
1182
</Script >
1106
1183
</ScriptMethod >
1184
+ <ScriptMethod >
1185
+ <Name >ToString</Name >
1186
+ <Script >
1187
+ param()
1188
+
1189
+ return "$($this.SVG.OuterXml)"
1190
+ </Script >
1191
+ </ScriptMethod >
1107
1192
<ScriptMethod >
1108
1193
<Name >TwinDragonCurve</Name >
1109
1194
<Script >
@@ -1236,12 +1321,12 @@ $this | Add-Member NoteProperty -Name '.BackgroundColor' -Value $value -Force
1236
1321
$viewBox = $this.ViewBox
1237
1322
$null, $null, $viewX, $viewY = $viewBox
1238
1323
"< style> canvas {max-width: 100%; height: 100%}< /style> "
1239
- "< canvas id='turtle -canvas' width='$($viewX + 1)' height='$($viewY + 1)'>< /canvas> "
1324
+ "< canvas id='$($this.ID) -canvas' width='$($viewX + 1)' height='$($viewY + 1)'>< /canvas> "
1240
1325
1241
1326
"< script> "
1242
1327
@"
1243
1328
window.onload = async function() {
1244
- var canvas = document.getElementById('turtle -canvas');
1329
+ var canvas = document.getElementById('$($this.ID) -canvas');
1245
1330
var ctx = canvas.getContext('2d');
1246
1331
ctx.strokeStyle = '$($this.Stroke)'
1247
1332
ctx.lineWidth = '$(
@@ -1351,6 +1436,20 @@ if ($VerbosePreference -ne 'SilentlyContinue') {
1351
1436
}
1352
1437
</SetScriptBlock >
1353
1438
</ScriptProperty >
1439
+ <ScriptProperty >
1440
+ <Name >ID</Name >
1441
+ <GetScriptBlock >
1442
+ if ($this.'.ID') { return $this.'.ID'}
1443
+ return 'turtle'
1444
+
1445
+ </GetScriptBlock >
1446
+ <SetScriptBlock >
1447
+ param([string]$Value)
1448
+
1449
+ $this | Add-Member NoteProperty '.ID' $Value -Force
1450
+
1451
+ </SetScriptBlock >
1452
+ </ScriptProperty >
1354
1453
<ScriptProperty >
1355
1454
<Name >IsPenDown</Name >
1356
1455
<GetScriptBlock >
@@ -1429,7 +1528,7 @@ if ($chromeOutput -match '<img\ssrc="data:image/\w+;base64,(?<b64>[^"]+
1429
1528
$segments = @(
1430
1529
"< svg xmlns='http://www.w3.org/2000/svg' width='0%' height='0%'> "
1431
1530
"< defs> "
1432
- "< mask id='turtle -mask'> "
1531
+ "< mask id='$($this.Id) -mask'> "
1433
1532
$this.Symbol.OuterXml -replace '\< \?[^\> ]+\> '
1434
1533
"< /mask> "
1435
1534
"< /defs> "
@@ -1546,7 +1645,7 @@ $this | Add-Member -MemberType NoteProperty -Force -Name '.PathClass' -Value @(
1546
1645
<Name >PathElement</Name >
1547
1646
<GetScriptBlock >
1548
1647
@(
1549
- "< path id='turtle -path' d='$($this.PathData)' stroke='$(
1648
+ "< path id='$($this.id) -path' d='$($this.PathData)' stroke='$(
1550
1649
if ($this.Stroke) { $this.Stroke } else { 'currentColor' }
1551
1650
)' stroke-width='$(
1552
1651
if ($this.StrokeWidth) { $this.StrokeWidth } else { '0.1%' }
@@ -1569,7 +1668,7 @@ $viewBox = $this.ViewBox
1569
1668
$null, $null, $viewX, $viewY = $viewBox
1570
1669
"< svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'> "
1571
1670
"< defs> "
1572
- "< pattern id='turtle -pattern' patternUnits='userSpaceOnUse' width='$viewX' height='$viewY' transform-origin='50% 50%'$(
1671
+ "< pattern id='$($this.ID) -pattern' patternUnits='userSpaceOnUse' width='$viewX' height='$viewY' transform-origin='50% 50%'$(
1573
1672
if ($this.PatternTransform) {
1574
1673
" patternTransform='" + (
1575
1674
@(foreach ($key in $this.PatternTransform.Keys) {
1587
1686
"< rect width='10000%' height='10000%' x='-5000%' y='-5000%' fill='$($this.BackgroundColor)' transform-origin='50% 50%' /> "
1588
1687
}
1589
1688
)
1590
- "< rect width='10000%' height='10000%' x='-5000%' y='-5000%' fill='url(#turtle -pattern)' transform-origin='50% 50%' /> "
1689
+ "< rect width='10000%' height='10000%' x='-5000%' y='-5000%' fill='url(#$($this.ID) -pattern)' transform-origin='50% 50%' /> "
1591
1690
"< /svg> ")
1592
1691
1593
1692
$segments -join '' -as [xml]
@@ -1657,7 +1756,7 @@ $b64 = [Convert]::ToBase64String($OutputEncoding.GetBytes($thisPattern.outerXml)
1657
1756
$segments = @(
1658
1757
"< svg xmlns='http://www.w3.org/2000/svg' width='0%' height='0%'> "
1659
1758
"< defs> "
1660
- "< mask id='turtle -mask'> "
1759
+ "< mask id='$($this.ID) -mask'> "
1661
1760
$this.Pattern.OuterXml -replace '\< \?[^\> ]+\> '
1662
1761
"< /mask> "
1663
1762
"< /defs> "
@@ -1744,9 +1843,10 @@ if ($chromeOutput -match '<img\ssrc="data:image/png;base64,(?<b64>[^"]+
1744
1843
<Name >Position</Name >
1745
1844
<GetScriptBlock >
1746
1845
if (-not $this.'.Position') {
1747
- $this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value [pscustomobject]@{ X = 0; Y = 0 }
1846
+ $this | Add-Member -MemberType NoteProperty -Force -Name '.Position' -Value ( [pscustomobject]@{ X = 0; Y = 0 })
1748
1847
}
1749
1848
return $this.'.Position'
1849
+
1750
1850
</GetScriptBlock >
1751
1851
<SetScriptBlock >
1752
1852
param([double[]]$xy)
@@ -1777,6 +1877,16 @@ if ($posY -gt $this.'.Maximum'.Y) {
1777
1877
}
1778
1878
</SetScriptBlock >
1779
1879
</ScriptProperty >
1880
+ <ScriptProperty >
1881
+ <Name >Stack</Name >
1882
+ <GetScriptBlock >
1883
+ if ($null -ne $this.'.Stack'.Count) {
1884
+ $this | Add-Member NoteProperty '.Stack' ([Collections.Stack]::new()) -Force
1885
+ }
1886
+ $this.'.Stack'
1887
+
1888
+ </GetScriptBlock >
1889
+ </ScriptProperty >
1780
1890
<ScriptProperty >
1781
1891
<Name >Steps</Name >
1782
1892
<GetScriptBlock >
@@ -1865,15 +1975,15 @@ param()
1865
1975
1866
1976
@(
1867
1977
"< svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%' transform-origin='50% 50%'> "
1868
- "< symbol id='turtle -symbol' viewBox='$($this.ViewBox)' transform-origin='50% 50%'> "
1978
+ "< symbol id='$($this.ID) -symbol' viewBox='$($this.ViewBox)' transform-origin='50% 50%'> "
1869
1979
$this.PathElement.OuterXml
1870
1980
"< /symbol> "
1871
1981
$(
1872
1982
if ($this.BackgroundColor) {
1873
1983
"< rect width='10000%' height='10000%' x='-5000%' y='-5000%' fill='$($this.BackgroundColor)' transform-origin='50% 50%' /> "
1874
1984
}
1875
1985
)
1876
- "< use href='#turtle -symbol' width='100%' height='100%' transform-origin='50% 50%' /> "
1986
+ "< use href='#$($this.ID) -symbol' width='100%' height='100%' transform-origin='50% 50%' /> "
1877
1987
"< /svg> "
1878
1988
) -join '' -as [xml]
1879
1989
</GetScriptBlock >
0 commit comments