gen_events: Generator for tweening the appearance of elements

View source: R/gen_events.R

gen_eventsR Documentation

Generator for tweening the appearance of elements

Description

This is a generator version of tween_events(). It returns a generator that can be used with get_frame() and get_raw_frames() to extract frames for a specific time point scaled between 0 and 1.

Usage

gen_events(
  .data,
  ease,
  start,
  end = NULL,
  range = NULL,
  enter = NULL,
  exit = NULL,
  enter_length = 0,
  exit_length = 0
)

Arguments

.data

A data.frame with components at different stages

ease

The easing function to use. Either a single string or one for each column in the data set.

start, end

The start (and potential end) of the event encoded in the row, as unquoted expressions. Will be evaluated in the context of .data so can refer to columns in it. If end = NULL the event will be without extend and only visible in a single frame, unless enter and/or exit is given.

range

The range of time points to include in the tween. If NULL it will use the range of time

enter, exit

functions that calculate a start state for new observations that appear in to or an end state for observations that are not present in to. If NULL the new/old observations will not be part of the tween. The function gets a data.frame with either the start state of the exiting observations, or the end state of the entering observations and must return a modified version of that data.frame. See the Match, Enter, and Exit section for more information.

enter_length, exit_length

The lenght of the opening and closing transitions if enter and/or exit is given. Measured in the same units as time

Value

A component_generator object

See Also

Other Other generators: gen_along(), gen_at(), gen_components(), gen_keyframe()

Examples

d <- data.frame(
  x = runif(20),
  y = runif(20),
  time = runif(20),
  duration = runif(20, max = 0.1)
)
from_left <- function(x) {
  x$x <- -0.5
  x
}
to_right <- function(x) {
  x$x <- 1.5
  x
}

gen <- gen_events(d, 'cubic-in-out', start = time, end = time + duration,
                  enter = from_left, exit = to_right, enter_length = 0.1,
                  exit_length = 0.05)

get_frame(gen, 0.65)


tweenr documentation built on May 29, 2024, 6:32 a.m.