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.
0 s — setup
2 s — movement
4 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)' |
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 |
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.