Converting to new core implementation.
[jars.git] / vis.scm
1 ;; Wish visualization module
2
3 (module wish
4     (make-wish
5      destroy-wish
6      set-wish-pixel)
7
8   (import scheme
9           (chicken base)
10           (chicken io)
11           (chicken process)
12           (chicken port)
13           (chicken string))
14
15   (define (make-wish w h)
16     (let-values (((in out id) (process (conc "wish -geometry " w "x" h))))
17       (with-output-to-port out
18         (lambda ()
19           (print "canvas .c -width " w " -height " h " -bg black")
20           (print "pack .c")
21           (print "image create photo core -width " w " -height " h " -palette 256/256/256")
22           (print ".c create image 0 0 -anchor nw -image core")))
23       (cons in out)))
24
25   (define (wish-in wish) (car wish))
26   (define (wish-out wish) (cdr wish))
27
28   (define (wish% wish . args)
29     (with-output-to-port (wish-out wish)
30       (lambda ()
31         (apply print args))))
32
33   (define (destroy-wish wish)
34     (wish% wish "destroy .")
35     (close-input-port (wish-in wish))
36     (close-output-port (wish-out wish)))
37
38   (define (set-wish-pixel wish x y col)
39     (wish% wish "core put " col " -to " x " " y)))
40
41
42   ;; ;; Test code
43
44   ;; (let ((w (make-wish 640 480)))
45   ;;   (set-wish-pixel w 10 10 "red")
46   ;;   (sleep 3)
47   ;;   (destroy-wish w)))