Skip to content

Commit b25593e

Browse files
docs: Get-Turtle example expansion ( Fixes #149 )
1 parent 823e974 commit b25593e

File tree

1 file changed

+189
-7
lines changed

1 file changed

+189
-7
lines changed

Commands/Get-Turtle.ps1

Lines changed: 189 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,204 @@
11
function Get-Turtle {
22
<#
33
.SYNOPSIS
4-
Gets Turtle in PowerShell
4+
Gets Turtles
55
.DESCRIPTION
6-
Gets, sets, and moves a turtle object in PowerShell.
6+
Gets turtles in a PowerShell.
77
.NOTES
8-
Each argument can be the name of a member of the turtle object.
8+
Turtle Graphics are pretty groovy.
9+
10+
They have been kicking it since 1966, and they are how computers first learned to draw.
911
10-
After a member name is encountered, subsequent arguments will be passed to the member as parameters.
12+
They kicked off the first computer-aided design boom and inspired generations of artists, engineers, mathematicians, and physicists.
13+
14+
They are also _incredibly_ easy to build.
15+
16+
A Turtle graphic is described with a series of moves.
17+
18+
Let's start with the core three moves:
19+
20+
Imagine you are a Turtle holding a pen.
21+
22+
* You can turn `rotate`
23+
* You can move `forward`
24+
* You can lift the pen
25+
26+
These are the three basic moves a turtle can make.
27+
28+
We can describe more complex moves by combining these steps.
29+
30+
Each argument can be the name of a move of the turtle object.
31+
32+
After a member name is encountered, subsequent arguments will be passed to the member as parameters.
33+
.EXAMPLE
34+
# We can write shapes as a series of steps
35+
turtle rotate 120 forward 42 rotate 120 forward 42 rotate 120 forward 42
1136
.EXAMPLE
12-
turtle square 50
37+
# We can also use a method.
38+
# Polygon will draw an an N-sided polygon.
39+
turtle polygon 10 5
1340
.EXAMPLE
41+
# A simple case of this is a square
42+
turtle square 42
43+
.EXAMPLE
44+
# If we rotate 45 degrees first, our square becomes a rhombus
45+
turtle rotate 45 square 42
46+
.EXAMPLE
47+
# We can draw a circle
1448
turtle circle 10
1549
.EXAMPLE
16-
turtle polygon 10 6
50+
# Or a pair of half-circles
51+
turtle circle 10 0.5 rotate 90 circle 10 0.5
1752
.EXAMPLE
53+
# We can multiply arrays in PowerShell
54+
# this can make composing complex shapes easier.
55+
# Let's take the previous example and repeat it 8 times.
56+
turtle @('circle',42,0.5,'rotate',90 * 8)
57+
.EXAMPLE
58+
# Let's make a triangle by multiplying steps
1859
turtle ('forward', 10, 'rotate', 120 * 3)
19-
60+
.EXAMPLE
61+
# Let's make a series of polygons, decreasing in size
62+
turtle polygon 10 6 polygon 10 5 polygon 10 4 polygon 10 3
63+
.EXAMPLE
64+
# We can also use a loop to produce a series of steps
65+
# Let's extend our previous example and make 9 polygons
66+
turtle @(
67+
foreach ($n in 12..3) {
68+
'polygon'
69+
42
70+
$n
71+
}
72+
)
73+
.EXAMPLE
74+
# We can use the same trick to make successively larger polygons
75+
turtle @(
76+
$sideCount = 3..8 | Get-Random
77+
foreach ($n in 1..5) {
78+
'polygon'
79+
$n * 10
80+
$sideCount
81+
}
82+
)
83+
.EXAMPLE
84+
# A flower is a series of repeated polygons and rotations
85+
turtle Flower
86+
.EXAMPLE
87+
# Flowers look pretty with any number of polygons
88+
turtle Flower 50 10 (3..12 | Get-Random) 36
89+
.EXAMPLE
90+
# Flowers get less dense as we increase the angle and decrease the repetitions
91+
turtle Flower 50 15 (3..12 | Get-Random) 24
92+
.EXAMPLE
93+
# Flowers get more dense as we decrease the angle and increase the repetitions.
94+
turtle Flower 50 5 (3..12 | Get-Random) 72
95+
.EXAMPLE
96+
# We can draw a pair of arcs and turn back after each one
97+
turtle ArcRight 42 45 rotate (180 - 45) ArcRight 42 45 rotate (180 - 45)
98+
.EXAMPLE
99+
# We call this a 'petal'
100+
turtle Petal 42 60
101+
.EXAMPLE
102+
# We can construct a flower out of petals
103+
turtle FlowerPetal
104+
.EXAMPLE
105+
# Adjusting the angle of the petal makes our petal wider or thinner
106+
turtle FlowerPetal 42 15 (20..60 | Get-Random) 24
107+
.EXAMPLE
108+
# Flower Petals get more dense as we decrease the angle and increase repetitions
109+
turtle FlowerPetal 42 10 (10..50 | Get-Random) 36
110+
.EXAMPLE
111+
# Flower Petals get less dense as we increase the angle and decrease repetitions
112+
turtle FlowerPetal 50 20 (20..72 | Get-Random) 18
113+
.EXAMPLE
114+
# We can construct a 'scissor' by drawing two lines at an angle
115+
turtle Scissor 42 60
116+
.EXAMPLE
117+
# Drawing a scissor does not change the heading
118+
# So we can create a zig-zag pattern by multiply scissors
119+
turtle @('Scissor',42,60 * 4)
120+
.EXAMPLE
121+
# Getting a bit more interesting, we can create a polygon out of scissors
122+
# We will continually rotate until we have turned a multiple of 360 degrees.
123+
Turtle ScissorPoly 23 90 120
124+
.EXAMPLE
125+
Turtle ScissorPoly 23 60 72
126+
.EXAMPLE
127+
# This can get very chaotic, if it takes a while to reach a multiple of 360
128+
# Build N scissor polygons
129+
foreach ($n in 60..72) {
130+
Turtle ScissorPoly 16 $n $n
131+
}
132+
.EXAMPLE
133+
Turtle ScissorPoly 16 69 69
134+
.EXAMPLE
135+
# We can draw an outward spiral by growing a bit each step
136+
turtle StepSpiral
137+
.EXAMPLE
138+
turtle StepSpiral 42 120 4 18
139+
.EXAMPLE
140+
turtle @('StepSpiral',3, 120, 'rotate',60 * 6)
141+
.EXAMPLE
142+
turtle @('StepSpiral',3, 90, 'rotate',90 * 4)
143+
.EXAMPLE
144+
turtle spirolateral
145+
.EXAMPLE
146+
turtle spirolateral 50 60 10
147+
.EXAMPLE
148+
turtle spirolateral 50 120 6 @(1,3)
149+
.EXAMPLE
150+
turtle spirolateral 23 144 8
151+
.EXAMPLE
152+
turtle spirolateral 23 72 8
153+
.EXAMPLE
154+
turtle @('ArcLeft', 42, 12, 'ArcRight', 72, 60 * 6 )
155+
.EXAMPLE
156+
# Turtle can draw a number of fractals
157+
turtle BoxFractal 42 4
158+
.EXAMPLE
159+
# We can make a Board Fractal
160+
turtle BoardFractal 42 4
161+
.EXAMPLE
162+
# We can make a Crystal Fractal
163+
turtle CrystalFractal 42 4
164+
.EXAMPLE
165+
# We can make ring fractals
166+
turtle RingFractal 42 4
167+
.EXAMPLE
168+
# We can make a Pentaplexity
169+
turtle Pentaplexity 42 3
170+
.EXAMPLE
171+
# We can draw the Koch Island
172+
turtle KochIsland 42 4
173+
.EXAMPLE
174+
# Or we can draw the Koch Curve
175+
turtle KochCurve 42
176+
.EXAMPLE
177+
# We can make a Koch Snowflake
178+
turtle KochSnowflake 42
179+
.EXAMPLE
180+
# We can use a Hilbert Curve to fill a space
181+
Turtle HilbertCurve 42 4
182+
.EXAMPLE
183+
# We can use a Moore Curve to fill a space with a bit more density.
184+
turtle MooreCurve 42 4
185+
.EXAMPLE
186+
# We can show a binary tree
187+
turtle BinaryTree 42 4
188+
.EXAMPLE
189+
# We can also mimic plant growth
190+
turtle FractalPlant 42 4
191+
.EXAMPLE
192+
# The SierpinskiArrowHead Curve is pretty
193+
turtle SierpinskiArrowheadCurve 42 4
194+
.EXAMPLE
195+
# The SierpinskiTriangle is a Fractal classic
196+
turtle SierpinskiTriangle 42 4
197+
.EXAMPLE
198+
# We can draw a 'Sierpinski Snowflake' by rotating and drawing multiple Sierpinski Triangles
199+
turtle @('rotate', 30, 'SierpinskiTriangle',42,4 * 12)
200+
.EXAMPLE
201+
turtle @('rotate', 45, 'SierpinskiTriangle',42,4 * 24)
20202
#>
21203
[CmdletBinding(PositionalBinding=$false)]
22204
[Alias('turtle')]

0 commit comments

Comments
 (0)