Drawing an ellipse with PHP


<?php

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

$dia = .5;              // 1/2" wide
$dia2 = 1;              //  1" tall
$rad = $dia/2;
$rad2 = $dia2/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)*$rad2*$res)+round($y);
echo
";\n";
}

?>

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