43 A moving circle
One circle moves from left to right, then stays at its destination. This is the smallest complete example of the pattern used throughout Animate: describe an object, put it in a Scene, add a change, and keep the result visible.
0 s
0.25 s
0.5 s
0.75 s
1 s
The one-second movement. The exported animation adds a half-second hold after it.
43.1 Complete source
scribblings/examples/moving-circle.rkt
#lang racket/base (require animate) (provide disc initial movement animation) ;; doc: object begin (define disc (circle #:id 'moving-circle #:center (vec2 -3 0) #:radius 3/4 #:fill "dodgerblue" #:stroke "navy" #:stroke-width 3)) ;; doc: object end ;; doc: scene begin (define initial (scene-add (make-scene) disc)) ;; doc: scene end ;; doc: motion begin (define movement (scene-play initial (move-to 'moving-circle (vec2 3 0)) #:duration 1)) ;; doc: motion end ;; doc: hold begin (define animation (scene-wait movement 1/2)) ;; doc: hold end
43.2 How the program is organized
disc is the original Visual. initial puts it in a Scene without adding time. movement adds one second of motion; animation adds the final half-second hold. These are separate values, so the program can inspect the starting Scene without undoing the movement.
The movie uses animation, not just movement. Its total duration is 1.5 seconds. The final hold gives the viewer time to see the completed move.
43.3 Render the movie
racket \ |
-e '(require animate/render "scribblings/examples/moving-circle.rkt")' \ |
-e '(render-frames! animation "slides-output/complete-examples/moving-circle/frames" #:fps 30)' \ |
-e '(encode-mp4! "slides-output/complete-examples/moving-circle/frames" "slides-output/complete-examples/moving-circle/moving-circle.mp4" #:fps 30)' |
43.4 Try one change
Change the destination in move-to, or change the duration of the move. Keep a final hold. To see a still while editing in DrRacket, evaluate (scene->pict animation 1).
See Quick Start: a moving circle for the explanation of each constructor and Save frames and make a video for the difference between rendering and encoding.