@@ -25,11 +25,11 @@ Turtle graphics starts with these two operations:
25
25
* Rotate() rotates the turtle
26
26
* Forward() moves forward
27
27
28
- We can easily represent these steps in memory, and draw them within a webpage using SVG.
28
+ We can easily keep a list of these steps in memory, and draw them with [ SVG] ( https://developer.mozilla.org/en-US/docs/Web/SVG ) .
29
29
30
- We can implement Turtle in any language.
30
+ We can make Turtle in any language.
31
31
32
- This module implements Turtle in PowerShell.
32
+ This module makes Turtle in PowerShell.
33
33
### Installing and Importing
34
34
35
35
We can install Turtle from the PowerShell Gallery:
@@ -59,6 +59,15 @@ Import-Module ./ -Force -PassThru
59
59
60
60
Once we've imported Turtle, we can create any number of turtles, and control them with commands and methods.
61
61
62
+ The turtle is represented as an object, and any number of commands can make or move turtles.
63
+
64
+ * New-Turtle created a turtle
65
+ * Move-Turtle performs a single turtle movement
66
+ * Set-Turtle changes the turtle's properties
67
+ * Save-Turtle saves the output of a turtle.
68
+
69
+ Last but not least: Get-Turtle lets you run multiple steps of turtle, and is aliased to urtle.
70
+
62
71
#### Drawing Simple Shapes
63
72
64
73
<div align =' center ' >
@@ -67,7 +76,7 @@ Once we've imported Turtle, we can create any number of turtles, and control the
67
76
</div >
68
77
69
78
70
- Let's start simple, by drawing a square.
79
+ Let's start simple, by drawing a square with a series of commands .
71
80
72
81
~~~ PowerShell
73
82
@@ -106,8 +115,32 @@ foreach ($n in 1..4) {
106
115
$turtle | Save-Turtle ./Square.svg
107
116
~~~
108
117
118
+ Or we could use ` Get-Turtle ` directly.
119
+
120
+ ~~~ PowerShell
121
+ turtle forward 10 rotate 90 forward 10 rotate 90 forward 10 rotate 90 forward 10 rotate 90 |
122
+ Save-Turtle ./Square.svg
123
+ ~~~
124
+
125
+ Or we could use ` Get-Turtle ` with a bit of PowerShell multiplication magic:
126
+
127
+ ~~~ PowerShell
128
+ turtle ('forward',10,'rotate',90 * 4) |
129
+ Save-Turtle ./Square.svg
130
+ ~~~
131
+
109
132
This just demonstrates how we can construct shapes out of these two simple primitive steps.
110
133
134
+ There are a shell of a lot of ways you can draw any shape.
135
+
136
+ Turtle has many methods to help you draw, including a convenience method for squares.
137
+
138
+ So our shortest square can be written as:
139
+
140
+ ~~~ PowerShell
141
+ turtle square 10 | Save-Turtle ./Square.svg
142
+ ~~~
143
+
111
144
We can also just say, make a square directly:
112
145
113
146
~~~ PowerShell
@@ -218,22 +251,17 @@ We can also animate the pattern, for endless variety:
218
251
$turtle = turtle KochSnowflake 10 4 |
219
252
Set-Turtle -Property PatternTransform -Value @{scale=0.33} |
220
253
set-turtle -property Fill -value '#4488ff' |
221
- Set-Turtle -Property PatternAnimation -Value "
222
-
223
- <animateTransform attributeName='patternTransform' attributeType='XML' type='scale' values='0.66;0.33;0.66' dur='23s' repeatCount='indefinite' additive='sum' />
224
-
225
- <animateTransform attributeName='patternTransform' attributeType='XML' type='rotate' from='0' to='360' dur='41s' repeatCount='indefinite' additive='sum' />
226
-
227
- <animateTransform attributeName='patternTransform' attributeType='XML' type='skewX' values='30;-30;30' dur='83s' repeatCount='indefinite' additive='sum' />
228
-
229
- <animateTransform attributeName='patternTransform' attributeType='XML' type='skewY' values='30;-30;30' dur='103s' repeatCount='indefinite' additive='sum' />
230
-
231
- <animateTransform attributeName='patternTransform' attributeType='XML' type='translate' values='0 0;42 42;0 0' dur='117s' repeatCount='indefinite' additive='sum' />
232
-
233
- "
234
-
235
-
236
-
254
+ Set-Turtle -Property PatternAnimation -Value ([Ordered]@{
255
+ type = 'scale' ; values = 0.66,0.33, 0.66 ; repeatCount = 'indefinite' ;dur = "23s"; additive = 'sum'
256
+ }, [Ordered]@{
257
+ type = 'rotate' ; values = 0, 360 ;repeatCount = 'indefinite'; dur = "41s"; additive = 'sum'
258
+ }, [Ordered]@{
259
+ type = 'skewX' ; values = -30,30,-30;repeatCount = 'indefinite';dur = "83s";additive = 'sum'
260
+ }, [Ordered]@{
261
+ type = 'skewY' ; values = 30,-30, 30;repeatCount = 'indefinite';additive = 'sum';dur = "103s"
262
+ }, [Ordered]@{
263
+ type = 'translate';values = "0 0","42 42", "0 0";repeatCount = 'indefinite';additive = 'sum';dur = "117s"
264
+ })
237
265
238
266
$turtle | save-turtle -Path ./EndlessSnowflake.svg -Property Pattern
239
267
Pop-Location
0 commit comments