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