00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 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 ?>