summaryrefslogtreecommitdiff
path: root/Examples/GIFPlot/Common-Lisp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2009-08-18 20:56:02 +0000
committerLorry <lorry@roadtrain.codethink.co.uk>2012-09-25 16:59:08 +0000
commit9f8a09ed743cedd9547bf0661d518647966ab114 (patch)
tree9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/GIFPlot/Common-Lisp
downloadswig-tarball-master.tar.gz
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/GIFPlot/Common-Lisp')
-rw-r--r--Examples/GIFPlot/Common-Lisp/full/cmapbin0 -> 768 bytes
-rw-r--r--Examples/GIFPlot/Common-Lisp/full/gifplot.i21
-rw-r--r--Examples/GIFPlot/Common-Lisp/full/runme.lisp59
3 files changed, 80 insertions, 0 deletions
diff --git a/Examples/GIFPlot/Common-Lisp/full/cmap b/Examples/GIFPlot/Common-Lisp/full/cmap
new file mode 100644
index 0000000..a20c331
--- /dev/null
+++ b/Examples/GIFPlot/Common-Lisp/full/cmap
Binary files differ
diff --git a/Examples/GIFPlot/Common-Lisp/full/gifplot.i b/Examples/GIFPlot/Common-Lisp/full/gifplot.i
new file mode 100644
index 0000000..e5c15aa
--- /dev/null
+++ b/Examples/GIFPlot/Common-Lisp/full/gifplot.i
@@ -0,0 +1,21 @@
+/* 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"
+
+%}
+
+/* Pixel is typedef'd to unsigned char, and SWIG will translate this
+ type into Scheme characters. We would like to translate Pixels to
+ Scheme integers instead, so: */
+
+SIMPLE_MAP(Pixel, gh_scm2int, gh_int2scm, integer);
+
+%include gifplot.h
diff --git a/Examples/GIFPlot/Common-Lisp/full/runme.lisp b/Examples/GIFPlot/Common-Lisp/full/runme.lisp
new file mode 100644
index 0000000..48f8042
--- /dev/null
+++ b/Examples/GIFPlot/Common-Lisp/full/runme.lisp
@@ -0,0 +1,59 @@
+;;; Plot a 3D function
+
+;; Here is the function to plot
+(defun func (x y)
+ (* 5
+ (cos (* 2 (sqrt (+ (* x x) (* y y)))))
+ (exp (* -0.3 (sqrt (+ (* x x) (* y y)))))))
+
+;; Here are some plotting parameters
+(defvar xmin -5D0)
+(defvar xmax 5D0)
+(defvar ymin -5D0)
+(defvar ymax 5D0)
+(defvar zmin -5D0)
+(defvar zmax 5D0)
+
+;; Grid resolution
+(defvar nxpoints 60)
+(defvar nypoints 60)
+
+(defun drawsolid (p3)
+ (Plot3D-clear p3 0)
+ (Plot3D-start p3)
+ (let ((dx (/ (- xmax xmin) nxpoints))
+ (dy (/ (- ymax ymin) nypoints))
+ (cscale (/ 240 (- zmax zmin))))
+ (loop for x from xmin by dx
+ repeat nxpoints
+ do (loop for y from ymin by dy
+ repeat nypoints
+ do (let* ((z1 (func x y))
+ (z2 (func (+ x dx) y))
+ (z3 (func (+ x dx) (+ y dy)))
+ (z4 (func x (+ y dy)))
+ (c1 (* cscale (- z1 zmin)))
+ (c2 (* cscale (- z2 zmin)))
+ (c3 (* cscale (- z3 zmin)))
+ (c4 (* cscale (- z4 zmin)))
+ (cc (/ (+ c1 c2 c3 c4) 4))
+ (c (round (max (min cc 239) 0))))
+ (Plot3D-solidquad p3 x y z1 (+ x dx) y z2 (+ x dx) (+ y dy)
+ z3 x (+ y dy) z4 (+ c 16)))))))
+
+(defun action (cmap-filename)
+ (let ((cmap (new-ColorMap cmap-filename))
+ (frame (new-FrameBuffer 500 500)))
+ (format t "Making a nice 3D plot...~%")
+ (FrameBuffer-clear frame 0)
+ (let ((p3 (new-Plot3D frame xmin ymin zmin xmax ymax zmax)))
+ (Plot3D-lookat p3 (* 2 (- zmax zmin)))
+ (Plot3D-autoperspective p3 40D0)
+ (Plot3D-rotu p3 60D0)
+ (Plot3D-rotr p3 30D0)
+ (Plot3D-rotd p3 10D0)
+ (drawsolid p3))
+ (FrameBuffer-writeGIF frame cmap "/tmp/image.gif")
+ (format t "Wrote image.gif~%")))
+
+