PageRenderTime 29ms CodeModel.GetById 24ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-24/SWIG/Examples/GIFPlot/Php4/shadow/runme.php4

#
PHP | 79 lines | 63 code | 12 blank | 4 comment | 4 complexity | 56fcbe29e40db615ba0896d213e735d8 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1<?
 2
 3# Plot a 3D function
 4include("gifplot.php");
 5
 6# Here is the function to plot
 7function func($x, $y) {
 8    return 5*cos(2*sqrt($x*$x+$y*$y))*exp(-0.3*sqrt($x*$x+$y*$y));
 9}
10
11# Here are some plotting parameters
12$xmin = -5.0;
13$xmax =  5.0;
14$ymin = -5.0;
15$ymax =  5.0;
16$zmin = -5.0;
17$zmax =  5.0;
18
19# Grid resolution
20$nxpoints =  60;
21$nypoints =  60;
22
23$cmap  = new ColorMap("cmap");
24$frame = new FrameBuffer(500,500);
25$frame->clear(BLACK);
26
27
28$p3    = new Plot3D($frame,$xmin,$ymin,$zmin,$xmax,$ymax,$zmax);
29$p3->lookat(2*($zmax-$zmin));
30$p3->autoperspective(40);
31$p3->rotu(60);
32$p3->rotr(30);
33$p3->rotd(10);
34
35function drawsolid() {
36	global $xmax;
37	global $xmin;
38	global $ymax;
39	global $ymin;
40	global $zmin;
41	global $zmax;
42	global $nxpoints;
43	global $nypoints;
44	global $p3;
45
46    $p3->clear(BLACK);
47    $p3->start();
48    $dx = 1.0*($xmax-$xmin)/$nxpoints;
49    $dy = 1.0*($ymax-$ymin)/$nypoints;
50    $cscale = 240.0/($zmax-$zmin);
51    $x = $xmin;
52    for ($i = 0; $i < $nxpoints; $i++) {
53	$y = $ymin;
54	for ($j = 0; $j < $nypoints; $j++) {
55	    $z1 = func($x,$y);
56	    $z2 = func($x+$dx,$y);
57	    $z3 = func($x+$dx,$y+$dy);
58	    $z4 = func($x,$y+$dy);
59	    $c1 = $cscale*($z1-$zmin);
60	    $c2 = $cscale*($z2-$zmin);
61	    $c3 = $cscale*($z3-$zmin);
62	    $c4 = $cscale*($z4-$zmin);
63	    $c = ($c1+$c2+$c3+$c4)/4;
64	    if ($c < 0) { $c = 0; }
65	    if ($c > 239) { $c = 239; }
66	    $p3->solidquad($x,$y,$z1,$x+$dx,$y,$z2,$x+$dx,$y+$dy,$z3,$x,$y+$dy,$z4,$c+16);
67	    $y = $y + $dy;
68	}
69	$x = $x + $dx;
70    }
71}
72
73print "Making a nice 3D plot...\n";
74drawsolid();
75
76$frame->writeGIF($cmap,"image.gif");
77print "Wrote image.gif\n";
78
79?>