Ejemplo n.º 1
0
<?php

$Surface = new CairoImageSurface(0, 256, 256);
$ctx = new CairoContext($Surface);
$ctx->setAntialias(0);
$ctx->setFillRule(0);
$ctx->scale(256 / 1.0, 256 / 1.0);
$pat = new CairoLinearGradient(0.0, 0.0, 0.0, 1.0);
$pat->addColorStopRgba(1, 0, 0, 0, 1);
$pat->addColorStopRgba(0, 1, 1, 1, 1);
$ctx->rectangle(0, 0, 1, 1);
$ctx->setSource($pat);
$ctx->fill();
$pat = new CairoRadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5);
$pat->addColorStopRgba(0, 1, 1, 1, 1);
$pat->addColorStopRgba(1, 0, 0, 0, 1);
$ctx->setSource($pat);
$ctx->arc(0.5, 0.5, 0.3, 0, 2 * 3.14);
$ctx->fill();
$check = $ctx->getTarget();
$check->writeToPng(dirname(__FILE__) . '/sphere.png');
Ejemplo n.º 2
0
<?php

$points = 10.0;
$step = 1.0 / $points;
$pad = 1.0;
$width = $pad + $points * 2 + $pad;
$height = $width;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 1, 1);
$con->paint();
$con->setSourceRgb(0, 0, 0);
$con->translate($pad, $pad);
$con->setAntialias(CairoAntialias::MODE_NONE);
for ($i = 0; $i < $points; $i++) {
    for ($j = 0; $j < $points; $j++) {
        $t1 = 2 * $i * 1.0 + $i * $step * 2.0;
        $t2 = 2 * $j * 1.0 + $j * $step * 1.0;
        $con->rectangle($t1, $t2, 1, 1);
        $con->fill();
    }
}
$sur->writeToPng(dirname(__FILE__) . '/a1-traps-sample-php.png');
?>