Drawing a circle with PHP


<?php

// This is a basic PHP method for drawing a circle using x-y points.
// The output is HPGL.

$dia = .75;              // 3/4" circle, as if you didn't know
$rad = $dia/2;
$seg = pi()/round(64*$rad); // segment resolution
$start = pi()/4;         // pi is top, 0 is bottom, pi/4 is 45 deg. lead-in
$res = 1000;             // steps per inch for my HPGL
$x = 1000;               // start point
$y = 1000;

echo
"PU";
print
round($x);
echo
" ";
print
round($y);
echo
";\n";

for (
$i = $start$i <= 2*pi()+$start+.01; $i=$i+$seg)
{
echo
"PD";
print -
round(sin($i)*$rad*$res)+round($x);
echo
" ";
print -
round(cos($i)*$rad*$res)+round($y);
echo
";\n";
}

?>

This is what the output looks like.
(except it's in a form that's in a textarea)