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