Source

boxer / lace-maker

Full commit
Trammell Hudson 9f9115f 





Trammell Hudson 75b4686 
Trammell Hudson 9f9115f 











Trammell Hudson 75b4686 
Trammell Hudson 9f9115f 

Trammell Hudson 75b4686 





















Trammell Hudson 9f9115f 
Trammell Hudson 75b4686 
Trammell Hudson 9f9115f 
Trammell Hudson 75b4686 
Trammell Hudson 9f9115f 







Trammell Hudson 75b4686 

Trammell Hudson 9f9115f 




Trammell Hudson 75b4686 
Trammell Hudson 9f9115f 








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

my $size = 300;
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 -->

POLY:
for my $poly ($geo->polygons)
{
	my $index = shift @$poly;
	my $count = @$poly;
	my $cx = 0;
	my $cy = 0;

	# Find the center point of the polygon.
	# Throw away any polygons that are outside of the box.
	for (my $i = 0 ; $i < $count-1 ; $i++)
	{
		my ($x0,$y0) = @{ $poly->[$i+0] };
		my ($x1,$y1) = @{ $poly->[$i+1] };
		my $a0 = $x0*$y1 - $x1*$y0;

		$cx += ($x0 + $x1) * $a0;
		$cy += ($y0 + $y1) * $a0;
		$a += $a0 / 2;
	}

	$cx /= 6 * $a;
	$cy /= 6 * $a;
	printf STDERR "%.5f, %.5f\n", $cx, $cy;

	print <<"";
		<g transform	= "translate($cx,$cy)" >
		<path
			transform	= "scale(0.5)"
			stroke		= "#ff0000"
			fill		= "none"
			stroke-width	= "0.1px"
			d		= "M

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

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

	#print Dumper($poly);
}


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

__END__