;; Copyright (C) 1996 DIMACS Center, Rutgers, The State University of New Jersey
;; Author(s): Jonathan Berry
;; This software is copyrighted by the DIMACS Center at Rutgers, The State
;; University of New Jersey.  IT IS PROVIDED AS IS, AND THE AUTHORS, DIMACS, AND
;; RUTGERS, THE STATE UNIVERSITY OF NEW JERSEY  DISCLAIM
;; ALL LIABILITY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
;; DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
;; DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
;; POSSIBILITY OF SUCH DAMAGE.
;; THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
;; IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
;; NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
;; MODIFICATIONS.
;; The authors hereby grant permission to use, copy, modify, distribute,
;; and license this software and its documentation for any purpose, provided
;; that existing copyright notices are retained in all copies and that this
;; notice is included verbatim in any distributions. No written agreement,
;; license, or royalty fee is required for any of the authorized uses.
;; Modifications to this software may be copyrighted by their authors
;; and need not follow the licensing terms described here, provided that
;; the new terms are clearly indicated on the first page of each file where
;; they apply.
;; Last File Update: 30-May-1997
;; 
(define-generic flash)
(define-method flash ((e <edge-item>) (num-times <integer>)(duration <integer>))
      (let   ((c (color e)))
          (do ((i 0 (+ i 1))) ((= i num-times) #f)
                (slot-set! e 'color "white")
                (update)
                (after duration)
                (slot-set! e 'color c)
                (update))))
(define-method flash ((e <edge-item>) (duration <integer>))
        (flash e duration))
(define-method flash ((e <edge-item>))
        (flash e 4))
(define-method flash ((e <edge*>))
      (flash (edge-item e)))

(define-method flash((v <vertex-item>)(num-times <integer>)(duration <integer>))
      (let   ((c (color v)))
          (do ((i 0 (+ i 1))) ((= i num-times) #f)
		(slot-set! v 'color "white")
		(update)
		(after duration)
		(slot-set! v 'color c)
		(update))))
(define-method flash ((v <vertex-item>) (duration <integer>))
	(flash v 4 duration))
(define-method flash ((v <vertex-item>))
	(flash v 4 20))

(define-method flash ((v <vertex*>))
 	(flash (vertex-item v)))

(define-generic jiggle)
(define-method jiggle ((e <edge-segment-item>) (duration <integer>))
      (let*  ((l (slot-ref e 'line-item))
	      (x1 (car (coords l)))
              (y1 (cadr (coords l)))
              (p2 (cddddr (coords l)))
	      (x2 (car p2))
	      (y2 (cadr p2))
	      (x (car (coords e)))
              (y (cadr (coords e)))
	      (m (if (= x1 x2) 10 (- (/ (- y2 y1) (- x2 x1)))))
	      (steep (if (> (abs m) 1) #t #f))
	      (xinc (if steep 5 0))
	      (yinc (if steep 0 5))
	      (xp1 (+ x xinc))
	      (yp1 (+ y yinc))
	      (xp2 (- x xinc))
	      (yp2 (- y yinc)))
	(set! (coords e) (list xp1 yp1))
	(update)
	(after duration)
	(set! (coords e) (list xp2 yp2))
	(update)
        (set! (coords e) (list x y))))
(define-method jiggle ((e <edge-item>) (num-times <integer>)
		       (duration <integer>)) 
      (let ((segs (slot-ref e 'seg-list)))
          (do ((i 0 (+ i 1))) ((= i num-times) #f)
		(map (lambda (x) (jiggle x duration)) segs))))
(define-method jiggle ((e <edge-item>) (duration <integer>))
	(jiggle e 4 duration))
(define-method jiggle ((e <edge-item>))
	(jiggle e 4 20))
(define-method jiggle ((e <edge*>)) 
      (jiggle (edge-item e)))

(define-method jiggle ((v <vertex-item>) (num-times <integer>)
		       (duration <integer>)) 
      (let*  ((vo (slot-ref v 'vertex-object))
	      (sz (slot-ref v 'size))
	      (coords (vertex-object-coords vo sz)))
          (do ((i 0 (+ i 1))) ((= i num-times) #f)
		(set-vertex-object-coords! vo (+ 3 (car coords))
					      (+ 3 (cadr coords))
					      sz)
		(update)
		(after duration)
		(set-vertex-object-coords! vo (car coords)
					      (cadr coords)
					      sz)
		(update))))

(define-method jiggle ((v <vertex-item>) (iter <integer>))
	(jiggle v iter 20))
(define-method jiggle ((v <vertex-item>))
	(jiggle v 4 20))

(define-method jiggle ((v <vertex*>))
      (jiggle (vertex-item v)))
(provide "flash")
