use vectors

This commit is contained in:
Dane Johnson 2024-10-22 09:25:54 -05:00
parent 31f4707fbf
commit 2da23e143c
2 changed files with 10 additions and 9 deletions

View File

@ -7,4 +7,4 @@
(define graph1 (generate-web 10 10)) (define graph1 (generate-web 10 10))
(define graph2 (remove-rect (copy-tree graph1) 10 3 3 4 5)) (define graph2 (remove-rect (copy-tree graph1) 10 3 3 4 5))
(assq-set! graph2 0 (set-node-color (assq-ref graph2 0) red)) (assq-set! graph2 0 (set-node-color (assq-ref graph2 0) red))
(write-graphs-to-file (list graph1 graph2) "graph.gif") (write-graphs-to-file (vector graph1 graph2) "graph.gif")

View File

@ -2,7 +2,8 @@
(use-modules (cairo) (use-modules (cairo)
(srfi srfi-1) (srfi srfi-1)
(srfi srfi-9 gnu)) (srfi srfi-9 gnu)
(srfi srfi-43))
(re-export (cairo-pattern-create-rgb . create-color)) (re-export (cairo-pattern-create-rgb . create-color))
@ -141,16 +142,16 @@
(define (output-to-file surfaces filename) (define (output-to-file surfaces filename)
(define pngdir (mkdtemp "/tmp/graphgif_XXXXXX")) (define pngdir (mkdtemp "/tmp/graphgif_XXXXXX"))
(do ([i 1 (1+ i)] (vector-for-each
[surfaces surfaces (cdr surfaces)]) (lambda (i surface)
((null? surfaces)) (cairo-surface-write-to-png
(cairo-surface-write-to-png surface
(car surfaces) (string-append pngdir "/img-" (number->string i) ".png")))
(string-append pngdir "/img-" (number->string i) ".png"))) surfaces)
(system* "ffmpeg" "-i" (string-append pngdir "/img-%d.png") "-r" "1" filename)) (system* "ffmpeg" "-i" (string-append pngdir "/img-%d.png") "-r" "1" filename))
(define-public (write-graphs-to-file graphs filename) (define-public (write-graphs-to-file graphs filename)
(output-to-file (map draw-abstract-graph graphs) filename)) (output-to-file (vector-map (lambda (_ graph) (draw-abstract-graph graph)) graphs) filename))
;; Local Variables: ;; Local Variables:
;; geiser-scheme-implementation: guile ;; geiser-scheme-implementation: guile