Changed the entire file structure to remove the .c includes from cairo.c
[phpCairo.git] / testcases / phpCairo / random-intersections.php
blob2d41ca14f3fdacd14241dc4d1442711baa74404d
1 <?
2 function uniform_random($minval, $maxval)
4 global $state;
5 $poly = 0x9a795537;
6 $n=32;
7 $state = 2*$state < $state ? (2*$state ^ $poly) : 2*$state;
8 return floor($minval + $state * ($maxval - $minval) / 4294967296.0);
11 $size = 512;
12 $numseg = 128;
13 $width = $size+3;
14 $height = $size + 3;
15 $sur = new CairoImageSurface(FORMAT_ARGB32, $size+3, $size + 3);
16 $con = new CairoContext($sur);
18 $con->setSourceRgb(0,0,0);
19 $con->paint();
21 $state = 0x123456;
23 $con->translate(1,1);
24 $con->setFillRule(FILL_RULE_EVEN_ODD);
25 $con->moveTo(0,0);
27 for($i=0; $i<$numseg;$i++) {
28 $x = uniform_random(0,$width);
29 $y = uniform_random(0,$height);
30 $con->lineTo($x,$y);
31 //echo "x = $x";
32 //echo "y = $y";
35 $con->closePath();
36 $con->setSourceRgb(1,0,0);
37 $con->fillPreserve();
38 $con->setSourceRgb(0,1,0);
39 $con->setLineWidth(0.5);
40 $con->stroke();
42 $sur->writeToPng("random-intersection-php.png");