# NOT RUN {
if (interactive()) {
# Basic animation of an element's
# position (moving to a new `x` and
# `y` position)
svg_1 <-
SVG(width = 300, height = 300) %>%
svg_rect(
x = 50, y = 50,
width = 50, height = 50,
attrs = svg_attrs_pres(
stroke = "magenta",
fill = "lightblue"
),
anims = anims(
2.0 ~ anim_position(x = 100, y = 50)
)
)
# We can define multiple animations
# for a single element: put them in a
# `list()`; the `easing_fn` function for
# both `anim_*()` function is no longer
# linear but now eases in and out
svg_2 <-
SVG(width = 300, height = 300) %>%
svg_rect(
x = 50, y = 50,
width = 50, height = 50,
attrs = svg_attrs_pres(
stroke = "black",
fill = "yellow"
),
anims = anims(
0.5 ~ list(
anim_position(x = 50, y = 50, easing_fn = ease_in_out()),
anim_rotation(0, easing_fn = ease_in_out())
),
2.0 ~ list(
anim_position(x = 200, y = 50, easing_fn = ease_in_out()),
anim_rotation(90, easing_fn = ease_in_out())
)
)
)
# The initial state of the element
# can be used in any `anim_*()`
# function with `initial = TRUE`
svg_3 <-
SVG(width = 300, height = 300) %>%
svg_rect(
x = 50, y = 50,
width = 50, height = 50,
attrs = svg_attrs_pres(
stroke = "black",
fill = "yellow"
),
anims = anims(
1.0 ~ list(
anim_position(initial = TRUE),
anim_rotation(initial = TRUE)
),
3.0 ~ list(
anim_position(x = 200, y = 50),
anim_rotation(90)
),
5.0 ~ list(
anim_position(initial = TRUE),
anim_rotation(initial = TRUE)
)
)
)
}
# }
Run the code above in your browser using DataLab