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 $order = 5;
constant $dim = 1000500;
constant $sides = 5;
constant scaling-factor = ( 3 - 5**.5 ) / 2;
my @orders = (.6(1 - scaling-factor) * $dim) «*» scaling-factor «**» (^$order);
 
my @tr = (0, (-900,1700), (-100,1450), (350,1250), (550,1200), (1000,1000));
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 ** $order -> $i {
my $vector = [+] @vertices[$i.base($sides).fmt("%05d{order}d").comb] «*» @orders;
say pgon ((@orders[*-1] * (1 - scaling-factor)) «*» @vertices «+» $vector)».reals».fmt("%0.3f");
};
 
sub pgon (*@q) {
qq|<polygon points="{@q}" style="fill:blue" transform="translate({@tr[$order]}dim,$dim) rotate(-18)" />|;
qq:to/STOP/;
<polygon points="{@q}"
style="fill:blue;stroke:blue;stroke-width:0"
transform="translate({@tr[$order]}) rotate(-18)" />
STOP
}</lang>
 
See [https://gist.github.com/thundergnat/c1b6cde8fff98dcd3f1e#file-pentaflake-svg 5th order pentaflake]
 
=={{header|Racket}}==