PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/GIFPlot/Java/full/main.java

#
Java | 75 lines | 61 code | 10 blank | 4 comment | 4 complexity | 00e6821ed9571ffd45da2cbffbdd1582 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. SWIGTYPE_p_ColorMap cmap = gifplot.new_ColorMap("cmap");
  24. SWIGTYPE_p_FrameBuffer frame = gifplot.new_FrameBuffer(500,500);
  25. gifplot.FrameBuffer_clear(frame,(short)gifplot.BLACK);
  26. SWIGTYPE_p_Plot3D p3 = gifplot.new_Plot3D(frame,xmin,ymin,zmin,xmax,ymax,zmax);
  27. gifplot.Plot3D_lookat(p3,2*(zmax-zmin));
  28. gifplot.Plot3D_autoperspective(p3,40);
  29. gifplot.Plot3D_rotu(p3,60);
  30. gifplot.Plot3D_rotr(p3,30);
  31. gifplot.Plot3D_rotd(p3,10);
  32. System.out.println( "Making a nice 3D plot..." );
  33. gifplot.Plot3D_clear(p3,(short)gifplot.BLACK);
  34. gifplot.Plot3D_start(p3);
  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. gifplot.Plot3D_solidquad(p3,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. gifplot.FrameBuffer_writeGIF(frame,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. }