Utility for creating animations from a series of images
- (make-animator #!key (magnitude 10000) (frames-per-second 4) (type png) (width 1600) (height 900)) → Two values: next-frame and finalize procedure
Create an animator, which consists of two values: a frame-creator and a finalizer.
Next-frame is a niladic function which returns the filename of the next frame; finalize is a monadic function taking the name of the resultant animation (e.g. "graph.avi").
- Roughly the number of animations one anticipates
- Frames per second
- The frame type; one of e.g. "png", "jpg"
- The width of the frame in pixels (#f for no scaling)
- The height of the frame (#f for no scaling)
(define (make-animator #!key (magnitude 10000) (frames-per-second 4) (type "png") (width 1600) (height 900)) (let ((directory (create-temporary-directory)) (current-frame 0) (digits (inexact->exact (ceiling (/ (log magnitude) (log 10)))))) (define (next-frame) (let ((frame (make-pathname directory (format (format "~~~a,48d" digits) current-frame) type))) (inc! current-frame) frame)) (define (finalize animation) (let ((options (option-string (append `((type unquote type) (fps unquote frames-per-second)) (if width `((w unquote width)) '()) (if height `((h unquote height)) '()))))) (run (mencoder ,(format "mf://~a" (make-pathname directory (format "*.~a" type))) -mf ,options -ovc lavc -o ,animation)))) (values next-frame finalize)))
In this hypothetical example, we're running a depth-first-search on a graph; outputting an animation frame every step.
(receive (next-frame finalize) (make-animator) (let ((graph (make-random-graph))) (call-for-each-frame (depth-first-search graph) (lambda (graph) (write-graph-as-png graph (next-frame)))) (finalize "graph")))
- Initial release
- Fix cock-invocation.
- Add width and height.
- Remove the dependency on setup-helper-cock.
- Remove the dependency on debug.
- Use hahn.
Documented by hahn.