File: tour.lsp

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (32 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(provide "tour")

(defun sphere-rand (n)
  (loop (let* ((x (- (* 2 (uniform-rand n)) 1))
               (nx2 (sum (^ x 2))))
          (if (< nx2 1) (return (/ x (sqrt nx2)))))))


(defun tour-plot (&rest args)
  (let ((p (apply #'spin-plot args)))
    (send p :add-slot 'tour-count -1)
    (send p :add-slot 'tour-trans nil)
    (defmeth p :do-idle () (send self :tour-step))
    (defmeth p :tour-step ()
      (when (< (slot-value 'tour-count) 0)
            (let ((vars (send self :num-variables))
                  (angle (abs (send self :angle))))
              (setf (slot-value 'tour-count) 
                    (random (floor (/ pi (* 2 angle)))))
              (setf (slot-value 'tour-trans) 
                    (make-rotation (sphere-rand vars) 
                                   (sphere-rand vars)
                                   angle))))
      (send self :apply-transformation (slot-value 'tour-trans))
      (setf (slot-value 'tour-count) (- (slot-value 'tour-count) 1)))
    (defmeth p :tour-on (&rest args) (apply #'send self :idle-on args))
    (let ((item (send graph-item-proto :new "Touring" p
                      :tour-on :tour-on :toggle t)))
      (send item :key #\T)
      (send (send p :menu) :append-items item))
    p))