;; 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: 31-Jul-1996
;; 

(define-generic flash)


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

(define-method flash ((e <edge-item>))
        (flash e 4))

(define-method flash ((e <edge*>) (gv <graph-view>))
      (flash (edge-item e gv)))


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

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

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

(define-generic jiggle)
(define-method jiggle ((e <edge-segment-item>))
      (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 20)
	(set! (coords e) (list xp2 yp2))
	(update)
        (set! (coords e) (list x y))))

(define-method jiggle ((e <edge-item>) (num-times <integer>)) 
      (let ((segs (slot-ref e 'seg-list)))
          (do ((i 0 (+ i 1))) ((= i num-times) #f)
		(map (lambda (x) (jiggle x)) segs))))

(define-method jiggle ((e <edge-item>))
	(jiggle e 4))

(define-method jiggle ((e <edge*>)(gv <graph-view>)) 
      (jiggle (edge-item e)))

(provide "flash")
