PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/Root-branch-php-utl/SWIG/Examples/GIFPlot/Java/shadow/main.java

#
Java | 76 lines | 61 code | 11 blank | 4 comment | 4 complexity | ee3e94b98307a155e96e2e194a758881 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // Plot a 3D function
  2. import java.lang.Math;
  3. public class main {
  4. static {
  5. try {
  6. System.loadLibrary("gifplot");
  7. } catch (UnsatisfiedLinkError e) {
  8. System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
  9. System.exit(1);
  10. }
  11. }
  12. public static void main(String argv[]) {
  13. // Here are some plotting parameters
  14. double xmin = -5.0;
  15. double xmax = 5.0;
  16. double ymin = -5.0;
  17. double ymax = 5.0;
  18. double zmin = -5.0;
  19. double zmax = 5.0;
  20. // Grid resolution
  21. int nxpoints = 60;
  22. int nypoints = 60;
  23. ColorMap cmap = new ColorMap("cmap");
  24. FrameBuffer frame = new FrameBuffer(500,500);
  25. frame.clear((short)gifplot.BLACK);
  26. Plot3D p3 = new Plot3D(frame,xmin,ymin,zmin,xmax,ymax,zmax);
  27. p3.lookat(2*(zmax-zmin));
  28. p3.autoperspective(40);
  29. p3.rotu(60);
  30. p3.rotr(30);
  31. p3.rotd(10);
  32. System.out.println( "Making a nice 3D plot..." );
  33. p3.clear((short)gifplot.BLACK);
  34. p3.start();
  35. double dx = 1.0*(xmax-xmin)/nxpoints;
  36. double dy = 1.0*(ymax-ymin)/nypoints;
  37. double cscale = 240.0/(zmax-zmin);
  38. double x = xmin;
  39. for (int i = 0; i < nxpoints; i++) {
  40. double y = ymin;
  41. for (int j = 0; j < nypoints; j++) {
  42. double z1 = func(x,y);
  43. double z2 = func(x+dx,y);
  44. double z3 = func(x+dx,y+dy);
  45. double z4 = func(x,y+dy);
  46. double c1 = cscale*(z1-zmin);
  47. double c2 = cscale*(z2-zmin);
  48. double c3 = cscale*(z3-zmin);
  49. double c4 = cscale*(z4-zmin);
  50. double c = (c1+c2+c3+c4)/4;
  51. if (c < 0) c = 0;
  52. if (c > 239) c = 239;
  53. p3.solidquad(x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,(short)(c+16));
  54. y = y + dy;
  55. }
  56. x = x + dx;
  57. }
  58. frame.writeGIF(cmap,"image.gif");
  59. System.out.println( "Wrote image.gif" );
  60. }
  61. // Here is the function to plot
  62. public static double func(double x, double y) {
  63. return 5*java.lang.Math.cos(2*java.lang.Math.sqrt(x*x+y*y))*java.lang.Math.exp(-0.3*java.lang.Math.sqrt(x*x+y*y));
  64. }
  65. }