use overload; use Math::Complex; # Declare all Entries that I will use globally. This is more for me to keep track # of them then actuall program syntax.. ;-) my(@BranchDepth, @BranchLenVar, @BranchMinLen, @BranchMaxEnds, @BranchAngle, @BranchEnd, @BranchEnds, @BranchParent, @BranchDepth, @BranchX, @BranchY, @BranchZ, @BranchAngle, $Branches, @sintab, @costab, @BranchAngleZ, @BranchWidth); # Initialize the values.. These values are educated guesses at the moment.. # if($ARGV[0] eq("V")) { # $verbose = 1; # } print "Pre Computing Sin and Cosin tables..\n"; $sintab[0] = sin(2 * pi); $costab[0] = cos(2 * pi); $test = (2 * pi) / 360; for($t=1;$t<721; $t++) { $sintab[$t] = sin($t * $test); $costab[$t] = cos($t * $test); print "."; } print "\n"; srand(); open(OUT, ">tree.pov"); print OUT "union {\n"; for($tree = 0;$tree < 150;$tree++) { $treelevel = rand(200); $treeleveldec = abs(($treelevel / 200) - 1); $Branches = 0; @BranchLenVar = (25, 20, 6, 3, 2, 1); @BranchMinLen = (5, 10, 6.5, 4.5, 2.5, 1); @BranchMaxEnds = (4, 4, 4, 5, 2, 1, 1); @BranchWidth = (.7, .5, .4, .3, .2, .1, .1); # Start the whole shabang off. This is basically a modified NewBranch routine # specifically designed for the mastwer branch.. It takes some things for # Granted, as there IS no parent branch for this.. $BranchZ[0] = rand(10); $BranchY[0] = rand(10) + 20; $BranchX[0] = 0; $BranchAngle[0] = 0; $BranchAngleZ[0] = 0; print OUT "union {\n"; print OUT<, .8, <$BranchX[0], $BranchY[0], $BranchZ[0]>, $BranchWidth[0] } EOF #print "Master Branch Created!\n"; #print "---- Master Branch from 0,0 to $BranchX[0], $BranchY[0], $BranchZ[0]\n"; print "."; $BranchEnds[0] = rand(4); # The headache section. This will call newbranch for each branch.. while($BranchEnds[0] > 0) { print "\nCreating New Branch.\n"; $Branches++; &NewBranch(0, $Branches, 0); $BranchEnds[0]--; } local $rot = rand(360); print OUT "rotate z*$rot\n"; print OUT "scale $treeleveldec\n"; print OUT "translate <0, 0, $treelevel>\n"; print OUT "}\n"; } print OUT "cone {"; print OUT "<0, 0, 0>, 2.5, <0, 0, 200>, .3 }\n"; print OUT "}\n"; close(OUT); exit(); # Well, actually, this is the cause of the headache.. It will create branches # off the branch that passes it, which will in turn do the same, untill it # gets deep enough that it doesn;t create any more, at which point it returns # untill it finds more to do.. 99.9 % of the programs work.. ;-P sub NewBranch { local $ThisBranch = $_[1]; local $ParentBranch = $_[0]; local $BranchDepth = $_[2]; local $length = rand($BranchLenVar[$BranchDepth]) + $BranchMinLen[$BranchDepth]; # print "Branch # $ThisBranch Created..\n"; print "."; $BranchAngle[$ThisBranch] = (rand(50) - 25) + $BranchAngle[$ParentBranch]; $BranchAngleZ[$ThisBranch] = (rand(40) - 20) + $BranchAngleZ[$ParentBranch]; $BranchX[$ThisBranch] = ($sintab[$BranchAngle[$ThisBranch] + $BranchAngle[$ParentBranch]]) * $length; $BranchY[$ThisBranch] = ($costab[$BranchAngle[$ThisBranch] + $BranchAngle[$ParentBranch]] * $length) + $BranchY[$ParentBranch]; $BranchZ[$ThisBranch] = ($sintab[$BranchAngleZ[$ThisBranch] + $BranchAngleZ[$ParentBranch]] * $length) + $BranchZ[$ParentBranch]; $BranchX[$ThisBranch] = ($costab[$BranchAngleZ[$ThisBranch] + $BranchAngleZ[$ParentBranch]] * $BranchX[$ThisBranch]) + $BranchX[$ParentBranch]; print OUT<, $BranchWidth[$BranchDepth - 1], <$BranchX[$ThisBranch], $BranchY[$ThisBranch], $BranchZ[$ThisBranch]>, $BranchWidth[$BranchDepth] } EOF # print "---- Branch $ThisBranch from $BranchX[$ParentBranch], $BranchY[$ParentBranch] to $BranchX[$ThisBranch], $BranchY[$ThisBranch]\n"; # print "-------Branch Level is $BranchDepth, Parent is $ParentBranch\n"; print "."; $BranchEnds[$ThisBranch] = rand($BranchMaxEnds[$BranchDepth]) - 1; while($BranchEnds[$ThisBranch] > 0) { $Branches++; NewBranch($ThisBranch, $Branches, $BranchDepth + 1); $BranchEnds[$ThisBranch]--; } }