Pop\Image\Svg::drawPolygon PHP Метод

drawPolygon() публичный Метод

Method to add a polygon to the image.
public drawPolygon ( array $points ) : Svg
$points array
Результат Svg
    public function drawPolygon($points)
    {
        $formattedPoints = array();
        foreach ($points as $point) {
            $formattedPoints[] = $point['x'] . ',' . $point['y'];
        }
        $poly = $this->resource->addChild('polygon');
        $poly->addAttribute('points', implode(' ', $formattedPoints));
        $poly = $this->setStyles($poly);
        return $this;
    }

Usage Example

Пример #1
0
 public function testAddPolygon()
 {
     $s = new Svg('graph.svg', '640px', '480px');
     $points = array(array('x' => 320, 'y' => 50), array('x' => 400, 'y' => 100), array('x' => 420, 'y' => 200), array('x' => 280, 'y' => 320), array('x' => 200, 'y' => 180));
     $s->setStrokeColor(new Rgb(0, 0, 0))->drawPolygon($points);
     $s->setBackgroundColor(new Rgb(255, 0, 0));
     $s->drawPolygon($points);
     $s->setFillColor(new Rgb(255, 0, 0));
     $s->drawPolygon($points);
     $this->assertEquals(640, $s->getWidth());
 }