PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-24/SWIG/Examples/GIFPlot/Perl5/shadow/runme.pl

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