CircleBackgroundDrawer.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Dmitry E. Demidov                          *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: CircleBackgroundDrawer.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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         /* void */ 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 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4