Added some test cases ....
[phpCairo.git] / testcases / phpCairo / random-intersections.php
blob6f5e7e3e5a1b27a015a36d901e0fe22a05affb36
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->set_source_rgb(0,0,0);
19 $con->paint();
21 $state = 0x123456;
23 $con->translate(1,1);
24 $con->set_fill_rule(FILL_RULE_EVEN_ODD);
25 $con->move_to(0,0);
27 for($i=0; $i<$numseg;$i++) {
28 $x = uniform_random(0,$width);
29 $y = uniform_random(0,$height);
30 $con->line_to($x,$y);
31 //echo "x = $x";
32 //echo "y = $y";
35 $con->close_path();
36 $con->set_source_rgb(1,0,0);
37 $con->fill_preserve();
38 $con->set_source_rgb(0,1,0);
39 $con->set_line_width(0.5);
40 $con->stroke();
42 $sur->write_to_png("random-intersection-php.png");