PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/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. ;; Use the wrapped GIFPlot library
  3. (use-modules (gifplot))
  4. ;; Here is the function to plot
  5. (define (func x y)
  6. (* 5
  7. (cos (* 2 (sqrt (+ (* x x) (* y y)))))
  8. (exp (* -0.3 (sqrt (+ (* x x) (* y y)))))))
  9. ;; Here are some plotting parameters
  10. (define xmin -5.0)
  11. (define xmax 5.0)
  12. (define ymin -5.0)
  13. (define ymax 5.0)
  14. (define zmin -5.0)
  15. (define zmax 5.0)
  16. ;; Grid resolution
  17. (define nxpoints 60)
  18. (define nypoints 60)
  19. (define cmap (new-ColorMap "cmap"))
  20. (define frame (new-FrameBuffer 500 500))
  21. (FrameBuffer-clear frame (BLACK))
  22. (define p3 (new-Plot3D frame xmin ymin zmin xmax ymax zmax))
  23. (Plot3D-lookat p3 (* 2 (- zmax zmin)))
  24. (Plot3D-autoperspective p3 40)
  25. (Plot3D-rotu p3 60)
  26. (Plot3D-rotr p3 30)
  27. (Plot3D-rotd p3 10)
  28. (define (drawsolid)
  29. (Plot3D-clear p3 (BLACK))
  30. (Plot3D-start p3)
  31. (let ((dx (/ (- xmax xmin) nxpoints))
  32. (dy (/ (- ymax ymin) nypoints))
  33. (cscale (/ 240 (- zmax zmin))))
  34. (let x-loop ((x xmin) (i 0))
  35. (cond
  36. ((< i nxpoints)
  37. (let y-loop ((y ymin) (j 0))
  38. (cond
  39. ((< j nypoints)
  40. (let* ((z1 (func x y))
  41. (z2 (func (+ x dx) y))
  42. (z3 (func (+ x dx) (+ y dy)))
  43. (z4 (func x (+ y dy)))
  44. (c1 (* cscale (- z1 zmin)))
  45. (c2 (* cscale (- z2 zmin)))
  46. (c3 (* cscale (- z3 zmin)))
  47. (c4 (* cscale (- z4 zmin)))
  48. (cc (/ (+ c1 c2 c3 c4) 4))
  49. (c (round (max (min cc 239) 0))))
  50. (Plot3D-solidquad p3 x y z1 (+ x dx) y z2 (+ x dx) (+ y dy)
  51. z3 x (+ y dy) z4 (+ c 16)))
  52. (y-loop (+ y dy) (+ j 1)))))
  53. (x-loop (+ x dx) (+ i 1)))))))
  54. (display "Making a nice 3D plot...\n")
  55. (drawsolid)
  56. (FrameBuffer-writeGIF frame cmap "image.gif")
  57. (display "Wrote image.gif\n")