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: CurvedStringDrawer.class.php 4687 2007-12-09 18:57:18Z voxus $ */ 00012 00016 final class CurvedStringDrawer extends TextDrawer 00017 { 00018 const MAX_ANGLE_CHANGE = 40; 00019 const MAX_ANGLE = 45; 00020 const MAX_VERTIVAL_POSITION_CHANGE = 1.5; 00021 00025 public function draw($string) 00026 { 00027 $turingImage = $this->getTuringImage(); 00028 00029 $textWidth = 00030 $this->getTextWidth($string) 00031 + (strlen($string) - 1) 00032 * $this->getSize() / 2; 00033 00034 if ($turingImage->getWidth() <= $textWidth) 00035 return $this->showError(); 00036 00037 $angle = 00038 mt_rand( 00039 -CurvedStringDrawer::MAX_ANGLE_CHANGE / 2, 00040 CurvedStringDrawer::MAX_ANGLE_CHANGE / 2 00041 ); 00042 00043 $maxHeight = $this->getMaxCharacterHeight(); 00044 00045 $y = round(($turingImage->getHeight() + $maxHeight) / 2); 00046 $x = round(($turingImage->getWidth() - $textWidth) / 2); 00047 00048 for ($size = strlen($string), $i = 0; $i < $size; ++$i) { 00049 $angle += 00050 mt_rand( 00051 -CurvedStringDrawer::MAX_ANGLE_CHANGE / 2, 00052 CurvedStringDrawer::MAX_ANGLE_CHANGE / 2 00053 ); 00054 00055 if ($angle > CurvedStringDrawer::MAX_ANGLE) 00056 $angle = CurvedStringDrawer::MAX_ANGLE; 00057 elseif ($angle < -CurvedStringDrawer::MAX_ANGLE) 00058 $angle = -CurvedStringDrawer::MAX_ANGLE; 00059 00060 $y += 00061 mt_rand( 00062 -$turingImage->getHeight() / 2, 00063 $turingImage->getHeight() / 2 00064 ); 00065 00066 if ($y < ($maxHeight * CurvedStringDrawer::MAX_VERTIVAL_POSITION_CHANGE)) 00067 $y = $maxHeight * CurvedStringDrawer::MAX_VERTIVAL_POSITION_CHANGE; 00068 00069 if ($y > ($turingImage->getHeight() - $maxHeight)) 00070 $y = $turingImage->getHeight() - $maxHeight; 00071 00072 $character = $string[$i]; 00073 $this->drawCraracter($angle, $x, $y, $character); 00074 00075 $x += $this->getStringWidth($character) + $this->getSize() / 2; 00076 } 00077 00078 return $this; 00079 } 00080 } 00081 ?>