~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/GIFPlot/Php/shadow/runme.php3

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?
 
2
 
 
3
# Plot a 3D function
 
4
include("gifplot.php");
 
5
 
 
6
# Here is the function to plot
 
7
function 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
 
 
35
function 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
 
 
73
print "Making a nice 3D plot...\n";
 
74
drawsolid();
 
75
 
 
76
$frame->writeGIF($cmap,"image.gif");
 
77
print "Wrote image.gif\n";
 
78
 
 
79
?>