fpdf
PHP powered
home was ist fpdf? downloads & add-ons dokumentation faq forum impressum links kontakt
 

Downloads > Add-On

 
         
 

Star

Informations

Author: Luciano Salvino
License: Freeware

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 simple 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' or $style=='DF')
        $op='B';
    else
        $op
='S';
    $cx = array($points*2);
    $cy = array($points*2);
    $dth = (pi()/$points);
    $th = 0;
    $k=$this->k;
    $h=$this->h;
    $points_string = '';
    for($i=0;$i<($points*2)+1;$i++)
    {
        $th = $th+$dth;
        $cx[$i] = $x + ((($i%2==0)?$rin:$rout) * cos($th));
        $cy[$i] = $y + ((($i%2==0)?$rin:$rout) * sin($th));
        $points_string .= sprintf('%.2f %.2f', $cx[$i]*$k, ($h-$cy[$i])*$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, 50, 40, 30, 36, 'DF');
$pdf->Output();
?>

View the result here.

Download

ZIP | TGZ
 






 
         
         
 
 
fpdf.de © Copyright 2004-2006 carrib internet solutions - Beachten Sie bitte die Nutzungsbedingungen
Eine Verwendung der auf fpdf.de befindlichen Inhalte (Texte, Grafiken) ist nur mit Zustimmung des Betreibers zulässig.