diff options
Diffstat (limited to 'Examples/GIFPlot/Ocaml')
| -rw-r--r-- | Examples/GIFPlot/Ocaml/check.list | 3 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/full/Makefile | 33 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/full/README | 8 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/full/cmap | bin | 0 -> 768 bytes | |||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/full/gifplot.i | 15 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/full/runme.ml | 87 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/simple/Makefile | 33 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/simple/cmap | bin | 0 -> 768 bytes | |||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/simple/runme.ml | 35 | ||||
| -rw-r--r-- | Examples/GIFPlot/Ocaml/simple/simple.i | 33 |
10 files changed, 247 insertions, 0 deletions
diff --git a/Examples/GIFPlot/Ocaml/check.list b/Examples/GIFPlot/Ocaml/check.list new file mode 100644 index 0000000..e75ee58 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/check.list @@ -0,0 +1,3 @@ +# see top-level Makefile.in +full +simple diff --git a/Examples/GIFPlot/Ocaml/full/Makefile b/Examples/GIFPlot/Ocaml/full/Makefile new file mode 100644 index 0000000..4f35c43 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/full/Makefile @@ -0,0 +1,33 @@ +TOP = ../../.. +SWIG = $(TOP)/../swig +SWIGOPT = -I../../Include +SRCS = +TARGET = gifcaml +INTERFACE = gifplot.i +LIBS = -L../.. -lgifplot -lm +INCLUDES = -I../../Include +MLFILE = gifplot.ml +IOBJS = runme.cmo +PROGFILE = runme.ml + +all:: static + +static:: + $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ + IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ + SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ + INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static + +dynamic:: + $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ + IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ + SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ + INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_dynamic + +clean:: + $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + rm -f *.gif + +check: all diff --git a/Examples/GIFPlot/Ocaml/full/README b/Examples/GIFPlot/Ocaml/full/README new file mode 100644 index 0000000..4a2b400 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/full/README @@ -0,0 +1,8 @@ +This example runs the entire gifplot.h header file through SWIG without +any changes. The ocaml program 'runme.ml' does something a little more +interesting. You'll have to go look at the header file to get a complete +listing of the functions. + + + + diff --git a/Examples/GIFPlot/Ocaml/full/cmap b/Examples/GIFPlot/Ocaml/full/cmap Binary files differnew file mode 100644 index 0000000..a20c331 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/full/cmap diff --git a/Examples/GIFPlot/Ocaml/full/gifplot.i b/Examples/GIFPlot/Ocaml/full/gifplot.i new file mode 100644 index 0000000..22f4df6 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/full/gifplot.i @@ -0,0 +1,15 @@ +/* Oh what the heck, let's just grab the whole darn header file + and see what happens. */ + +%module gifplot +%{ + +/* Note: You still need this part because the %include directive + merely causes SWIG to interpret the contents of a file. It doesn't + include the right include headers for the resulting C code */ + +#include "gifplot.h" +%} + +typedef int Pixel; +%include gifplot.h diff --git a/Examples/GIFPlot/Ocaml/full/runme.ml b/Examples/GIFPlot/Ocaml/full/runme.ml new file mode 100644 index 0000000..0dfa985 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/full/runme.ml @@ -0,0 +1,87 @@ +(* Plot a 3D Function *) + +(* Use the wrapped GIFPlot library *) +open Swig +open Gifplot +open Int32 + +(* Here is the function to plot *) +let func x y = + 5.0 *. + (cos (2.0 *. (sqrt (x *. x) +. (y *. y)))) *. + (exp (-0.3 *. (sqrt (x *. x) +. (y *. y)))) + +(* Here are some plotting parameters *) + +let xmin = -5.0 +let xmax = 5.0 +let ymin = -5.0 +let ymax = 5.0 +let zmin = -5.0 +let zmax = 5.0 + +(* Grid resolution *) +let nxpoints = 60 +let nypoints = 60 + +let cmap = _new_ColorMap (C_string "cmap") +let frame = _new_FrameBuffer (C_list [ C_int 500 ; + C_int 500 ]) +let _ = _FrameBuffer_clear (C_list [ frame ; _BLACK C_void ]) + +let p2 = _new_Plot3D (C_list [ frame ; + C_float xmin ; C_float ymin ; C_float zmin ; + C_float xmax ; C_float ymax ; C_float zmax ]) +let _ = _Plot3D_lookat (C_list [ p2 ; C_float (2.0 *. (zmax -. zmin)) ]) +let _ = _Plot3D_autoperspective (C_list [ p2 ; C_float 40.0 ]) +let _ = _Plot3D_rotu (C_list [ p2 ; C_float 60.0 ]) +let _ = _Plot3D_rotr (C_list [ p2 ; C_float 30.0 ]) +let _ = _Plot3D_rotd (C_list [ p2 ; C_float 10.0 ]) + +let drawsolid () = + begin + _Plot3D_clear (C_list [ p2 ; _BLACK C_void ]) ; + _Plot3D_start p2 ; + let dx = ((xmax -. xmin) /. (float_of_int nxpoints)) + and dy = ((ymax -. ymin) /. (float_of_int nypoints)) + and cscale = (240.0 /. (zmax -. zmin)) in + let rec x_loop x i = + if i < nxpoints then + begin + let rec y_loop y j = + begin + if j < nypoints then + let z1 = func x y + and z2 = func (x +. dx) y + and z3 = func (x +. dx) (y +. dy) + and z4 = func x (y +. dy) in + let c1 = cscale *. (z1 -. zmin) + and c2 = cscale *. (z2 -. zmin) + and c3 = cscale *. (z3 -. zmin) + and c4 = cscale *. (z4 -. zmin) in + let cc = (c1 +. c2 +. c3 +. c4) /. 4.0 in + let c = (max (min (int_of_float cc) 239) 0) in + _Plot3D_solidquad + (C_list (p2 :: + (List.map + (fun x -> C_float x) + [ x ; y ; z1 ; + (x +. dx) ; y ; z2 ; + (x +. dx) ; (y +. dy) ; z3 ; + x ; (y +. dx) ; z4 ; + (float_of_int (c + 16)) ]))) ; + y_loop (y +. dy) (j + 1) + end in + begin + y_loop ymin 0 ; + x_loop (x +. dx) (i + 1) + end + end in + x_loop xmin 0 + end + +let _ = print_endline "Making a nice 3D plot..." +let _ = drawsolid () + +let _ = _FrameBuffer_writeGIF (C_list [ frame ; cmap ; C_string "image.gif" ]) +let _ = print_endline "Write image.gif" diff --git a/Examples/GIFPlot/Ocaml/simple/Makefile b/Examples/GIFPlot/Ocaml/simple/Makefile new file mode 100644 index 0000000..50492ef --- /dev/null +++ b/Examples/GIFPlot/Ocaml/simple/Makefile @@ -0,0 +1,33 @@ +TOP = ../../.. +SWIG = $(TOP)/../swig +SWIGOPT = -I../../Include +SRCS = +TARGET = gifsimple +INTERFACE = simple.i +LIBS = -L../.. -lgifplot -lm +INCLUDES = -I../../Include +MLFILE = simple.ml +IOBJS = simple_wrap.o simple.cmo runme.cmo +PROGFILE = runme.ml + +all:: static + +static:: + $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ + IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ + SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ + INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static + +dynamic:: + $(MAKE) -f $(TOP)/Makefile TOP='$(TOP)' \ + IOBJS='$(IOBJS)' PROGFILE='$(PROGFILE)' \ + SRCS='$(SRCS)' SWIG='$(SWIG)' MLFILE='$(MLFILE)' \ + INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' ocaml_static + +clean:: + $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + rm -f *.gif + +check: all diff --git a/Examples/GIFPlot/Ocaml/simple/cmap b/Examples/GIFPlot/Ocaml/simple/cmap Binary files differnew file mode 100644 index 0000000..a20c331 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/simple/cmap diff --git a/Examples/GIFPlot/Ocaml/simple/runme.ml b/Examples/GIFPlot/Ocaml/simple/runme.ml new file mode 100644 index 0000000..3b6602c --- /dev/null +++ b/Examples/GIFPlot/Ocaml/simple/runme.ml @@ -0,0 +1,35 @@ +(* Draw some simple shapes *) + +(* Use the wrapped GIFPlot library *) +open Swig +open Simple +open Int32 + +let _ = print_endline "Drawing some basic shapes" + +let cmap = _new_ColorMap (C_string "cmap") +let f = _new_FrameBuffer (C_list [ C_int 400 ; C_int 400 ]) + +(* Clear the picture *) +let _ = _FrameBuffer_clear (C_list [ f ; _BLACK C_void ]) + +(* Make a red box *) +let _ = _FrameBuffer_box + (C_list [ f ; C_int 40 ; C_int 40 ; C_int 200 ; C_int 200 ; _RED C_void ]) + +(* Make a blue circle *) +let _ = _FrameBuffer_circle + (C_list [ f ; C_int 200 ; C_int 200 ; C_int 40 ; _BLUE C_void ]) + +(* Make green line *) +let _ = _FrameBuffer_line + (C_list [ f ; C_int 10 ; C_int 390 ; C_int 390 ; C_int 200 ; _GREEN C_void ]) + +(* Write an image out to disk *) + +let _ = _FrameBuffer_writeGIF (C_list [ f ; cmap ; C_string "image.gif" ]) +let _ = print_endline "Wrote image.gif" + +let _ = _delete_FrameBuffer f +let _ = _delete_ColorMap cmap + diff --git a/Examples/GIFPlot/Ocaml/simple/simple.i b/Examples/GIFPlot/Ocaml/simple/simple.i new file mode 100644 index 0000000..33297f4 --- /dev/null +++ b/Examples/GIFPlot/Ocaml/simple/simple.i @@ -0,0 +1,33 @@ +/* This example shows a very simple interface wrapping a few + primitive declarations */ + +%module simple +%{ +#include "gifplot.h" +%} + +typedef int Pixel; + +/* Here are a few useful functions */ + +ColorMap *new_ColorMap(char *filename = 0); +void delete_ColorMap(ColorMap *cmap); + +FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height); +void delete_FrameBuffer(FrameBuffer *frame); +void FrameBuffer_clear(FrameBuffer *frame, Pixel color); +void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); +void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color); +void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color); +int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename); + +/* And some useful constants */ + +#define BLACK 0 +#define WHITE 1 +#define RED 2 +#define GREEN 3 +#define BLUE 4 +#define YELLOW 5 +#define CYAN 6 +#define MAGENTA 7 |
