Sierpinski pentagon: Difference between revisions

Content deleted Content added
Tim-brown (talk | contribs)
=={{header|Racket}}== created
Thundergnat (talk | contribs)
→‎{{header|Perl 6}}: Added implemaentation
Line 118: Line 118:
return Color.getHSBColor((float) hue, 1, 1);
return Color.getHSBColor((float) hue, 1, 1);
}
}
}</lang>

=={{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 $order = 5;
constant $dim = 1000;
constant $sides = 5;
constant factor = ( 3 - 5**.5 ) / 2;
my @orders = (.6 * $dim) «*» 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"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="{$dim*2}" width="{$dim*2}" version="1.1" xmlns="http://www.w3.org/2000/svg">
STOP
END say '</svg>';

my @vertices = map { cis( $_ * 2 * pi / $sides ) }, ^$sides;

for 0 .. $sides ** $order -> $i {
my $vector = [+] @vertices[$i.base($sides).fmt("%05d").comb] «*» @orders;
say pgon ((@orders[*-1] * (1-factor)) «*» @vertices «+» $vector)».reals».fmt("%0.3f");
};

sub pgon (*@q) {
qq:to/STOP/;
<polygon points="{@q}"
style="fill:blue;stroke:blue;stroke-width:0"
transform="translate({@tr[$order]}) rotate(-18)" />
STOP
}</lang>
}</lang>