/tags/rel-1-3-24/SWIG/Examples/GIFPlot/Guile/full/runme.scm
Lisp | 66 lines | 52 code | 9 blank | 5 comment | 0 complexity | 54794362897026a06a183760910b9563 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1;;; Plot a 3D function 2 3;; Use the wrapped GIFPlot library 4(use-modules (gifplot)) 5 6;; Here is the function to plot 7(define (func x y) 8 (* 5 9 (cos (* 2 (sqrt (+ (* x x) (* y y))))) 10 (exp (* -0.3 (sqrt (+ (* x x) (* y y))))))) 11 12;; Here are some plotting parameters 13(define xmin -5.0) 14(define xmax 5.0) 15(define ymin -5.0) 16(define ymax 5.0) 17(define zmin -5.0) 18(define zmax 5.0) 19 20;; Grid resolution 21(define nxpoints 60) 22(define nypoints 60) 23 24(define cmap (new-ColorMap "cmap")) 25(define frame (new-FrameBuffer 500 500)) 26(FrameBuffer-clear frame (BLACK)) 27 28(define p3 (new-Plot3D frame xmin ymin zmin xmax ymax zmax)) 29(Plot3D-lookat p3 (* 2 (- zmax zmin))) 30(Plot3D-autoperspective p3 40) 31(Plot3D-rotu p3 60) 32(Plot3D-rotr p3 30) 33(Plot3D-rotd p3 10) 34 35(define (drawsolid) 36 (Plot3D-clear p3 (BLACK)) 37 (Plot3D-start p3) 38 (let ((dx (/ (- xmax xmin) nxpoints)) 39 (dy (/ (- ymax ymin) nypoints)) 40 (cscale (/ 240 (- zmax zmin)))) 41 (let x-loop ((x xmin) (i 0)) 42 (cond 43 ((< i nxpoints) 44 (let y-loop ((y ymin) (j 0)) 45 (cond 46 ((< j nypoints) 47 (let* ((z1 (func x y)) 48 (z2 (func (+ x dx) y)) 49 (z3 (func (+ x dx) (+ y dy))) 50 (z4 (func x (+ y dy))) 51 (c1 (* cscale (- z1 zmin))) 52 (c2 (* cscale (- z2 zmin))) 53 (c3 (* cscale (- z3 zmin))) 54 (c4 (* cscale (- z4 zmin))) 55 (cc (/ (+ c1 c2 c3 c4) 4)) 56 (c (round (max (min cc 239) 0)))) 57 (Plot3D-solidquad p3 x y z1 (+ x dx) y z2 (+ x dx) (+ y dy) 58 z3 x (+ y dy) z4 (+ c 16))) 59 (y-loop (+ y dy) (+ j 1))))) 60 (x-loop (+ x dx) (+ i 1))))))) 61 62(display "Making a nice 3D plot...\n") 63(drawsolid) 64 65(FrameBuffer-writeGIF frame cmap "image.gif") 66(display "Wrote image.gif\n")