;;; pp-visualizer.scm -*-scheme-*-
;;; Time-stamp: <1997/07/03 23:40:34 narazaki@InetQ.or.jp>
;;; Author: (c) Shuji Narazaki 

;;; Comment:
;;; Code:

(define (script-fu-pp-visualizer datafile image-size)
  (define (parse-file file)
    '(30 ((10 . 10) (1 . 3) (3 . 4) (11 . 15) (18 . 18))
	 ((11 . 11) (2 . 3) (4 . 5) (10 . 14) (17 . 17))
	 ))
  (let* ((img (car (gimp-image-new image-size image-size RGB)))
	 (layer #f)
	 (data (parse-file datafile))
	 (grid (make-list (car data) 1))
	 (grid-size (/ image-size (car data)))
	 (counter 0)
	 (pos-list #f)
	 (time-max (- (length data) 1)))
    (define (draw-circle x y color)
      (gimp-ellipse-select img 
			   (+ (* (- x 1) grid-size) 1)
			   (+ (* (- y 1) grid-size) 1)
			   (- grid-size 2) (- grid-size 2) REPLACE TRUE FALSE 0)
      (gimp-palette-set-background color)
      (gimp-edit-fill img layer)
      (gimp-selection-none img))
    (gimp-image-disable-undo img)
    (set! data (cdr data))
    (while (< counter time-max)
      (set! layer (car (gimp-layer-new img image-size image-size RGBA_IMAGE
				       (string-append "Time = "
						      (number->string counter))
				       100 NORMAL)))
      (gimp-image-add-layer img layer 0)
      (gimp-edit-clear img layer)
      (script-fu-grid-system img layer grid grid)
      (set! pos-list (car data))
      ;; red
      (draw-circle (caar pos-list) (cdar pos-list) '(255 0 0))
      (mapcar (lambda (xy) (draw-circle (car xy) (cdr xy) '(0 0 255))) 
	      (cdr pos-list))
      (set! data (cdr data))
      (set! counter (+ counter 1)))
    (gimp-image-enable-undo img)
    (gimp-display-new img)
    (gimp-displays-flush)))

(script-fu-register "script-fu-pp-visualizer"
		    "<Toolbox>/Xtns/Script-Fu/Misc/PP Visualizer"
		    "pursuit problem visualizer"
		    "Shuji Narazaki"
		    "Shuji Narazaki"
		    "1997"
		    ""
		    SF-VALUE "Data File" "\"/tmp/\""
		    SF-VALUE "Image Size" "300"
)

;;; Local Variables:
;;; mode:scheme
;;; End:
;;; .scm ends here