Here is a piece of code using imagefilledellipse which creates a simulation of the current phase of the moon...
Usage is <img src="moon.php?size=100"> which produces an image 100px by 100px wide. If size is left out, the default is 24px by 24px.
<?php
$mps=2551442.8; $position=time()-mktime(10, 32, 0, 1, 25, 2005); $position=($position-$mps*intval($position/$mps))/$mps; $position=2*(0.5-$position);
$size=$_GET['size'];
if (!is_numeric($size)) $size=24; $moon=imagecreate($size, $size);
$dark=imagecolorallocate($moon, 0, 34, 68); $light=imagecolorallocate($moon, 238, 238, 255); $corona=imagecolorallocatealpha($moon, 153, 153, 153, 64); $background=imagecolorallocatealpha($moon, 0, 0, 0, 127);
imagefill($moon, 0, 0, $background);
imagefilledellipse($moon, round($size/2), round($size/2), $size, $size, $corona);
if ($position>-1/$size AND $position<1/$size) imagefilledellipse($moon, round($size/2), round($size/2), $size-2, $size-2, $dark); elseif (abs($position)>1-1/$size) imagefilledellipse($moon, round($size/2), round($size/2), $size-2, $size-2, $light); elseif ($position>0) {
imagefilledellipse($moon, round($size/2), round($size/2), $size-2, $size-2, $light);
for ($i=0; $i<$size-2; $i++) {
$xpos=($size-2)/2;
$xpos=1-($i/$xpos);
$xpos=sqrt(1-($xpos*$xpos));
$xpos=($size/2)+($position-0.5)*$xpos*($size-2);
imagesetpixel($moon, round($xpos), $i+1, $dark);
}
for ($i=0; $i<$size; $i++) {
$set=0;
for ($j=0; $j<$size; $j++) {
if (!$set AND imagecolorat($moon, $j, $i)==$dark) $set=1;
elseif ($set AND imagecolorat($moon, $j, $i)==$light) imagesetpixel($moon, $j, $i, $dark);
}
}
}
else {
imagefilledellipse($moon, round($size/2), round($size/2), $size-2, $size-2, $dark);
for ($i=0; $i<$size-2; $i++) {
$xpos=($size-2)/2;
$xpos=1-($i/$xpos);
$xpos=sqrt(1-($xpos*$xpos));
$xpos=($size/2)+($position+0.5)*$xpos*($size-2);
imagesetpixel($moon, round($xpos), $i+1, $light);
}
for ($i=0; $i<$size; $i++) {
$set=0;
for ($j=0; $j<$size; $j++) {
if (!$set AND imagecolorat($moon, $j, $i)==$light) $set=1;
elseif ($set AND imagecolorat($moon, $j, $i)==$dark) imagesetpixel($moon, $j, $i, $light);
}
}
}
header ("Content-Type: image/png");
imagepng($moon);
imagedestroy($moon);
?>