diff --git a/demo.scm b/demo.scm index 8d32939..b1801c5 100644 --- a/demo.scm +++ b/demo.scm @@ -18,18 +18,14 @@ (set-node-color (cdr pair) red) (cdr pair)))) graph)) - -(define djikstra-generator +(define (make-graph-generator f) (generator - (djikstra graph 90 9 (lambda (visited heap) + (f graph 90 9 (lambda (visited heap) (yield (color-graph graph visited heap)))) #f)) -(define a*-generator - (generator - (a* graph 90 9 (lambda (visited heap) - (yield (color-graph graph visited heap)))) - #f)) +(define djikstra-generator (make-graph-generator djikstra)) +(define a*-generator (make-graph-generator a*)) (write-graphs-to-file "djikstra.webp" djikstra-generator) (write-graphs-to-file "astar.webp" a*-generator) diff --git a/graphgif.scm b/graphgif.scm index 507c079..8f540c6 100644 --- a/graphgif.scm +++ b/graphgif.scm @@ -33,12 +33,11 @@ (lambda (node) (cairo-set-source cr black) (let-values ([(x y) (car+cdr (node-coords node))] - [edges (node-edges node)]) + [(edges) (node-edges node)]) (for-each (lambda (edge) - (let* ([other (assq-ref graph edge)] - [ox (car (node-coords other))] - [oy (cdr (node-coords other))]) + (let*-values ([(other) (assq-ref graph edge)] + [(ox oy) (car+cdr (node-coords other))]) (cairo-move-to cr x y) (cairo-line-to cr ox oy) (cairo-stroke cr))) @@ -48,7 +47,7 @@ "Creates a closure that draws the nodes of graph using cr" (lambda (node) (let-values ([(x y) (car+cdr (node-coords node))] - [color (or (node-color node) white)]) + [(color) (or (node-color node) white)]) (cairo-arc cr x y 4. 0. tau) (cairo-set-source cr color) (cairo-fill-preserve cr)