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.
gen_events(
.data,
ease,
start,
end = NULL,
range = NULL,
enter = NULL,
exit = NULL,
enter_length = 0,
exit_length = 0
)
A data.frame with components at different stages
The easing function to use. Either a single string or one for each column in the data set.
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.
The range of time points to include in the tween. If NULL
it
will use the range of time
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.
The lenght of the opening and closing
transitions if enter
and/or exit
is given. Measured in the same units as
time
A component_generator
object
Other Other generators:
gen_along()
,
gen_at()
,
gen_components()
,
gen_keyframe()
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)
#> x y time duration .phase
#> 1 0.08075014 0.28989230 0.6801629 0.082519942 static
#> 2 0.60077958 0.73531960 0.6416793 0.057004495 exit
#> 3 0.16513933 0.19595673 0.6602843 0.033571908 exit
#> 4 -0.34874073 0.74152153 0.7656002 0.019151803 enter
#> 5 -0.39358075 0.05144628 0.7696748 0.094776394 enter
#> 6 -0.47692325 0.43217126 0.7793086 0.002006522 enter
#> 7 0.05767481 0.94857658 0.7133973 0.055991284 enter