Skip to content

Commit b76b885

Browse files
feat: Lucky turtle and random defaults ( Fixes #363, Fixes #366 )
Randomizing sun, stepcurve, twindragon, triplexity
1 parent a331987 commit b76b885

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

Types/Turtle/StepCurve.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#>
99
param(
1010
# The DeltaX
11-
[double]$DeltaX = $(Get-Random -Min -100.0 -Max 100.0),
11+
[double]$DeltaX = $(Get-Random -Min -10.0 -Max 10.0),
1212
# The DeltaY
13-
[double]$DeltaY = $(Get-Random -Min -100.0 -Max 100.0)
13+
[double]$DeltaY = $(Get-Random -Min -10.0 -Max 10.0)
1414
)
1515

1616
# If both coordinates are empty, we aren't going anywhere.

Types/Turtle/Sun.ps1

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
param(
4848
# The length of both arcs
4949
[double]
50-
$Length = 42,
50+
$Length = $(Get-Random -Min 42 -Max 81),
5151

5252
# The rotation after each step
5353
[double]
54-
$Angle = 160,
54+
$Rotation = $(Get-Random -Min 60 -Max 270),
5555

5656
# The angle of the rays of the sun
5757
[double]
@@ -60,11 +60,27 @@ $RayAngle = 90,
6060
# The number of steps to draw.
6161
# In order to close the shape, this multiplied by the angle should be a multiple of 360.
6262
[int]
63-
$StepCount = 9
63+
$StepCount = 0
6464
)
6565

66-
# If there are no steps to draw, return this
67-
if ($stepCount -eq 0) { return $this }
66+
if ($rotation -eq 0 -and $StepCount -eq 0) {
67+
return $this
68+
}
69+
70+
71+
# If no step count was provided
72+
if ($StepCount -eq 0) {
73+
# pick a random number of rotations
74+
$revolutions = (Get-Random -Minimum 1 -Max 16)
75+
# and figure out how many steps at our angle it takes to get there.
76+
foreach ($n in 2..$revolutions) {
77+
$revNumber = ($revolutions * 360)/$Rotation
78+
$StepCount = [Math]::Ceiling($revNumber)
79+
if ([Math]::Floor($revNumber) -eq $revNumber) {
80+
break
81+
}
82+
}
83+
}
6884

6985
# Every step we take
7086
$null = foreach ($n in 1..([Math]::Abs($StepCount))) {
@@ -74,7 +90,7 @@ $null = foreach ($n in 1..([Math]::Abs($StepCount))) {
7490
# then arc left
7591
ArcLeft($length/2, $RayAngle).
7692
# then rotate.
77-
Rotate($Angle)
93+
Rotate($Rotation)
7894
}
7995

8096
# Return this so we never break the chain.

Types/Turtle/Triplexity.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#>
1919
param(
2020
# The size of each segment
21-
[double]$Size = 42,
21+
[double]$Size = (Get-Random -Min 21 -Max 21),
2222
# The order of magnitude (the number of expansions)
23-
[int]$Order = 4,
23+
[int]$Order = (2,3,4 | Get-Random),
2424
# The default angle.
2525
[double]$Angle = 60
2626
)

Types/Turtle/TwinDragonCurve.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
#>
2525

2626
param(
27-
[double]$Size = 20,
28-
[int]$Order = 6,
27+
[double]$Size = (Get-Random -Min 21 -Max 42),
28+
[int]$Order = (3,4,5,6, 7, 8 | Get-Random ),
2929
[double]$Angle = 90
3030
)
3131
return $this.LSystem('FX+FX+', [Ordered]@{
3232
X = 'X+YF'
3333
Y = 'FX-Y'
3434
}, $Order, [Ordered]@{
3535
'\+' = { $this.Rotate($Angle) }
36-
'-' = { $this.Rotate($Angle * -1) }
36+
'\-' = { $this.Rotate($Angle * -1) }
3737
'[F]' = { $this.Forward($Size) }
3838
})

0 commit comments

Comments
 (0)