From 2da23e143c834a9b9bdf4677834c2f3936bb7de0 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Tue, 22 Oct 2024 09:25:54 -0500 Subject: [PATCH] use vectors --- demo.scm | 2 +- graphgif.scm | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/demo.scm b/demo.scm index e49b0e5..6d3a48e 100644 --- a/demo.scm +++ b/demo.scm @@ -7,4 +7,4 @@ (define graph1 (generate-web 10 10)) (define graph2 (remove-rect (copy-tree graph1) 10 3 3 4 5)) (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") diff --git a/graphgif.scm b/graphgif.scm index f69b7e8..bee75f5 100644 --- a/graphgif.scm +++ b/graphgif.scm @@ -2,7 +2,8 @@ (use-modules (cairo) (srfi srfi-1) - (srfi srfi-9 gnu)) + (srfi srfi-9 gnu) + (srfi srfi-43)) (re-export (cairo-pattern-create-rgb . create-color)) @@ -141,16 +142,16 @@ (define (output-to-file surfaces filename) (define pngdir (mkdtemp "/tmp/graphgif_XXXXXX")) - (do ([i 1 (1+ i)] - [surfaces surfaces (cdr surfaces)]) - ((null? surfaces)) - (cairo-surface-write-to-png - (car surfaces) - (string-append pngdir "/img-" (number->string i) ".png"))) + (vector-for-each + (lambda (i surface) + (cairo-surface-write-to-png + surface + (string-append pngdir "/img-" (number->string i) ".png"))) + surfaces) (system* "ffmpeg" "-i" (string-append pngdir "/img-%d.png") "-r" "1" 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: ;; geiser-scheme-implementation: guile