/** * 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); } }
private function drawFilledTriangleVertically(awGradient $gradient, awPolygon $polygon) { list($yMin, $yMax) = $polygon->getBoxYRange(); $this->init($gradient, $yMax - $yMin); // 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 from the top // to the bottom of the surrounding box for ($i = 0; $i < $count; $i++) { if ($lines[$i]->isTopToBottom($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 ($y = round($yMin); $y < round($yMax); $y++) { $fromX = $fromLine->getXFrom($y); $toX = array(); foreach ($lines as $line) { $xValue = $line->getXFrom($y); if (!is_null($xValue)) { $toX[] = $xValue; } } if (count($toX) === 1) { $fillLine = new Line(new Point($fromX, $y), new Point($toX[0], $y)); } else { $line1 = new Line(new Point($fromX, $y), new Point($toX[0], $y)); $line2 = new Line(new Point($fromX, $y), new Point($toX[1], $y)); if ($line1->getSize() < $line2->getSize()) { $fillLine = $line1; } else { $fillLine = $line2; } } if (!$fillLine->isPoint()) { $color = $this->color($y - $yMin); $this->driver->line($color, $fillLine); unset($color); } } }
/** * 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); }