On this page:
43.1 Complete source
43.2 How the program is organized
43.3 Render the movie
43.4 Try one change
9.3

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.

Requirements: Animate; FFmpeg for MP4 output.

0 s0 s0.25 s0.25 s0.5 s0.5 s0.75 s0.75 s1 s1 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)'

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

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.