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