Source

boxer / lace-maker

Full commit
#!/opt/local/bin/perl
use warnings;
use strict;
use Data::Dumper;
use Math::Geometry::Voronoi;

my $size = 100;
my $num = 10;

my @points = map { [ rand $size, rand $size ] } 0..$num;

my $geo = Math::Geometry::Voronoi->new(points => \@points);
$geo->compute;

print <<"";
<!-- Created with lace-maker (http://trmm.net/) -->
<svg xmlns="http://www.w3.org/2000/svg">
<g transform="scale(3.543307)"><!-- scale to mm -->

for my $poly ($geo->polygons)
{
	print <<"";
		<path
			stroke		= "#ff0000"
			fill		= "none"
			stroke-width	= "0.1px"
			d		= "M

	my $index = shift @$poly;

	for my $pt (@$poly)
	{
		my ($x,$y) = @$pt;
		print "$x,$y\n";
	}

	# Close the path
	print <<"";
		Z"/>

	#print Dumper($poly);
}


print <<"";
</g>
</svg>

__END__