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