Jump to content

Voronoi diagram: Difference between revisions

m
→‎{{header|Perl 6}}: Add some progress indicators
m (→‎{{header|Perl 6}}: Add some progress indicators)
Line 1,248:
 
<lang perl6>use Image::PNG::Portable;
 
my @bars = '▁▂▃▄▅▆▇█▇▆▅▃▂▁'.comb;
 
my %type = ( # Voronoi diagram type distance calculation
Line 1,266 ⟶ 1,268:
 
for %type.keys -> $type {
print "\nGenerating $type diagram... ", ' ' x @bars;
my $img = voronoi(@domains, :w($width), :h($height), :$type);
@domains.map: *.&dot($img);
Line 1,273 ⟶ 1,276:
sub voronoi (@domains, :$w, :$h, :$type) {
my $png = Image::PNG::Portable.new: :width($w), :height($h);
for ^$w X ^$h -> ($x, $y) {
myprint ($,"\b" $i)x = min2+@bars, @domainsbars.map: { %type{$type}=rotate(%($_1)<x>,.join %($_)<y>, $x,' $y), $++ }';
$png.set:for ^$x,h -> $y, |@domains[$i]<rgb>{
my ($, $i) = min @domains.map: { %type{$type}(%($_)<x>, %($_)<y>, $x, $y), $++ };
$png.set: $x, $y, |@domains[$i]<rgb>
}
}
$png
Line 1,286 ⟶ 1,292:
}
}
}
}</lang>
 
See [https://github.com/thundergnat/rc/blob/master/img/Voronoi-Euclidean-perl6.png Euclidean], [https://github.com/thundergnat/rc/blob/master/img/Voronoi-Taxicab-perl6.png Taxicab] & [https://github.com/thundergnat/rc/blob/master/img/Voronoi-Minkowski-perl6.png Minkowski] Voronoi diagram example images.
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.