home *** CD-ROM | disk | FTP | other *** search
- ; book pp.311-313
-
- (setf handdraw (plot-lines (rseq 0 1 50) (repeat 0 50)))
- (send handdraw :y-axis nil)
- (send handdraw :add-mouse-mode 'drawing
- :title "Drawing"
- :cursor 'finger
- :click :mouse-drawing)
- #|
- (defmeth handdraw :mouse-drawing (x y m1 m2)
- (flet ((adjust (x y)
- (let* ((n (send self :num-lines))
- (reals (send self :canvas-to-real x y))
- (i (x-index (first reals) n))
- (y (second reals)))
- (send self :linestart-coordinate 1 i y)
- (send self :redraw-content))))
- (adjust x y)
- (send self :while-button-down #'adjust)))
- |#
- (defmeth handdraw :mouse-drawing (x y m1 m2)
- (let* ((n (send self :num-lines))
- (reals (send self :canvas-to-real x y))
- (old-i (x-index (first reals) n))
- (old-y (second reals)))
- (flet ((adjust (x y)
- (let* ((reals (send self :canvas-to-real x y))
- (new-i (x-index (first reals) n))
- (new-y (second reals))
- (i (iseq old-i new-i))
- (yvals (interpolate i old-i new-i old-y new-y)))
- (send self :linestart-coordinate 1 i yvals)
- (send self :redraw-content)
- (setf old-i new-i)
- (setf old-y new-y))))
- (adjust x y)
- (send self :while-button-down #'adjust))))
- (defun x-index (x n)
- (max 0 (min (- n 1) (floor (* n x)))))
- (defun interpolate (x a b ya yb)
- (let* ((range (if-else (/= a b) (- b a) 1))
- (p (pmax 0 (pmin 1 (abs (/ (- x a) range))))))
- (+ (* p yb) (* (- 1 p) ya))))
- (defmeth handdraw :lines ()
- (let ((i (iseq (send self :num-lines))))
- (list (send self :linestart-coordinate 0 i)
- (send self :linestart-coordinate 1 i))))
-
- (send handdraw :mouse-mode 'drawing)
-