WavesBackgroundDrawer.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: WavesBackgroundDrawer.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class WavesBackgroundDrawer extends BackgroundDrawer
00017     {
00018         const MIN_WAVE_DISTANCE = 8;
00019         const MAX_WAVE_DISTANCE = 20;
00020         const MAX_WAVE_OFFSET   = 5;
00021         
00025         public function draw()
00026         {
00027             $y = mt_rand(-self::MAX_WAVE_OFFSET, self::MAX_WAVE_OFFSET);
00028             
00029             while ($y < $this->getTuringImage()->getHeight()) {
00030                 $this->drawWave($y);
00031                 
00032                 $y += mt_rand(self::MIN_WAVE_DISTANCE, self::MAX_WAVE_DISTANCE);
00033             }
00034             
00035             return $this;
00036         }
00037         
00038         /* void */ private function drawWave($y)
00039         {
00040             $radius = 5;
00041             $frequency = 30;
00042             
00043             $imageId = $this->getTuringImage()->getImageId();
00044             
00045             for (
00046                 $x = 0, $width = $this->getTuringImage()->getWidth();
00047                 $x < $width;
00048                 ++$x
00049             ) {
00050                 $color = $this->makeColor();
00051                 $colorId = $this->getTuringImage()->getColorIdentifier($color);
00052                 
00053                 $angle = $x % $frequency;
00054                 $angle = 2 * M_PI * $angle / $frequency;
00055                 
00056                 $dy = $radius * sin($angle);
00057                 
00058                 imagesetpixel(
00059                     $imageId,
00060                     $x,
00061                     $y + $dy,
00062                     $colorId
00063                 );
00064             }
00065         }
00066     }
00067 ?>

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