Skip to content

Commit bf85f5d

Browse files
docs: Morphing examples ( Fixes #154 )
1 parent cf4d6b1 commit bf85f5d

File tree

2 files changed

+92
-10
lines changed

2 files changed

+92
-10
lines changed

Commands/Get-Turtle.ps1

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ function Get-Turtle {
9999
.EXAMPLE
100100
# Flowers get more dense as we decrease the angle and increase the repetitions.
101101
turtle Flower 50 5 (3..12 | Get-Random) 72
102+
.EXAMPLE
103+
# We can morph any two similar shapes.
104+
#
105+
# Flowers look especially beautiful as they morph
106+
$sideCount = (3..12 | Get-Random)
107+
turtle Flower 50 15 $sideCount 36 morph @(
108+
turtle Flower 50 10 $sideCount 72
109+
turtle rotate (Get-Random -Max 360 -Min 180) Flower 50 5 $sideCount 72
110+
turtle Flower 50 10 $sideCount 72
111+
)
102112
.EXAMPLE
103113
# We can draw a pair of arcs and turn back after each one.
104114
# We call this a 'petal'.
@@ -114,7 +124,25 @@ function Get-Turtle {
114124
turtle FlowerPetal 42 10 (10..50 | Get-Random) 36
115125
.EXAMPLE
116126
# Flower Petals get less dense as we increase the angle and decrease repetitions
117-
turtle FlowerPetal 50 20 (20..72 | Get-Random) 18
127+
turtle FlowerPetal 50 20 (20..72 | Get-Random) 18
128+
.EXAMPLE
129+
# Flower Petals look amazing when morphed
130+
$Radius = 23..42 | Get-Random
131+
$flowerAngle = 30..60 | Get-Random
132+
$AngleFactor = 2..6 | Get-Random
133+
$flowerPetals = turtle rotate (
134+
(Get-Random -Max 180) * -1
135+
) flowerPetal $radius 10 $flowerAngle $stepCount
136+
$flowerPetals2 = turtle rotate (
137+
(Get-Random -Max 180)
138+
) flowerPetal $radius (
139+
10 * $AngleFactor
140+
) $flowerAngle $stepCount
141+
turtle flowerPetal $radius 10 $flowerAngle $stepCount morph (
142+
$flowerPetals,
143+
$flowerPetals2,
144+
$flowerPetals
145+
)
118146
.EXAMPLE
119147
# We can construct a 'scissor' by drawing two lines at an angle
120148
turtle Scissor 42 60
@@ -140,21 +168,69 @@ function Get-Turtle {
140168
# We can draw an outward spiral by growing a bit each step
141169
turtle StepSpiral
142170
.EXAMPLE
143-
turtle StepSpiral 42 120 4 18
171+
turtle StepSpiral 42 120 4 18
172+
.EXAMPLE
173+
# Because Step Spirals are a fixed number of steps,
174+
# they are easy to morph.
175+
turtle StepSpiral 42 120 4 18 morph @(
176+
turtle StepSpiral 42 90 4 24
177+
turtle StepSpiral 42 120 4 24
178+
turtle StepSpiral 42 90 4 24
179+
)
144180
.EXAMPLE
145181
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
146182
.EXAMPLE
147183
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
184+
.EXAMPLE
185+
# Step spirals look lovely when morphed
186+
#
187+
# (especially when reversing angles)
188+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6) morph @(
189+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
190+
turtle @('StepSpiral',6, -120, 'rotate',120 * 6)
191+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
192+
)
193+
.EXAMPLE
194+
# When we reverse the spiral angle, the step spiral curve flips
195+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4) morph @(
196+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
197+
turtle @('StepSpiral',3, -90, 'rotate',90 * 4)
198+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
199+
)
200+
.EXAMPLE
201+
# When we reverse the rotation, the step spiral curve slides
202+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4) morph @(
203+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
204+
turtle @('StepSpiral',3, 90, 'rotate',-90 * 4)
205+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
206+
)
207+
.EXAMPLE
208+
# We we alternate, it looks amazing
209+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4) morph @(
210+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
211+
turtle @('StepSpiral',3, 90, 'rotate',-90 * 4)
212+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
213+
turtle @('StepSpiral',3, -90, 'rotate',90 * 4)
214+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
215+
)
216+
.EXAMPLE
217+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6) morph @(
218+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
219+
turtle @('StepSpiral',6, -120, 'rotate',120 * 6)
220+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
221+
turtle @('StepSpiral',6, 120, 'rotate',-120 * 6)
222+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
223+
)
148224
.EXAMPLE
149225
turtle spirolateral
150226
.EXAMPLE
151227
turtle spirolateral 50 60 10
152228
.EXAMPLE
153-
turtle spirolateral 50 120 6 @(1,3)
229+
turtle spirolateral 50 120 6 @(1,3)
154230
.EXAMPLE
155231
turtle spirolateral 23 144 8
156232
.EXAMPLE
157-
turtle spirolateral 23 72 8
233+
turtle spirolateral 23 72 8
158234
.EXAMPLE
159235
# Turtle can draw a number of fractals
160236
turtle BoxFractal 42 4
@@ -170,6 +246,9 @@ function Get-Turtle {
170246
.EXAMPLE
171247
# We can make a Pentaplexity
172248
turtle Pentaplexity 42 3
249+
.EXAMPLE
250+
# We can make a Triplexity
251+
turtle Triplexity 42 4
173252
.EXAMPLE
174253
# We can draw the Koch Island
175254
turtle KochIsland 42 4
@@ -179,6 +258,9 @@ function Get-Turtle {
179258
.EXAMPLE
180259
# We can make a Koch Snowflake
181260
turtle KochSnowflake 42
261+
.EXAMPLE
262+
# We can draw the Levy Curve
263+
turtle LevyCurve 42 6
182264
.EXAMPLE
183265
# We can use a Hilbert Curve to fill a space
184266
Turtle HilbertCurve 42 4
@@ -198,7 +280,7 @@ function Get-Turtle {
198280
# The SierpinskiTriangle is a Fractal classic
199281
turtle SierpinskiTriangle 42 4
200282
.EXAMPLE
201-
# We can draw a 'Sierpinski Snowflake' by rotating and drawing multiple Sierpinski Triangles
283+
# We can draw a 'Sierpinski Snowflake' with multiple Sierpinski Triangles.
202284
turtle @('rotate', 30, 'SierpinskiTriangle',42,4 * 12)
203285
.EXAMPLE
204286
turtle @('rotate', 45, 'SierpinskiTriangle',42,4 * 24)
@@ -267,7 +349,7 @@ function Get-Turtle {
267349
# otherwise, leave the argument alone.
268350
$arg
269351
}
270-
})
352+
})
271353

272354
# Now that we have a series of words, we can process them.
273355
# We want to keep track of the current member,
@@ -282,7 +364,7 @@ function Get-Turtle {
282364
$arg = $wordsAndArguments[$argIndex]
283365
# If the argument is not in the member names list, we can complain about it.
284366
if ($arg -notin $memberNames) {
285-
if (-not $currentMember -and $arg -is [string]) {
367+
if (-not $currentMember -and $arg -is [string] -and "$arg".Trim()) {
286368
Write-Warning "Unknown command '$arg'."
287369
}
288370
continue

Types/Turtle/get_PathAttribute.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if ($this.'.PathAttribute') {
2-
return $this.'.PathAttribute'
1+
if (-not $this.'.PathAttribute') {
2+
$this | Add-Member NoteProperty '.PathAttribute' ([Ordered]@{}) -Force
33
}
4-
return [Ordered]@{}
4+
return $this.'.PathAttribute'

0 commit comments

Comments
 (0)