Voronoi diagram: Difference between revisions
m
→{{header|Perl 6}}: added .race for concurrency, code tweaks
No edit summary |
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: added .race for concurrency, code tweaks) |
||
Line 1,241:
=={{header|Perl 6}}==
{{works with|Rakudo|
{{trans|Python}}
Perhaps "Inspired by Python" would be more accurate.
Line 1,249:
<lang perl6>use Image::PNG::Portable;
my @bars = '
my %type = ( # Voronoi diagram type distance calculation
Line 1,276:
sub voronoi (@domains, :$w, :$h, :$type) {
my $png = Image::PNG::Portable.new: :width($w), :height($h);
print "\b" x 2+@bars, @bars.=rotate(1).join , ' ';
for ^$h -> $y {
Line 1,287:
sub dot (%h, $png, $radius = 3) {
for (%h<x>
$png.set($x, $y, 0, 0, 0) if ( %h<x> - $x + (%h<y> - $y) * i ).abs <= $radius;
}
}
|