PageRenderTime 47ms CodeModel.GetById 16ms 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
  2. use gifplot;
  3. package gifplot;
  4. # Here is the function to plot
  5. sub func {
  6. my $x = shift;
  7. my $y = shift;
  8. return 5*cos(2*sqrt($x*$x+$y*$y))*exp(-0.3*sqrt($x*$x+$y*$y));
  9. }
  10. # Here are some plotting parameters
  11. $xmin = -5.0;
  12. $xmax = 5.0;
  13. $ymin = -5.0;
  14. $ymax = 5.0;
  15. $zmin = -5.0;
  16. $zmax = 5.0;
  17. # Grid resolution
  18. $nxpoints = 60;
  19. $nypoints = 60;
  20. $cmap = new gifplot::ColorMap("cmap");
  21. $frame = new gifplot::FrameBuffer(500,500);
  22. $frame->clear($BLACK);
  23. $p3 = new gifplot::Plot3D($frame,$xmin,$ymin,$zmin,$xmax,$ymax,$zmax);
  24. $p3->lookat(2*($zmax-$zmin));
  25. $p3->autoperspective(40);
  26. $p3->rotu(60);
  27. $p3->rotr(30);
  28. $p3->rotd(10);
  29. sub drawsolid {
  30. $p3->clear($BLACK);
  31. $p3->start();
  32. my $dx = 1.0*($xmax-$xmin)/$nxpoints;
  33. my $dy = 1.0*($ymax-$ymin)/$nypoints;
  34. my $cscale = 240.0/($zmax-$zmin);
  35. my $x = $xmin;
  36. for ($i = 0; $i < $nxpoints; $i++) {
  37. my $y = $ymin;
  38. for ($j = 0; $j < $nypoints; $j++) {
  39. my $z1 = func($x,$y);
  40. my $z2 = func($x+$dx,$y);
  41. my $z3 = func($x+$dx,$y+$dy);
  42. my $z4 = func($x,$y+$dy);
  43. my $c1 = $cscale*($z1-$zmin);
  44. my $c2 = $cscale*($z2-$zmin);
  45. my $c3 = $cscale*($z3-$zmin);
  46. my $c4 = $cscale*($z4-$zmin);
  47. my $c = ($c1+$c2+$c3+$c4)/4;
  48. if ($c < 0) { $c = 0; }
  49. if ($c > 239) { $c = 239; }
  50. $p3->solidquad($x,$y,$z1,$x+$dx,$y,$z2,$x+$dx,$y+$dy,$z3,$x,$y+$dy,$z4,$c+16);
  51. $y = $y + $dy;
  52. }
  53. $x = $x + $dx;
  54. }
  55. }
  56. print "Making a nice 3D plot...\n";
  57. drawsolid();
  58. $frame->writeGIF($cmap,"image.gif");
  59. print "Wrote image.gif\n";