<?php

function microtime_float()
{
   list(
$usec$sec) = explode(" "microtime());
   return ((float)
$usec + (float)$sec);
}

$time_start microtime_float();
error_reporting(E_ALL E_STRICT);

/* calculates the total area of an arc in a given pixel
   this is used to determine the shading */

@dl('aa_gd.so');

$demo_w 500;
$demo_h 350;

$im = @imagecreatetruecolor ($demo_w$demo_h)
    or die (
"Cannot Initialize new GD image stream");
$background_color imagecolorallocate ($im255255255);
imagefill($im0,0,$background_color);
$text_color imagecolorallocatealpha ($im233149180);
$seed rand(0,1000000);
mt_srand($seed);
imagestring ($im155,  "Seed: $seed"$text_color);


for(
$i 0$i 20$i++) {
  
$rand_color =  imagecolorallocatealpha ($immt_rand(0,255), mt_rand(0,255), mt_rand(0,255), mt_rand(0,127));
  
$x mt_rand(0$demo_w);
  
$y mt_rand(0$demo_h);
  
$w mt_rand(1$demo_h/2);
  
$h mt_rand(1$demo_w/2);
  
$s mt_rand(0,360);
  
$e mt_rand(0360);
    
aa_filled_arc($im$x$y$w$h$s$e$rand_color);
    
//  test_compare($im, $x, $y, $w, $h, $s, $e, $rand_color);

   
}

function 
test_compare($im$cx$cy$w$h$given_start_angle$given_end_angle$color)


  
// draw an arc with gd
  
imagefilledarc($im$cx$cy$w$h$given_start_angle$given_end_angle$colorIMG_ARC_PIE);

  
// now outline the angles
  
$x_at_start $h*sin(deg2rad($given_start_angle));
  
$y_at_start $w*cos(deg2rad($given_start_angle));
  
$start_angle rad2deg(atan2($y_at_start$x_at_start));

  
$x_at_end $h*sin(deg2rad($given_end_angle));
  
$y_at_end $w*cos(deg2rad($given_end_angle));
  
$end_angle rad2deg(atan2($y_at_end$x_at_end));  

  
/* normalize angles */
  
if ($start_angle 0) {
    
$start_angle += 360;
  }
  if (
$end_angle 0) {
    
$end_angle += 360;
  }
  
$start_angle fmod($start_angle360);
  
$end_angle fmod($end_angle360);
 

  
imageline($im$cx$cy$cx+150*sin(deg2rad($start_angle)),  $cy+150*cos(deg2rad($start_angle)), $color);
    
    
imageline($im$cx$cy$cx+150*sin(deg2rad($end_angle)),  $cy+150*cos(deg2rad($end_angle)), $color);

}


//imageline($im, 1,1,500,300,$text_color);
header ("Content-type: image/png");
imagepng ($im);
/*
imagepng ($im, $_SERVER['DOCUMENT_ROOT'].'/nerd/tmp/testout.png');

$time_end = microtime_float();
$time = $time_end - $time_start;

echo "$time seconds\n";

echo('img<br>');
echo('<img src="tmp/testout.png?a='.rand().'">');
*/

?>