RandomLinesBackgroundDrawer.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: RandomLinesBackgroundDrawer.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class RandomLinesBackgroundDrawer extends BackgroundDrawer
00017     {
00018         private $count = null;
00019         
00020         public function __construct($count)
00021         {
00022             $this->count = $count;
00023         }
00024         
00028         public function draw()
00029         {
00030             $imageId = $this->getTuringImage()->getImageId();
00031             
00032             $height = $this->getTuringImage()->getHeight();
00033             $width = $this->getTuringImage()->getWidth();
00034             
00035             for ($i = 0; $i < $this->count; ++$i) {
00036                 $color = $this->makeColor();
00037                 $colorId = $this->getTuringImage()->getColorIdentifier($color);
00038                 
00039                 $y = mt_rand(1, $height - 1);
00040                 $x = mt_rand(1, $width - 1);
00041                 
00042                 $angle = mt_rand(0, 180);
00043                 
00044                 while ($angle == 90)
00045                     $angle = mt_rand(0, 180);
00046                 
00047                 $angleRad = deg2rad($angle);
00048                 
00049                 $dy = ($width - $x) * tan($angleRad);
00050                 
00051                 if ($dy < $y) {
00052                     $xEnd = $width;
00053                     $yEnd = $y - $dy;
00054                 } else {
00055                     $yEnd = 0;
00056                     $xEnd = $x + tan($angleRad) / $y;
00057                 }
00058                 
00059                 $dy = $x * tan($angleRad);
00060                 
00061                 if ($dy <= ($height - $y)) {
00062                     $xStart = 0;
00063                     $yStart = $y + $dy;
00064                 } else {
00065                     $yStart = $height;
00066                     $xStart = $x - tan($angleRad) / ($height - $y);
00067                 }
00068                 
00069                 imageline(
00070                     $imageId,
00071                     $xStart,
00072                     $yStart,
00073                     $xEnd,
00074                     $yEnd,
00075                     $colorId
00076                 );
00077             }
00078             
00079             return $this;
00080         }
00081     }
00082 ?>

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