;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; CAPTURING A MOVIE
;;
;; This example captures the first 10 seconds of
;; throbbing text to the tmp directory. each
;; frame is saved individually once every
;; 1/10 of a second. You can use quicktime
;; to build a movie using these individual files
;; by selecting open image sequence in quickttime
;; and selecting the first file in the image sequence then
;; selecting the frame rate (10 frames a second in this example).
;;
;; You could of course call gfx:capture-canvas directly inside
;; the throb function everytime you update the canvas. The
;; idea in this example though is to show how this can happen
;; indendently of any drawing routines.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define canvas (gfx:make-canvas 400 400))
(define text-style (gfx:make-text-style "Times-Roman" 72.0 (list 1.0 1.0 1.0 0.25)))
(define text-path (gfx:make-path))
; make the text into a path
(gfx:set-start-point text-path 50 150)
(gfx:add-text text-path text-style "impromptu")
; start with a clean cavas
(gfx:clear-canvas (now) canvas '(0.1 0.1 0.27 1))
(define throb
(lambda (time path val)
; wipe out a bit of the previous drawing
(gfx:clear-canvas time canvas '(0.1 0.1 0.27 0.09))
; display the text-path
(gfx:draw-path (+ time 1) canvas path
'(0.5 0.7 0.9 0.3)
'(0.0 0.9 0.2 0.1) 4)
; shift the text-path rotation one degree
(gfx:rotate-path (now) path 1 200 153 *degrees*)
; change the size of the text-path
(gfx:scale-path (+ time 2) path val val *gfx:centre-scale*)
; repeat the process with slightly changed values
(callback (+ time 1000) 'throb (+ time 3000) path
(if (> val 1.2) 0.8 (+ val 0.025)))))
(define movie-capture
(lambda (time inc cnt)
(gfx:capture-canvas canvas (string-append "/tmp/throb_" (number->string cnt) ".png"))
(if (< cnt 100)
(callback (+ time inc) 'movie-capture (+ time inc) inc (+ cnt 1)))))
; start
(throb (now) text-path 0.8)
; capture 10 seconds at 10 frames per second
(movie-capture (now) (* *second* 0.1) 0)