On this page:
50.1 Complete source
50.2 How the program is organized
50.3 Render the compiled Scene
50.4 Open the maintained interactive variant
50.5 Try one change
9.3

50 A source-block program🔗ℹ

This program gives three stages names: setup, movement, and a final hold. It exports both the source program and its compiled Scene. The same organization is useful when a longer lesson will be edited in the interactive preview.

Requirements: Animate Authoring; FFmpeg for MP4 output; GUI only for the optional preview.

0 s — setup0 s — setup2 s — movement2 s — movement4 s — held result4 s — held result

Setup, movement, and the held result of the four-second compiled program.

50.1 Complete source🔗ℹ

scribblings/examples/source-blocks.rkt

#lang racket/base
(require animate animate/authoring)
(provide hot-reload-demo animation)
 
;; doc: blocks begin
(define-scene-program hot-reload-demo
  #:initial (make-scene)
  (scene-block setup (scene)
    (scene-wait
     (scene-add scene
                (circle #:id 'dot #:center (vec2 -3 0) #:radius 1/2
                        #:fill "tomato" #:stroke "firebrick"))
     1))
  (scene-block move-dot (scene)
    (scene-play scene (move-to 'dot (vec2 3 0)) #:duration 2))
  (scene-block hold (scene)
    (scene-wait scene 1)))
;; doc: blocks end
 
;; Headless compilation for the manual's frame renderer and tests. This does
;; not open a preview, draw frames, or encode a movie.
(define animation
  (compiled-scene-program-scene (compile-scene-program hot-reload-demo)))
 

50.2 How the program is organized🔗ℹ

Each scene-block receives the Scene built so far and returns the next one. The setup lasts one second, movement lasts two, and the final hold lasts one. compile-scene-program evaluates those blocks; it does not render frames or open a window. The animation export is the resulting four-second Scene.

A block’s name identifies a source-level unit that the preview can track. It is not an object ID, and it does not introduce a second animation clock.

50.3 Render the compiled Scene🔗ℹ

racket \

  -e '(require animate/render "scribblings/examples/source-blocks.rkt")' \

  -e '(render-frames! animation "slides-output/complete-examples/source-blocks/frames" #:fps 30)' \

  -e '(encode-mp4! "slides-output/complete-examples/source-blocks/frames" "slides-output/complete-examples/source-blocks/source-blocks.mp4" #:fps 30)'

Writes numbered PNGs, then encodes them as an MP4. This simple two-step route renders in one process.
Expected output: "slides-output/complete-examples/source-blocks/source-blocks.mp4".

50.4 Open the maintained interactive variant🔗ℹ

The repository also contains "examples/source-block-hot-reload.rkt". It uses the same setup, movement, and hold, and adds the explicit preview launch. It is a separate interactive example, not the headless module printed above.

racket examples/source-block-hot-reload.rkt

Opens the maintained interactive variant. This is a GUI action, not a movie render.
This command opens a preview; it does not write a movie.

50.5 Try one change🔗ℹ

Change the destination or duration inside the movement block. While using the preview, save the file and inspect which blocks were rebuilt. Keep file output out of block bodies so recompiling a source program does not write a movie.

See Organize a source program and Preview, edit, and inspect.