@@ -98,6 +98,26 @@ $Distance = 10
9898
9999$this.Forward($Distance * -1)
100100
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+
101121 </Script >
102122 </ScriptMethod >
103123 <ScriptMethod >
@@ -285,6 +305,26 @@ if ($This.IsPenDown) {
285305return $this
286306 </Script >
287307 </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 >
288328 <ScriptMethod >
289329 <Name >GosperCurve</Name >
290330 <Script >
@@ -352,7 +392,7 @@ if ($this.IsPenDown) {
352392} else {
353393 $this.Steps += " m $deltaX $deltaY"
354394}
355- $this.Position = $x , $y
395+ $this.Position = $deltaX , $deltaY
356396return $this
357397 </Script >
358398 </ScriptMethod >
@@ -365,10 +405,10 @@ return $this
365405 [double]$Angle = 90
366406)
367407
368- return $this.LSystem('A', @{
408+ return $this.LSystem('A', [Ordered] @{
369409 A = '+BF-AFA-FB+'
370410 B = '-AF+BFB+FA-'
371- }, $Order, @{
411+ }, $Order, [Ordered] @{
372412 'F' = { $this.Forward($Size) }
373413 '\+' = { $this.Rotate($Angle) }
374414 '\-' = { $this.Rotate($Angle * -1) }
@@ -682,6 +722,12 @@ $null = foreach ($character in $finalState.ToCharArray()) {
682722 }
683723 }
684724}
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+ }
685731return $this
686732
687733 </Script >
@@ -798,6 +844,37 @@ $null = foreach ($n in 1..$SideCount) {
798844 $this.Forward($Size)
799845 $this.Rotate(360 / $SideCount)
800846}
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+ })
801878return $this
802879 </Script >
803880 </ScriptMethod >
10571134$deltaX = $x - $this.X
10581135$deltaY = $y - $this.Y
10591136$this.Steps += "m $deltaX $deltaY"
1060- $this.Position = $x , $y
1137+ $this.Position = $deltaX , $deltaY
10611138return $this
10621139 </Script >
10631140 </ScriptMethod >
@@ -1104,6 +1181,14 @@ return $this.LSystem('F', [Ordered]@{
11041181
11051182 </Script >
11061183 </ScriptMethod >
1184+ <ScriptMethod >
1185+ <Name >ToString</Name >
1186+ <Script >
1187+ param()
1188+
1189+ return "$($this.SVG.OuterXml)"
1190+ </Script >
1191+ </ScriptMethod >
11071192 <ScriptMethod >
11081193 <Name >TwinDragonCurve</Name >
11091194 <Script >
@@ -1236,12 +1321,12 @@ $this | Add-Member NoteProperty -Name '.BackgroundColor' -Value $value -Force
12361321 $viewBox = $this.ViewBox
12371322 $null, $null, $viewX, $viewY = $viewBox
12381323 "< 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> "
12401325
12411326 "< script> "
12421327@"
12431328window.onload = async function() {
1244- var canvas = document.getElementById('turtle -canvas');
1329+ var canvas = document.getElementById('$($this.ID) -canvas');
12451330 var ctx = canvas.getContext('2d');
12461331 ctx.strokeStyle = '$($this.Stroke)'
12471332 ctx.lineWidth = '$(
@@ -1351,6 +1436,20 @@ if ($VerbosePreference -ne 'SilentlyContinue') {
13511436}
13521437 </SetScriptBlock >
13531438 </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 >
13541453 <ScriptProperty >
13551454 <Name >IsPenDown</Name >
13561455 <GetScriptBlock >
@@ -1429,7 +1528,7 @@ if ($chromeOutput -match '<img\ssrc="data:image/\w+;base64,(?<b64>[^"]+
14291528 $segments = @(
14301529"< svg xmlns='http://www.w3.org/2000/svg' width='0%' height='0%'> "
14311530 "< defs> "
1432- "< mask id='turtle -mask'> "
1531+ "< mask id='$($this.Id) -mask'> "
14331532 $this.Symbol.OuterXml -replace '\< \?[^\> ]+\> '
14341533 "< /mask> "
14351534 "< /defs> "
@@ -1546,7 +1645,7 @@ $this | Add-Member -MemberType NoteProperty -Force -Name '.PathClass' -Value @(
15461645 <Name >PathElement</Name >
15471646 <GetScriptBlock >
15481647 @(
1549- "< path id='turtle -path' d='$($this.PathData)' stroke='$(
1648+ "< path id='$($this.id) -path' d='$($this.PathData)' stroke='$(
15501649 if ($this.Stroke) { $this.Stroke } else { 'currentColor' }
15511650)' stroke-width='$(
15521651 if ($this.StrokeWidth) { $this.StrokeWidth } else { '0.1%' }
@@ -1569,7 +1668,7 @@ $viewBox = $this.ViewBox
15691668$null, $null, $viewX, $viewY = $viewBox
15701669"< svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'> "
15711670"< 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%'$(
15731672 if ($this.PatternTransform) {
15741673 " patternTransform='" + (
15751674 @(foreach ($key in $this.PatternTransform.Keys) {
15871686 "< rect width='10000%' height='10000%' x='-5000%' y='-5000%' fill='$($this.BackgroundColor)' transform-origin='50% 50%' /> "
15881687 }
15891688)
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%' /> "
15911690"< /svg> ")
15921691
15931692$segments -join '' -as [xml]
@@ -1657,7 +1756,7 @@ $b64 = [Convert]::ToBase64String($OutputEncoding.GetBytes($thisPattern.outerXml)
16571756 $segments = @(
16581757"< svg xmlns='http://www.w3.org/2000/svg' width='0%' height='0%'> "
16591758 "< defs> "
1660- "< mask id='turtle -mask'> "
1759+ "< mask id='$($this.ID) -mask'> "
16611760 $this.Pattern.OuterXml -replace '\< \?[^\> ]+\> '
16621761 "< /mask> "
16631762 "< /defs> "
@@ -1744,9 +1843,10 @@ if ($chromeOutput -match '<img\ssrc="data:image/png;base64,(?<b64>[^"]+
17441843 <Name >Position</Name >
17451844 <GetScriptBlock >
17461845 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 })
17481847}
17491848return $this.'.Position'
1849+
17501850 </GetScriptBlock >
17511851 <SetScriptBlock >
17521852 param([double[]]$xy)
@@ -1777,6 +1877,16 @@ if ($posY -gt $this.'.Maximum'.Y) {
17771877}
17781878 </SetScriptBlock >
17791879 </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 >
17801890 <ScriptProperty >
17811891 <Name >Steps</Name >
17821892 <GetScriptBlock >
@@ -1865,15 +1975,15 @@ param()
18651975
18661976@(
18671977 "< 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%'> "
18691979 $this.PathElement.OuterXml
18701980 "< /symbol> "
18711981 $(
18721982 if ($this.BackgroundColor) {
18731983 "< rect width='10000%' height='10000%' x='-5000%' y='-5000%' fill='$($this.BackgroundColor)' transform-origin='50% 50%' /> "
18741984 }
18751985 )
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%' /> "
18771987 "< /svg> "
18781988) -join '' -as [xml]
18791989 </GetScriptBlock >
0 commit comments