summaryrefslogtreecommitdiff
path: root/Examples/GIFPlot/Ocaml/simple
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/GIFPlot/Ocaml/simple')
-rw-r--r--Examples/GIFPlot/Ocaml/simple/Makefile33
-rw-r--r--Examples/GIFPlot/Ocaml/simple/cmapbin0 -> 768 bytes
-rw-r--r--Examples/GIFPlot/Ocaml/simple/runme.ml35
-rw-r--r--Examples/GIFPlot/Ocaml/simple/simple.i33
4 files changed, 101 insertions, 0 deletions
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
new file mode 100644
index 0000000..a20c331
--- /dev/null
+++ b/Examples/GIFPlot/Ocaml/simple/cmap
Binary files differ
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