Star

Informations

Author: Luciano Salvino
License: FPDF

Description

This script draws a star.

Star(float X, float Y, float rin, float rout, int points [, string style])

X: abscissa of center.
Y: ordinate of center.
rin: internal radius.
rout: external radius.
points: number of points that the star is composed of.
style: style of rendering, the same as for Rect(): D, F or FD.

Note: if rin=rout, the star will appear as a circle.

Source

<?php
require('fpdf.php');

class PDF_Star extends FPDF
{

function Star($x, $y, $rin, $rout, $points, $style='D')
{
    if($style=='F')
        $op = 'f';
    elseif($style=='FD' || $style=='DF')
        $op = 'B';
    else
        $op = 'S';
    $dth = M_PI/$points;
    $th = 0;
    $k = $this->k;
    $h = $this->h;
    $points_string = '';
    for($i=0;$i<($points*2)+1;$i++)
    {
        $th += $dth;
        $cx = $x + (($i%2==0 ? $rin : $rout) * cos($th));
        $cy = $y + (($i%2==0 ? $rin : $rout) * sin($th));
        $points_string .= sprintf('%.2F %.2F', $cx*$k, ($h-$cy)*$k);
        if($i==0)
            $points_string .= ' m ';
        else
            $points_string .= ' l ';
    }
    $this->_out($points_string . $op);
}

}
?>

Example

<?php
require('star.php');

$pdf = new PDF_Star();
$pdf->AddPage();
$pdf->SetDrawColor(0,0,0);
$pdf->SetFillColor(255,0,0);
$pdf->SetLineWidth(0.5);
$pdf->Star(100,60,40,30,36,'DF');
$pdf->Output();
?>
View the result here.

Download

ZIP | TGZ