Pentagram: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 174: Line 174:
ExitApp
ExitApp
Return</lang>
Return</lang>

=={{header|C}}==
=={{header|C}}==
Interactive program which takes the side lengths of the pentagram's core, it's arms and the colours for filling the background, drawing the figure and then filling it in. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
Interactive program which takes the side lengths of the pentagram's core, it's arms and the colours for filling the background, drawing the figure and then filling it in. Requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library.
Line 685: Line 686:
close $fh;</lang>
close $fh;</lang>
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/pentagram.svg Pentagram] (offsite image)
[https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/pentagram.svg Pentagram] (offsite image)

=={{header|Perl 6}}==
{{works with|rakudo|2018.08}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<lang perl6>use SVG;

constant $dim = 200;
constant $sides = 5;

my @vertices = map { 0.9 * $dim * cis($_ * τ / $sides) }, ^$sides;

my @points = map |*.reals.fmt("%0.3f"),
flat @vertices[0, 2 ... *], @vertices[1, 3 ... *], @vertices[0];

say SVG.serialize(
svg => [
:width($dim*2), :height($dim*2),
:rect[:width<100%>, :height<100%>, :style<fill:bisque;>],
:polyline[ :points(@points.join: ','),
:style("stroke:blue; stroke-width:3; fill:seashell;"),
:transform("translate($dim,$dim) rotate(-90)")
],
],
);</lang>
See [https://github.com/thundergnat/rc/blob/master/img/pentagram-perl6.svg Pentagram] (offsite svg image)

Ever wondered what a regular 7 sided star looks like? Change $sides to 7 and re-run.
See [https://github.com/thundergnat/rc/blob/master/img/heptagram-perl6.svg Heptagram]


=={{header|Phix}}==
=={{header|Phix}}==
Line 979: Line 952:
(star-polygon 100 5 2 "outline" (make-pen "blue" 4 "solid" "round" "round"))
(star-polygon 100 5 2 "outline" (make-pen "blue" 4 "solid" "round" "round"))
(star-polygon 100 5 2 "solid" "cyan"))</lang>
(star-polygon 100 5 2 "solid" "cyan"))</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|rakudo|2018.08}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<lang perl6>use SVG;

constant $dim = 200;
constant $sides = 5;

my @vertices = map { 0.9 * $dim * cis($_ * τ / $sides) }, ^$sides;

my @points = map |*.reals.fmt("%0.3f"),
flat @vertices[0, 2 ... *], @vertices[1, 3 ... *], @vertices[0];

say SVG.serialize(
svg => [
:width($dim*2), :height($dim*2),
:rect[:width<100%>, :height<100%>, :style<fill:bisque;>],
:polyline[ :points(@points.join: ','),
:style("stroke:blue; stroke-width:3; fill:seashell;"),
:transform("translate($dim,$dim) rotate(-90)")
],
],
);</lang>
See [https://github.com/thundergnat/rc/blob/master/img/pentagram-perl6.svg Pentagram] (offsite svg image)

Ever wondered what a regular 7 sided star looks like? Change $sides to 7 and re-run.
See [https://github.com/thundergnat/rc/blob/master/img/heptagram-perl6.svg Heptagram]


=={{header|Red}}==
=={{header|Red}}==
Line 1,310: Line 1,312:


}</lang>
}</lang>

=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Perl 6}}
{{trans|Perl 6}}
Line 1,408: Line 1,411:
End With
End With
End Sub</lang>
End Sub</lang>

=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Perl 6}}
{{trans|Perl 6}}