Skripty : Hodiny

Popis

rotací a Circles čerpat Tento skript ukazuje použití skriptu Rotace a Kruhy a elipsy pro vykreslení analogových hodin. clock.

Zdrojový kód


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


class PDF_Clock extends PDF_Rotate
{

function hour_scale($x,$y,$r)

{
    $this->SetLineWidth(0.5);
    $this->SetDrawColor(0,0,139);

    for($i=0;$i<12;$i++) {
        $this->Rotate(30*$i,$x,$y);

        $this->Line($x+$r-.5,$y,$x+$r-5,$y);

    }
    $this->Rotate(0);
}

function min_scale($x,$y,$r)

{
    $this->SetLineWidth(0.3);
    $this->SetDrawColor(0,0,139);

    for($i=0;$i<60;$i++) {
        $this->Rotate(6*$i,$x,$y);

        $this->Line($x+$r-3.6,$y,$x+$r-1.8,$y);

    }
    $this->Rotate(0);
}

function hour_hand($x,$y,$r)

{
    $hour=date('h');
    $min=date('i');
    $angle=90-30*($hour+$min/60);

    $this->Rotate($angle,$x,$y);
    $this->SetDrawColor(65,105,225);

    $this->Line($x,$y,$x+$r,$y);
    $this->Rotate(0);

}

function min_hand($x,$y,$r)
{
    $min=date('i');

    $sec=date('s');
    $angle=90-6*($min+$sec/60);

    $this->Rotate($angle,$x,$y);
    $this->SetDrawColor(0,255,0);

    $this->Line($x,$y,$x+$r,$y);
    $this->Rotate(0);

}

function sec_hand($x,$y,$r)
{
    $sec=date('s');

    $angle=90-6*$sec;
    $this->Rotate($angle,$x,$y);

    $this->SetDrawColor(255,0,0);
    $this->Line($x,$y,$x+$r,$y);

    $this->Rotate(0);
}

function sec_hand2($x,$y,$r)

{
    $sec=date('s');
    $angle=-90-6*$sec;

    $this->Rotate($angle,$x,$y);
    $this->SetDrawColor(255,0,0);

    $this->Line($x,$y,$x+$r,$y);
    $this->Rotate(0);

}

function Clock($x,$y,$r)
{
    $this->SetLineWidth(0.50);

    $this->SetFillColor(255,255,0);
    $this->Circle($x,$y,$r,'DF');

    $this->hour_scale($x,$y,$r);
    $this->min_scale($x,$y,$r);


    $this->SetLineWidth(1.50);
    $this->hour_hand($x,$y,0.6*$r);


    $this->SetLineWidth(1.10);
    $this->min_hand($x,$y,0.85*$r);


    $this->SetLineWidth(0.30);
    $this->sec_hand($x,$y,0.88*$r);

    $this->SetLineWidth(1);
    $this->sec_hand2($x,$y,0.2*$r);

    $this->SetFillColor(255,0,0);
    $this->Circle($x,$y,1.5,'F');

}
}

?>



Příklad


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


$pdf=new PDF_Clock();
$pdf->AddPage();
$pdf->Clock(105,65,50);

$pdf->Output();
?>


Ukázka

fpdf-hodiny.pdf

Download

fpdf-hodiny.zip

Informace

Author: Toshio Onishi
License: FPDF