#!/usr/bin/perl

die <<USAGE if @ARGV < 2;
Usage: genforest radius_ft angle
USAGE

$rad = $ARGV[0];
$ang = $ARGV[1];
$arclen = 6.3 * $rad * ($ang/360);

# space trees about 15 ft apart. vary distance by up to 10 ft (plus/minus)
$steps = $arclen / 15;
$stepang = ($ang / $steps);

srand(time);

for($i=0; $i < $steps; $i++) {
   $variance = (rand(25)-12.5)/100;
   $theta = 3.141579 / 180 * ($i + $variance) * $stepang;
   $x = int($rad * sin($theta)) * 12;
   $y = int($rad * cos($theta)) * 12;
   $rot = int(rand(360));
   $size = rand(4) + 10;
   print <<TREE;

void instance tree.$i
9 tree.oct -rz $rot -s $size -t $x $y 0
0
0
TREE
}
