Skip to content

Commit 9f735e2

Browse files
feat: Turtle.Rhombus ( Fixes #372 )
Adding examples and golden angle rhombi
1 parent 4c9ffaa commit 9f735e2

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Types/Turtle/Rhombus.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
.SYNOPSIS
33
Draws a Rhombus
44
.DESCRIPTION
5-
Draws a Rhombus
5+
Draws a Rhombus in Turtle Graphics.
6+
.NOTES
7+
If you provide `NaN` or positive infinity `∞`, you'll get rhombus with a golden angle.
8+
9+
If you provide negative infinity `-∞`, you'll get a rhombus with a different golden angle.
610
.LINK
711
https://logothings.github.io/logothings/logo/SquashedSquares.html
812
.EXAMPLE
@@ -18,14 +22,22 @@
1822
turtle rhombus 20 10 90
1923
turtle rhombus 10 20 30
2024
)
25+
.EXAMPLE
26+
turtle rhombus 20 20 90 morph @(
27+
turtle rhombus 20 20 90
28+
turtle rhombus 20 10 30
29+
turtle rhombus 20 20 90
30+
turtle rhombus 10 20 -30
31+
turtle rhombus 20 20 90
32+
)
2133
.EXAMPLE
2234
# If we pass nan for an angle,
2335
# we use 1/the golden ratio as the angle
2436
turtle rhombus 10 20 nan
25-
.EXAMPLE
37+
.EXAMPLE
2638
turtle rhombus 10 20 nan morph @(
2739
turtle rhombus 10 20 nan
28-
turtle rhombus 20 10 nan
40+
turtle rhombus -20 -10 nan
2941
turtle rhombus 10 20 nan
3042
)
3143
#>
@@ -49,12 +61,15 @@ $Angle = $(
4961
)
5062
)
5163

52-
if ("$angle" -eq "NaN") {
64+
if ("$angle" -eq "NaN" -or
65+
"$angle" -eq "$([double]::PositiveInfinity)") {
5366
$angle =
5467
[Math]::Atan(1 / (1 + [Math]::Sqrt(5))) * 2 * 180/[Math]::Pi
68+
} elseif ($angle -eq "$([double]::NegativeInfinity)") {
69+
$angle =
70+
[Math]::Atan((1 + [Math]::Sqrt(5))) * 2 * 180/[Math]::Pi
5571
}
5672

57-
5873
$this.
5974
Forward($Side1).Rotate($Angle).
6075
Forward($Side2).Rotate(180-$Angle).

0 commit comments

Comments
 (0)