Skip to content

Commit 19d6b6d

Browse files
author
James Brundage
committed
feat: Turtle.KochIsland() ( Fixes #49 )
1 parent bba0bc4 commit 19d6b6d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Types/Turtle/KochIsland.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<#
2+
.SYNOPSIS
3+
Generates a Koch Island
4+
.DESCRIPTION
5+
Generates a Koch Island using turtle graphics.
6+
.EXAMPLE
7+
$turtle.KochIsland().Pattern.Save("$pwd/KochIsland.svg")
8+
.EXAMPLE
9+
$turtle.Clear()
10+
$turtle.KochIsland(10,4)
11+
$turtle.PatternTransform = @{
12+
'scale' = 0.9
13+
}
14+
$turtle.PatternAnimation = "
15+
<animateTransform attributeName='patternTransform' attributeType='XML' type='scale' values='1;0.9;1' dur='19s' repeatCount='indefinite' additive='sum' />
16+
<animateTransform attributeName='patternTransform' attributeType='XML' type='skewY' values='0;-30;30;-30;0' dur='67s' repeatCount='indefinite' additive='sum' />
17+
<animateTransform attributeName='patternTransform' attributeType='XML' type='skewX' values='0;-30;30;-30;0' dur='83s' repeatCount='indefinite' additive='sum' />
18+
<animateTransform attributeName='patternTransform' attributeType='XML' type='rotate' values='0;360' dur='163s' repeatCount='indefinite' additive='sum' />
19+
<animateTransform attributeName='patternTransform' attributeType='XML' type='translate' values='0 0;200 200;0 0' dur='283s' repeatCount='indefinite' additive='sum' />
20+
"
21+
$turtle.Pattern.Save("$pwd/KochIsland2.svg")
22+
#>
23+
param(
24+
[double]$Size = 20,
25+
[int]$Order = 3,
26+
[double]$Angle = 90
27+
)
28+
29+
return $this.LSystem('W', [Ordered]@{
30+
W = 'F+F+F+F'
31+
F = 'F+F-F-FF+F+F-F'
32+
}, $Order, [Ordered]@{
33+
'\+' = { $this.Rotate($Angle) }
34+
'-' = { $this.Rotate($Angle * -1) }
35+
'[FG]' = { $this.Forward($Size) }
36+
})

0 commit comments

Comments
 (0)