/*
 * $VER: TimeLapse 1.00.00 (24.9.92)
 *
 * Arexx program for the ImageFX image processing system.
 * Written by Thomas Krehbiel
 *
 * This program will capture a frame from any of the framegrabber
 * modules at intervals, render and save the frames out to an
 * animation.
 *
 */

OPTIONS RESULTS

SIGNAL ON BREAK_C

/*
 * Make sure we have a framegrabber-type scanner module.
 */
GetScanner
IF (result ~= 'FrameGrabber') & (result ~= 'IVFG') THEN DO
   RequestNotify 'This program requires a framegrabber module.'
   SetScanner
   IF rc ~= 0 THEN EXIT
   END


/*
 * And make sure we have an appropriate Render module.
 */
GetRender
IF (result ~= 'Amiga') & (result ~= 'Amiga2.0') THEN DO
   RequestNotify 'This program requires either Amiga render module.'
   SetRender
   IF rc ~= 0 THEN EXIT
   END

/*
 * Get time lapse interval in seconds.  Keep in mind that it may
 * take a moment or two to capture a frame, render it, and then
 * save it to an animation.
 */
RequestNumber '"Time Lapse Interval (Seconds):"' 0 600 10
IF rc ~= 0 THEN EXIT
lapse = result

/*
 * Get output animation filename.
 */
RequestFile '"Output Animation Filename:"'
IF rc ~= 0 THEN EXIT
output = result

IF EXISTS(output) THEN DO
   RequestResponse 'Output animation exists.  Overwrite?'
   IF rc ~= 0 THEN EXIT
   ADDRESS COMMAND 'c:Delete >NIL:' output
   END

/*
 * Make sure we generate a palette for the first frame.
 */
LockRange 0 OFF

/*
 * Now loop until the user aborts the script.
 */
i = 1
DO FOREVER

   Message 'Frame' i
   i = i + 1

   Scanner Grab

   Render Go
   SaveRenderedAs ANIM '"'output'"' Append Keep
   Render Close

   /* Lock palette on frames 2 and beyond */
   LockRange 0 ON

   IF lapse ~= 0 THEN ADDRESS COMMAND 'c:Wait' lapse

   END

BREAK_C:

SaveRenderedAs ANIM '"'output'"' Close

EXIT
