Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class RandomLinesBackgroundDrawer extends BackgroundDrawer
00016 {
00017 private $count = null;
00018
00019 public function __construct($count)
00020 {
00021 $this->count = $count;
00022 }
00023
00027 public function draw()
00028 {
00029 $imageId = $this->getTuringImage()->getImageId();
00030
00031 $height = $this->getTuringImage()->getHeight();
00032 $width = $this->getTuringImage()->getWidth();
00033
00034 for ($i = 0; $i < $this->count; ++$i) {
00035 $color = $this->makeColor();
00036 $colorId = $this->getTuringImage()->getColorIdentifier($color);
00037
00038 $y = mt_rand(1, $height - 1);
00039 $x = mt_rand(1, $width - 1);
00040
00041 $angle = mt_rand(0, 180);
00042
00043 while ($angle == 90)
00044 $angle = mt_rand(0, 180);
00045
00046 $angleRad = deg2rad($angle);
00047
00048 $dy = ($width - $x) * tan($angleRad);
00049
00050 if ($dy < $y) {
00051 $xEnd = $width;
00052 $yEnd = $y - $dy;
00053 } else {
00054 $yEnd = 0;
00055 $xEnd = $x + tan($angleRad) / $y;
00056 }
00057
00058 $dy = $x * tan($angleRad);
00059
00060 if ($dy <= ($height - $y)) {
00061 $xStart = 0;
00062 $yStart = $y + $dy;
00063 } else {
00064 $yStart = $height;
00065 $xStart = $x - tan($angleRad) / ($height - $y);
00066 }
00067
00068 imageline(
00069 $imageId,
00070 $xStart,
00071 $yStart,
00072 $xEnd,
00073 $yEnd,
00074 $colorId
00075 );
00076 }
00077
00078 return $this;
00079 }
00080 }
00081 ?>