00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class CircleBackgroundDrawer extends BackgroundDrawer
00017 {
00018 const VERTEX_COUNT = 20;
00019
00020 private $minRadius = null;
00021 private $maxRadius = null;
00022 private $count = null;
00023
00024 public function __construct($count, $minRadius, $maxRadius = null)
00025 {
00026 if ($maxRadius === null)
00027 $maxRadius = $minRadius;
00028
00029 $this->maxRadius = $maxRadius;
00030 $this->minRadius = $minRadius;
00031 $this->count = $count;
00032 }
00033
00037 public function draw()
00038 {
00039 for ($i = 0; $i < $this->count; ++$i) {
00040 $y = mt_rand(0, $this->getTuringImage()->getHeight());
00041 $x = mt_rand(0, $this->getTuringImage()->getWidth());
00042
00043 $radius = mt_rand($this->minRadius, $this->maxRadius);
00044
00045 $this->drawCircle($x, $y, $radius);
00046 }
00047
00048 return $this;
00049 }
00050
00051 private function drawCircle($x, $y, $radius)
00052 {
00053 $vertexArray = array();
00054
00055 $angleStep = 360 / CircleBackgroundDrawer::VERTEX_COUNT;
00056 $angle = 0;
00057
00058 for ($i = 0; $i < CircleBackgroundDrawer::VERTEX_COUNT; ++$i) {
00059 $color = $this->makeColor();
00060 $colorId = $this->getTuringImage()->getColorIdentifier($color);
00061
00062 $angleRad = deg2rad($angle);
00063
00064 $dx = sin($angleRad) * $radius;
00065 $dy = cos($angleRad) * $radius;
00066
00067 $vertexArray[] = $x + $dx;
00068 $vertexArray[] = $y + $dy;
00069
00070 $angle += $angleStep;
00071 }
00072
00073 imagefilledpolygon(
00074 $this->getTuringImage()->getImageId(),
00075 $vertexArray,
00076 CircleBackgroundDrawer::VERTEX_COUNT,
00077 $colorId
00078 );
00079 }
00080 }
00081 ?>