Sierpinski pentagon: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) →{{header|Perl 6}}: Added implemaentation |
Thundergnat (talk | contribs) m →{{header|Perl 6}}: fix off-by-one error, stabilize display coordinates, rename some variables, add image link |
||
Line 123:
{{works with|rakudo|2015-11-02}}
Generate an SVG file to STDOUT. Redirect to a file to capture and display it.
<lang perl6>constant
constant $dim =
constant $sides = 5;
constant scaling-factor = ( 3 - 5**.5 ) / 2;
my @orders = (
INIT say qq:to/STOP/;
<?xml version="1.0" standalone="no"?>
Line 140 ⟶ 138:
my @vertices = map { cis( $_ * 2 * pi / $sides ) }, ^$sides;
for 0 ..^ $sides **
my $vector = [+] @vertices[$i.base($sides).fmt("%
say pgon ((@orders[*-1] * (1 - scaling-factor)) «*» @vertices «+» $vector)».reals».fmt("%0.3f");
};
sub pgon (
qq|<polygon points="{@q}" style="fill:blue" transform="translate(
▲ transform="translate({@tr[$order]}) rotate(-18)" />
}</lang>
See [https://gist.github.com/thundergnat/c1b6cde8fff98dcd3f1e#file-pentaflake-svg 5th order pentaflake]
=={{header|Racket}}==
|