# 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
if (FALSE) # 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)
}
Run the code above in your browser using DataLab