@@ -1848,20 +1848,43 @@ return $this
18481848.DESCRIPTION
18491849 Draws a star pattern with turtle graphics.
18501850.EXAMPLE
1851- $turtle = New-Turtle
1852- $turtle.Star().Pattern.Save("$pwd/Star.svg")
1851+ turtle star 42
1852+ .EXAMPLE
1853+ turtle star 42 20
1854+ .EXAMPLE
1855+ turtle star 42 20 @('rotate', (360/20*2), 'star', 42, 20 * 10) save ./StarFlower20.svg
18531856.EXAMPLE
1854- Move-Turtle Star | Save-Turtle "./Star.svg"
1857+ turtle star 42 20 @('rotate', (360/20*2), 'star', 42, 20 * 10) morph @(
1858+ turtle star 42 20 @('rotate', (360/20*2), 'star', 42, 20 * 10)
1859+ turtle star 42 20 @('rotate', (360/20*26), 'star', 42, 20 * 10)
1860+ turtle star 42 20 @('rotate', (360/20*2), 'star', 42, 20 * 10)
1861+ ) save ./StarFlower20Morph.svg
1862+ .EXAMPLE
1863+ turtle star 42 20 @('rotate', (360/20*18), 'star', 42, 20 * 10) save ./StarFlower-20-18.svg
18551864#>
18561865param(
1866+ # The approximate size of the star
18571867 [double]$Size = 50,
1858- [int]$Points = 5
1868+ # The number of points in the star
1869+ [int]$Points = 6
18591870)
1860- $Angle = 180 - (180 / $Points)
1861- foreach ($n in 1..$Points) {
1862- $this.Forward($Size)
1863- $this.Rotate($Angle)
1864- }
1871+
1872+ # To determine the angle, divide 360 by the number of points
1873+ $angle = 360 / $Points
1874+
1875+ $SegmentLength = ($Size*2)/$Points
1876+ # Each 'point' in the star actually consists of two points, an inward and outward point.
1877+ # Imagine we start an an outward point
1878+ $null = foreach ($n in 1..([Math]::Abs($Points))) {
1879+ $this. # We rotate by the angle and move forward one segment
1880+ Rotate($Angle).Forward($SegmentLength).
1881+ # The rotate back and move forward another segment
1882+ Rotate(-$angle).Forward($SegmentLength).
1883+ # then rotate once more so we continue moving around the circle
1884+ Rotate($angle)
1885+ } # we repeat this up to the number of points in order to draw a star with no crossings.
1886+
1887+ return $this
18651888
18661889 </Script >
18671890 </ScriptMethod >
0 commit comments