1212. EXAMPLE
1313 $sierpinskiTriangle = turtle SierpinskiTriangle 42 4
1414 $SierpinskiTriangleFlipped = turtle rotate 180 SierpinskiTriangle 42 4
15- turtle SierpinskiTriangle 42 4 morph (
15+ $sf = turtle SierpinskiTriangle 42 4 morph (
1616 $SierpinskiTriangle,
1717 $SierpinskiTriangleFlipped,
1818 $sierpinskiTriangle
19- ) save ./SierpinskiTriangleFlip.svg
19+ )
20+ $sf | Save-Turtle ./SierpinskiTriangleFlip.svg
21+ . EXAMPLE
22+ $sierpinskiTriangle = turtle SierpinskiTriangle 42 4
23+ $SierpinskiTriangle90 = turtle rotate 90 SierpinskiTriangle 42 4
24+ $SierpinskiTriangle180 = turtle rotate 180 SierpinskiTriangle 42 4
25+ $SierpinskiTriangle270 = turtle rotate 270 SierpinskiTriangle 42 4
26+ $sf = turtle SierpinskiTriangle 42 4 morph @(
27+ $SierpinskiTriangle,
28+ $SierpinskiTriangle90
29+ ) morph @(
30+ $SierpinskiTriangle180
31+ $SierpinskiTriangle270
32+ $sierpinskiTriangle
33+ )
34+ $sf | save-turtle ./SierpinskiRoll.svg
2035. EXAMPLE
2136 $sideCount = (3..24 | Get-Random )
2237 $stepCount = 36
@@ -53,12 +68,16 @@ $Arguments
5368$durationArgument = $null
5469$hasPoints = $false
5570$segmentCount = 0
71+ $reflect = $false
5672$newPaths = @ (foreach ($arg in $Arguments ) {
5773 if ($arg -is [string ]) {
5874 if ($arg -match ' ^\s{0,}m' ) {
5975 $arg
6076 $hasPoints = $true
6177 }
78+ elseif ($arg -match ' reflect' ) {
79+ $reflect = $true
80+ }
6281 } elseif ($arg.PathData ) {
6382 $arg.PathData
6483 $hasPoints = $true
@@ -73,7 +92,7 @@ $newPaths = @(foreach ($arg in $Arguments) {
7392 $segmentCount = [Math ]::Abs($arg )
7493 } else {
7594 $durationArgument = [TimeSpan ]::FromSeconds($arg )
76- }
95+ }
7796 }
7897})
7998
@@ -97,19 +116,28 @@ if (-not $newPaths) {
97116 }
98117}
99118
100- if ($this.PathAnimation ) {
119+ # Check to see if we have existing animations on the path
120+ $pathAnimation = $this.PathAnimation
121+ $updatedAnimations = @ ()
122+ # If we do
123+ if ($pathAnimation ) {
124+ # see if any of them are updated
101125 $updatedAnimations =
102- @ (foreach ($animationXML in $this.PathAnimation -split ' (?<=/>)' ) {
103- $animationXML = $animationXML -as [xml ]
126+ @ (foreach ($animationXML in $pathAnimation ) {
104127 if (-not $animationXML ) { continue }
105- if ($animationXML.animate.attributeName -eq ' d' ) {
106- $animationXML.animate.values = " $ ( $newPaths -join ' ;' ) "
128+ # we only want to change morphs
129+ # (which are animations of the path data)
130+ if ($animationXML.animate.attributeName -eq ' d' ) {
131+ $animationXML.animate.values = " $ (
132+ @ ($animationXML.animate.values ; $newPaths ) -join ' ;'
133+ ) "
107134 }
108- $animationXML.OuterXml
109- })
110- $this.PathAnimation = $updatedAnimations
111- } else {
112- $this.PathAnimation += [Ordered ]@ {
135+ $animationXML
136+ })
137+ }
138+
139+ if (-not $updatedAnimations ) {
140+ $this.PathAnimation = [Ordered ]@ {
113141 attributeName = ' d' ; values = " $ ( $newPaths -join ' ;' ) " ; repeatCount = ' indefinite' ; dur = $ (
114142 if ($durationArgument ) {
115143 " $ ( $durationArgument.TotalSeconds ) s"
@@ -118,9 +146,8 @@ if ($this.PathAnimation) {
118146 } else {
119147 " 4.2s"
120148 }
121-
122149 )
123- }
150+ }
124151}
125152
126153return $this
0 commit comments