Example #1
0
<?php

$starsize = 20;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $starsize * 2 + 2, $starsize + 2);
$con = new CairoContext($sur);
$con->setSourceRgb(1, 0, 0);
$con->translate(1, 1);
$con->save();
$con->moveTo(10, 0);
$con->relLineTo(6, 20);
$con->relLineTo(-16, -12);
$con->relLineTo(20, 0);
$con->relLineTo(-16, 12);
$con->setFillRule(CairoFillRule::WINDING);
$con->clip();
$con->paint();
$con->restore();
$con->translate($starsize + 1, 0);
$con->save();
$con->moveTo(10, 0);
$con->relLineTo(6, 20);
$con->relLineTo(-16, -12);
$con->relLineTo(20, 0);
$con->relLineTo(-16, 12);
$con->setFillRule(CairoFillRule::EVEN_ODD);
$con->clip();
$con->paint();
$con->restore();
$sur->writeToPng(dirname(__FILE__) . "/clip-fill-rule-php.png");
?>
Example #2
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');
Example #3
0
    $poly = 0x9a795537;
    $n = 32;
    $state = 2 * $state < $state ? 2 * $state ^ $poly : 2 * $state;
    return floor($minval + $state * ($maxval - $minval) / 4294967296.0);
}
$size = 512;
$numseg = 128;
$width = $size + 3;
$height = $size + 3;
$sur = new CairoImageSurface(CairoFormat::ARGB32, $size + 3, $size + 3);
$con = new CairoContext($sur);
$con->setSourceRgb(0, 0, 0);
$con->paint();
$state = 0x123456;
$con->translate(1, 1);
$con->setFillRule(CairoFillRule::EVEN_ODD);
$con->moveTo(0, 0);
for ($i = 0; $i < $numseg; $i++) {
    $x = uniform_random(0, $width);
    $y = uniform_random(0, $height);
    $con->lineTo($x, $y);
    //echo "x = $x";
    //echo "y = $y";
}
$con->closePath();
$con->setSourceRgb(1, 0, 0);
$con->fillPreserve();
$con->setSourceRgb(0, 1, 0);
$con->setLineWidth(0.5);
$con->stroke();
$sur->writeToPng(dirname(__FILE__) . "/random-intersection-php.png");