(index ("make-animator" 0))
(def (sig (procedure "(make-animator #!key (magnitude 10000) (frames-per-second 4) (type png) (width 1600) (height 900)) → Two values: next-frame and finalize" (id make-animator))) (p "Create an animator, which consists of two values: a frame-creator and a finalizer.") (p (tt "Next-frame") " is a niladic function which returns the filename of the next frame; " (tt "finalize") " is a monadic function taking the name of the resultant animation (e.g. " (tt "\"graph.avi\"") ").") (dl (dt (tt "magnitude")) (dd "Roughly the number of animations one anticipates") (dt (tt "frames-per-second")) (dd "Frames per second") (dt (tt "type")) (dd "The frame type; one of e.g. \"png\", \"jpg\"") (dt (tt "width")) (dd "The width of the frame in pixels (#f for no scaling)") (dt (tt "height")) (dd "The height of the frame (#f for no scaling)")) (highlight scheme "(define (make-animator\n         #!key\n         (magnitude 10000)\n         (frames-per-second 4)\n         (type \"png\")\n         (width 1600)\n         (height 900))\n  (let ((directory (create-temporary-directory))\n        (current-frame 0)\n        (digits (inexact->exact (ceiling (/ (log magnitude) (log 10))))))\n    (define (next-frame)\n      (let ((frame (make-pathname\n                     directory\n                     (format (format \"~~~a,48d\" digits) current-frame)\n                     type)))\n        (inc! current-frame)\n        frame))\n    (define (finalize animation)\n      (let ((options\n              (option-string\n                (append\n                  `((type unquote type) (fps unquote frames-per-second))\n                  (if width `((w unquote width)) '())\n                  (if height `((h unquote height)) '())))))\n        (run (mencoder\n               ,(format\n                  \"mf://~a\"\n                  (make-pathname directory (format \"*.~a\" type)))\n               -mf\n               ,options\n               -ovc\n               lavc\n               -o\n               ,animation))))\n    (values next-frame finalize)))"))
