3 ;;; Time-stamp: <2009-09-21 19:32:22 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: plotting-data.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
9 ;;; Purpose: Example of generating plots.
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;;; This organization and structure is new to the 21st Century
16 ;;; version.. Think, "21st Century Schizoid Man".
18 ;; SETUP FOR PLOT EXAMPLE:
21 (defpackage :cl-2d-user-x11
22 (:use
:cl
:cl-cairo2
:cl-2d
:cl-numlib
:cl-colors
:bind
:cls
)
23 (:shadowing-import-from
:lisp-stat call-method call-next-method
25 expt
+ -
* / ** mod rem abs
1+ 1- log exp sqrt sin cos tan
26 asin acos atan sinh cosh tanh asinh acosh atanh float random
27 truncate floor ceiling round minusp zerop plusp evenp oddp
28 < <= = /= >= > > ;; complex
29 conjugate realpart imagpart phase
30 min max logand logior logxor lognot ffloor fceiling
31 ftruncate fround signum cis
35 (in-package :cl-2d-user-x11
)
42 ;; this is how you create an X11 frame. If you supply a
43 ;; background-color to as-frame, each plot will clear the frame with
46 (defparameter *frame1
* (as-frame (create-xlib-image-context 300 300)
47 :background-color
+white
+))
49 ;; or netbook size, picture is similar but on a lower-res display window.
50 (defparameter *frame2
* (as-frame (create-xlib-image-context 200 200)
51 :background-color
+white
+))
53 (plot-function *frame1
*
54 #'exp
(interval-of 0 2)
58 ;; split the frame, and you can draw on the subframes independently.
61 (bind ((#2A
((f1 f2
) (f3 f4
))
62 (split-frame *frame2
* (percent 50) (percent 50))))
63 (defparameter *f1
* f1
)
64 (defparameter *f2
* f2
)
65 (defparameter *f3
* f3
)
66 (defparameter *f4
* f4
))
69 (bind ((#2A
((f1 f2
) (f3 f4
))
70 (split-frame *frame2
* (percent 75) (percent 25))))
71 (defparameter *f1
* f1
)
72 (defparameter *f2
* f2
)
73 (defparameter *f3
* f3
)
74 (defparameter *f4
* f4
))
76 (plot-function *f1
* #'sin
(interval-of 0 2) :x-title
"x" :y-title
"sin(x)")
77 (plot-function *f2
* #'cos
(interval-of 0 2) :x-title
"x" :y-title
"cos(x)")
78 (plot-function *f3
* #'tan
(interval-of 0 2) :x-title
"x" :y-title
"tan(x)")
79 (plot-function *f4
* #'/ (interval-of 0 2) :x-title
"x" :y-title
"1/x")
85 (xs (num-sequence :from
0 :to
10 :length n
))
86 (ys (map 'vector
#'(lambda (x) (+ x
8 (random 4.0))) xs
))
87 (weights (replicate #'(lambda () (1+ (random 10))) n
'fixnum
))
88 (da (plot-simple *frame1
* (interval-of 0 10) (interval-of 10 20)
89 :x-title
"x" :y-title
"y")))
90 (draw-symbols da xs ys
:weights weights
))
92 (xlib-image-context-to-png (context *frame1
*) "/home/tony/test1.png")
93 (xlib-image-context-to-png (context *frame2
*) "/home/tony/test2.png")
97 ;;; EXAMPLE FOR DSC2009
98 (defparameter *frame2
* (as-frame (create-xlib-image-context 300 300)
99 :background-color
+white
+))
101 (bind ((#2A
((f1 f2
) (f3 f4
))
102 (split-frame *frame2
* (percent 50) (percent 50))))
103 (defparameter *f1
* f1
)
104 (defparameter *f2
* f2
)
105 (defparameter *f3
* f3
)
106 (defparameter *f4
* f4
))
107 (plot-function *f1
* #'sin
(interval-of 0 2) :x-title
"x" :y-title
"sin(x)")
108 (plot-function *f2
* #'cos
(interval-of 0 2) :x-title
"x" :y-title
"cos(x)")
109 (plot-function *f3
* #'tan
(interval-of 0 2) :x-title
"x" :y-title
"tan(x)")
111 (num-sequence :from
0 :to
10 :length
30)
114 (xs (num-sequence :from
0 :to
10 :length n
))
115 (ys (map 'vector
#'(lambda (x) (+ x
8 (random 4.0))) xs
))
116 (weights (replicate #'(lambda () (1+ (random 10))) n
'fixnum
))
117 (da (plot-simple *f4
* (interval-of 0 10) (interval-of 10 20)
118 :x-title
"x" :y-title
"y")))
119 (draw-symbols da xs ys
:weights weights
))
120 (xlib-image-context-to-png (context *f1
*) "/home/tony/test1.png")
121 (xlib-image-context-to-png (context *frame2
*) "/home/tony/test2.png")
122 (destroy (context *frame2
*))