JScene: Construct a JScene

View source: R/anim-tools.R

JSceneR Documentation

Construct a JScene

Description

A JScene is a portion of a complex animation. It consists of some metadata (duration, frame rate), a set of animation transitions and a plotting function.

Usage

JScene(duration, fps, startAfter = 0, ..., plotFn)

Arguments

duration

Scene duration in seconds.

fps

Frame rate (frames per second).

startAfter

Timing of the start of this frame. Number of seconds after the end of the previous scene that this scene starts.

...

Ordered set of transitions. Transitions may be named for documentation purposes, but names are not required.

plotFn

The parameterised plotting function. Called with one positional argument for each transition, and an optional final boolean argument, add, which is TRUE if the function should add to an existing plot rather than create a new plot. The add is only used for overlapping scenes.

Value

A list, known as a JScene, that can be included in a list of scenes then used to create an animation.

See Also

JAnimateScenes, JTransition, JPlotSceneFn

Examples

# Construct a single-scene animation
scenes <- list(JScene(1, # Duration
                      20, # Frame rate

                      # Parameters to be passed to plotFn
                      pt1 = JTransition(1, 0),
                      pt2 = JTransition(0, 1),

                      # Plotting function with parameters matching those defined above
                      plotFn = function(pt1, pt2) {
                        plot(c(pt1, 1 - pt2), c(pt2, pt1), type = "b",
                             xlim = c(0, 1), ylim = c(0, 1))
                      }))
# Plot 20 frames
for (i in 1:20) {
  JPlotSceneFn(scenes)(i)
  # Crude way to animate in real time
  dev.flush()
  Sys.sleep(0.05)
}


JimMcL/JUtils documentation built on Nov. 7, 2024, 11:25 a.m.