View source: R/animate_piece.R
animate_piece | R Documentation |
animate_piece()
animates board game pieces.
animate_piece(
dfs,
file = "animation.gif",
...,
annotate = TRUE,
.f = piecepackr::grid.piece,
cfg = getOption("piecepackr.cfg", NULL),
envir = getOption("piecepackr.envir", game_systems("sans")),
n_transitions = 0L,
n_pauses = 1L,
fps = n_transitions + n_pauses,
width = NULL,
height = NULL,
ppi = NULL,
new_device = TRUE,
annotation_scale = NULL
)
dfs |
A list of data frames of game data to plot. |
file |
Filename to save animation unless |
... |
Arguments to |
annotate |
If |
.f |
Low level graphics function to use e.g. |
cfg |
A piecepackr configuration list |
envir |
Environment (or named list) of piecepackr configuration lists |
n_transitions |
Integer, if over zero (the default) how many transition frames to add between moves. |
n_pauses |
Integer, how many paused frames per completed move. |
fps |
Double, frames per second. |
width |
Width of animation (in inches). Inferred by default. |
height |
Height of animation (in inches). Inferred by default. |
ppi |
Resolution of animation in pixels per inch. By default set so image max 600 pixels wide or tall. |
new_device |
If |
annotation_scale |
Multiplicative factor that scales (stretches) any annotation coordinates.
By default uses |
Nothing, as a side effect creates an animation.
# Basic tic-tac-toe animation
dfs <- list()
d.frame <- function(piece_side = "bit_back", ..., rank = 1L) {
data.frame(piece_side = piece_side, ..., rank = rank,
cfg = "checkers1", stringsAsFactors = FALSE)
}
df <- d.frame("board_back", suit = 2L, rank = 3L, x = 2, y = 2, id = "1")
dfs[[1L]] <- df
df <- rbind(df, d.frame(suit = 1L, x = 2, y = 2, id = "2"))
dfs[[2L]] <- df
df <- rbind(df, d.frame(suit = 2L, x = 1, y = 2, id = "3"))
dfs[[3L]] <- df
df <- rbind(df, d.frame(suit = 1L, x = 3, y = 1, id = "4"))
dfs[[4L]] <- df
df <- rbind(df, d.frame(suit = 2L, x = 1, y = 3, id = "5"))
dfs[[5L]] <- df
df <- rbind(df, d.frame(suit = 1L, x = 1, y = 1, id = "6"))
dfs[[6L]] <- df
df <- rbind(df, d.frame(suit = 2L, x = 3, y = 3, id = "7"))
dfs[[7L]] <- df
df <- rbind(df, d.frame(suit = 1L, x = 2, y = 1, id = "8"))
dfs[[8L]] <- df
## Press enter to walk through moves in a "game" in new graphics device
if (interactive()) {
animate_piece(dfs, file = NULL)
}
## Save GIF of game with animation transitions
## Not run: # May take more than 5 seconds on CRAN servers
if ((requireNamespace("animation", quietly = TRUE) ||
requireNamespace("gifski", quietly = TRUE)) &&
requireNamespace("tweenr", quietly = TRUE)) {
file <- tempfile("tic-tac-toe", fileext = ".gif")
animate_piece(dfs, file = file,
n_transitions = 5L, n_pauses = 2L, fps = 9)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.