There are also four diagonal lines, in red. On my monitor two of those, 1 and 4, look very good, i.e. perfectly smooth. But 2 and 3 both have a one pixle dog leg at what appears to be the midpoint. Normally I wouldn't expect a diagonal line to be perfectly smooth. But since lines 1 and 3 should be parallel and since line 3 appears perfectly smooth why doesn't 1? And the same question of course regarding lines 2 and 4.
Code below. Any help will be appreciated. Thanks, Bob
Code: Select all
<?php
function imgmsg($im,$msg)
{
static $msgoff = 0;
$black = imagecolorallocate($im,0,0,0);
$msgoff += 10;
// imagestring($im,3,10,$msgoff,$msg,$black);
}
//set up image
$height = 600;
$width = 600;
$im = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($im,255,255,255);
$black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,0);
// create the image
imagefill($im,0,0,$white);
// draw the circle
$center_x = $width/2;
$center_y = $height/2;
imagearc($im,$center_x,$center_y,$width-4,$height-4,0,360,$black );
// draw the radii
$radius = ($width-4)/2;
imgmsg($im,'$radius is ' . $radius);
$degree_interval = 90;
//imagestring($im,3,10,10,'before loop',$black);
//for ($angle = $degree_interval; $angle <= 360; $angle += $degree_interval )
for ($angle = 0; $angle <= 359; $angle += $degree_interval )
{ imgmsg($im,'in loop');
$x = sin(deg2rad($angle)) * $radius;
imgmsg($im,'$angle is '.$angle.' / $x is '.$x . ' / sin is ' . sin(deg2rad($angle)) );
$y = sin(deg2rad(90-$angle)) * $radius;
imgmsg($im,'$angle is ' . (90-$angle) .' / $y is '.$y. ' / sin is ' . sin(deg2rad(90-$angle)));
imageline($im,$center_x,$center_y,$x+$center_x, $y+$center_y,$black);
$points_x[] = $x;
$points_Y[] = $y;
if (isset($last_x))
{ imageline($im,$last_x+$center_x,$last_y+$center_y,$x+$center_x,$y+$center_y,$red);
}
else {$first_x = $x; $first_y = $y;}
$last_x = $x; $last_y = $y;
}
imageline($im,$last_x+$center_x,$last_y+$center_y,$first_x+$center_x,$first_y+$center_y,$red);
//imagestring($im,3,10,10,'loop done',$black);
// output image
Header('Content-type: image/png');
imagepng($im);
// clean up
imagedestroy($im);
?>