Pentagram: Difference between revisions

(→‎{{header|Perl 6}}: style : using phasers, complex numbers and infinite sequences)
Line 229:
 
=={{header|Perl 6}}==
{{works with|rakudo|2015-11-02}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<lang perl6>constant $dim = 200;
constant $sides = 5;
 
INIT say qq:to /STOP/;
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
<svg height="{$dim*2}" width="{$dim*2}" xmlns="http://www.w3.org/2000/svg">
STOP
END say '</svg>';
 
my @vertices = map { 0.9 * $dim * cis($_ * 2 * pi / $sides) }, ^$sides;
@vertices = |flat(@vertices[0, 2 ... *], |@vertices[1, 3 ... *];)
@vertices .=map(: |*.reals».fmt("%0.3f"));
@vertices.push(@vertices[0,1]);
 
say pline( flat @vertices );
for @vertices.rotor(4 => -2, :partial) -> @p {say pline( flat @p )};
 
sub pline (*@q) {
qq:to/STOP/;
qq| <polyline points="{ join ' ', @q }"
style="fill:seashell;stroke:{<black red orange blue purple green>[state $++ % 6]};stroke-width:2"
transform="translate($dim, $dim) rotate(180)" />\n|
STOP
}</lang>
 
Anonymous user