Пример #1
0
 /**
  * Draw a polygon with a background
  *
  * @param mixed $background Background (can be a color or a gradient)
  * @param Polygon A polygon
  */
 public function filledPolygon($background, awPolygon $polygon)
 {
     $shape = new SWFShape();
     if ($background instanceof awColor) {
         list($red, $green, $blue, $alpha) = $this->getColor($background);
         $shape->setRightFill($red, $green, $blue, $alpha);
     } elseif ($background instanceof awGradient) {
         list($flashGradient, $style) = $this->getGradient($background);
         $fill = $shape->addFill($flashGradient, $style);
         list($xMin, $xMax) = $polygon->getBoxXRange();
         list($yMin, $yMax) = $polygon->getBoxYRange();
         if ($background->angle === 0) {
             $fill->scaleTo(($yMax - $yMin) / 1600);
         } else {
             $fill->scaleTo(($xMax - $xMin) / 1600);
         }
         $fill->moveTo($xMin + ($xMax - $xMin) / 2, $yMin + ($yMax - $yMin) / 2);
         $shape->setRightFill($fill);
     }
     $points = $polygon->all();
     $count = count($points);
     if ($count > 1) {
         $prev = $points[0];
         $shape->movePenTo($prev->x, $prev->y);
         for ($i = 1; $i < $count; $i++) {
             $current = $points[$i];
             $shape->drawLineTo($current->x, $current->y);
         }
         // Close the polygon
         $shape->drawLineTo($prev->x, $prev->y);
         $this->movie->add($shape);
     }
 }
Пример #2
0
 private function drawFilledTriangleHorizontally(awGradient $gradient, awPolygon $polygon)
 {
     list($xMin, $xMax) = $polygon->getBoxXRange();
     $this->init($gradient, $xMax - $xMin);
     // Get the triangle line we will draw our lines from
     $fromLine = NULL;
     $lines = $polygon->getLines();
     $count = count($lines);
     // Pick the side of the triangle going all the way
     // from the left side to the right side of the surrounding box
     for ($i = 0; $i < $count; $i++) {
         if ($lines[$i]->isLeftToRight($polygon)) {
             list($fromLine) = array_splice($lines, $i, 1);
             break;
         }
     }
     // If for some reason the three points are aligned,
     // $fromLine will still be NULL
     if ($fromLine === NULL) {
         return;
     }
     $fillLine = NULL;
     for ($x = round($xMin); $x < round($xMax); $x++) {
         $fromY = floor($fromLine->getYFrom($x));
         $toY = array();
         foreach ($lines as $line) {
             $yValue = $line->getYFrom($x);
             if (!is_null($yValue)) {
                 $toY[] = floor($yValue);
             }
         }
         if (count($toY) === 1) {
             $fillLine = new Line(new Point($x, $fromY), new Point($x, $toY[0]));
         } else {
             $line1 = new Line(new Point($x, $fromY), new Point($x, $toY[0]));
             $line2 = new Line(new Point($x, $fromY), new Point($x, $toY[1]));
             if ($line1->getSize() < $line2->getSize()) {
                 $fillLine = $line1;
             } else {
                 $fillLine = $line2;
             }
         }
         $color = $this->color($x - $xMin);
         if ($fillLine->isPoint()) {
             $this->driver->point($color, $fillLine->p1);
         } elseif ($fillLine->getSize() >= 1) {
             $this->driver->line($color, $fillLine);
         }
         unset($color);
     }
 }
Пример #3
0
 /**
  * Returns TRUE if the line is going all the way from the left side
  * to the right side of the polygon surrounding box.
  * 
  * @param $polygon Polygon A Polygon object
  * @return bool
  */
 public function isLeftToRight(awPolygon $polygon)
 {
     list($xMin, $xMax) = $polygon->getBoxXRange();
     list($yMin, $yMax) = $polygon->getBoxYRange();
     if ($this->isVertical()) {
         return FALSE;
     } else {
         if ($this->p1->x < $this->p2->x) {
             $left = $this->p1;
             $right = $this->p2;
         } else {
             $left = $this->p2;
             $right = $this->p1;
         }
     }
     return $this->isOnBoxLeftSide($left, $yMin, $yMax, $xMin) and $this->isOnBoxRightSide($right, $yMin, $yMax, $xMax);
 }