Pentagram: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: anonymous variables are stateful by default)
(→‎{{header|Perl 6}}: various simplifications)
Line 233: Line 233:
<lang perl6>constant $dim = 200;
<lang perl6>constant $dim = 200;
constant $sides = 5;
constant $sides = 5;

INIT say qq:to/STOP/;
INIT say qq:to/STOP/;
<?xml version="1.0" standalone="no" ?>
<?xml version="1.0" standalone="no" ?>
Line 241: Line 241:
STOP
STOP
END say '</svg>';
END say '</svg>';

my @vertices = map { 0.9 * $dim * cis($_ * 2 * pi / $sides) }, ^$sides;
my @vertices = map { 0.9 * $dim * cis($_ * 2 * pi / $sides) }, ^$sides;
@vertices = flat(@vertices[0, 2 ... *], @vertices[1, 3 ... *])
@vertices = map |*.reals, flat @vertices[0, 2 ... *], @vertices[1, 3 ... *];
.map: |*.reals».fmt("%0.3f");
@vertices.push(@vertices[0,1]);

say pline @vertices;
say pline @vertices;
for @vertices.rotor(4 => -2, :partial) -> @p {say pline @p};
for @vertices.rotor(4 => -2, :partial) -> @p {say pline @p};

sub pline (*@q) {
sub pline (*@q) {
qq:to/STOP/;
qq:to/STOP/;
<polyline points="{ join ' ', @q }"
<polyline points="@q[|^@q, 0, 1].fmt("%0.3f")"
style="fill:seashell;stroke:{<black red orange blue purple green>[$++ % 6]};stroke-width:2"
style="fill:seashell;stroke:{<black red orange blue purple green>[$++ % 6]};stroke-width:2"
transform="translate($dim, $dim) rotate(180)" />
transform="translate($dim, $dim) rotate(180)" />