<?
/* povgraph.php - 2003 by ftzdomino (fatz@fatkids.com)
do whatever you want with this.
  
sample call:
povgraph.php?v[]=10&v[]=5&v[]=7
notes:
you must have a httpd writeable tmp directory in a subdirectory of your document root.
you will want to delete these by cron or add code to do it after the fpassthru is complete
you need to have povray installed
*/

$out_file rand();
$in_file rand();

$bar_arr = array();

foreach(
$_GET['v'] as $vv)
{
if (
is_numeric($vv))
  
$bar_arr[] = $vv;
}



$outstr "global_settings { assumed_gamma 2.2 }

#include \"colors.inc\"

#declare Brown = color red 1 green 0.8 blue 0.2;

camera {
   location  <0, 25, -20>
   up y
   right x*1.33
   direction z*1.5
   look_at   <0, 5, 0>
}

#declare Orig_Fog = 1;
#declare Ground_Mist= 2;

fog{
    fog_type Ground_Mist
    fog_alt 3
    fog_offset 0
    distance 2
    color LightSteelBlue
    turbulence <0.05, 0.05, 0.05>
    omega 0.25
    lambda 2.5
    octaves 2
}
light_source { <100,300,-100> color White}

plane{
  y, -3
  pigment{ checker color White color Black}
  finish{diffuse 1}
  scale<3,1,3>
}

//sphere{<0,0,0> 1000 pigment{color Black}}
background { color Black }

#declare dd = 4;
#declare dd2 = 4;

#declare pole =   box { <-0.5, 0, -0.5> <0.5, 10, 0.5>
                  //cylinder{<0,-3,0>,<0,10,0>,0.7
                   pigment{color Brown}
                   finish{diffuse 2} scale <1,1.5,1>
                }

#declare row = union{
"
;

$ctr 0;
$maxval 0.00001;
foreach(
$bar_arr as $one_bar)
{
   
$maxval max($maxval$one_bar);
}

foreach(
$bar_arr as $one_bar)
{
$cur_val $one_bar $maxval;
$outstr .= ("                 object{pole translate<dd*$ctr,0,0> scale <1,$cur_val,1>}\n");
$ctr++;

}         
$outstr .="                

                 }

object{row rotate y*45 translate<-2*dd,0,0>}"
;
$fp fopen("tmp/$in_file.pov","wt");
fwrite($fp$outstr);
fclose($fp);


system("povray ".$_SERVER['DOCUMENT_ROOT']."/tmp/$in_file.pov AM2 Q9 +FN -D +O".$_SERVER['DOCUMENT_ROOT']."/tmp/$out_file.png > /dev/null");
$fp fopen($_SERVER['DOCUMENT_ROOT']."/tmp/$out_file.png","rb");
fpassthru($fp);

?>