#!/usr/bin/perl
# converts an pbm bitmap to a shape for meep!

# size of image in pixels
my $sx = 44;
my $sy = 46;

# open input file
defined($ARGV[0]) || die "Missing totally boring input filename.";
open(IN,"<$ARGV[0]") || die "Could not open totally boring input file.";


# load input data
foreach(<IN>){
	chomp;
	@tmp = split(/ /,$_);
	foreach(@tmp){
		push(@data,$_);
	}
}

# print out stuff for meep
for($y=0;$y<$sy;++$y){
for($x=0;$x<$sx;++$x){
	if($data[$y*$sx+$x]==1){
		$ly = ($y-$sy/2)/$sy;
		$lx = ($x-$sx/2)/$sx;
		print "(make block\n";
		print "\t(center (* sx $lx) (* sy $ly) (/ srr-sz 2))\n";
		print "\t(size (/ 1.25 res) (/ 1.25 res) srr-sz)\n";
		print "\t(material myAg))\n";
	}
}}
