Skip to content

Commit 34743fc

Browse files
fix: Fractal Plant improvement ( Fixes #271 )
1 parent 2f56aad commit 34743fc

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

Types/Turtle/BinaryTree.ps1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
<#
2+
.SYNOPSIS
3+
Draws a binary tree
4+
.DESCRIPTION
5+
Draws a binary tree using an L-system.
6+
.LINK
7+
https://en.wikipedia.org/wiki/L-system#Example_2:_fractal_(binary)_tree
8+
#>
19
param(
2-
[double]$Size = 20,
3-
[int]$Order = 4,
4-
[double]$Angle = 45
10+
# The size of each segment
11+
[double]$Size = 42,
12+
# The order of magnitude (the number of times the L-system is expanded)
13+
[int]$Order = 4,
14+
# The angle
15+
[double]$Angle = 45
516
)
617
return $this.Rotate(-90).LSystem('0', [Ordered]@{
718
'1' = '11'
819
'0' = '1[0]0'
920
}, $Order, [Ordered]@{
1021
'[01]' = { $this.Forward($Size) }
11-
'\[' = { $this.Rotate($Angle * -1).Push() }
22+
'\[' = { $this.Push().Rotate($Angle * -1) }
1223
'\]' = { $this.Pop().Rotate($Angle) }
1324
})
1425

Types/Turtle/FractalPlant.ps1

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
<#
2+
.SYNOPSIS
3+
Draws a Fractal Plant
4+
.DESCRIPTION
5+
Draws a Fractal Plant as an L-System
6+
.LINK
7+
https://en.wikipedia.org/wiki/L-system#Example_7:_fractal_plant
8+
.EXAMPLE
9+
turtle FractalPlant save ./FractalPlant.svg
10+
.EXAMPLE
11+
turtle FractalPlant morph save ./FractalPlantMorph.svg
12+
#>
113
param(
2-
[double]$Size = 20,
14+
# The size of each segment
15+
[double]$Size = 42,
16+
# The order of magnitude (the number of times the L-system is expanded)
317
[int]$Order = 4,
4-
[double]$Angle = 25
18+
# The angle of each segment
19+
[double]$Angle = -25
520
)
621
return $this.Rotate(-90).LSystem('-X', [Ordered]@{
722
'X' = 'F+[[X]-X]-F[-FX]+X'
8-
'F' = 'FF'
23+
'F' = 'FF'
924
}, $Order, [Ordered]@{
10-
'F' = { $this.Forward($Size) }
11-
'\[' = { $this.Rotate($Angle * -1).Push() }
12-
'\]' = { $this.Pop().Rotate($Angle) }
13-
})
14-
25+
'F' = { $this.Forward($Size) }
26+
'\+' = { $this.Rotate($angle)}
27+
'\-' = { $this.Rotate($angle * -1)}
28+
'\[' = { $this.Push() }
29+
'\]' = { $this.Pop() }
30+
})

0 commit comments

Comments
 (0)