animate_game: Animate a ppn game

View source: R/animate_game.R

animate_gameR Documentation

Animate a ppn game

Description

Animate a ppn game

Usage

animate_game(
  game,
  file = "animation.gif",
  annotate = TRUE,
  ...,
  .f = piecepackr::grid.piece,
  cfg = NULL,
  envir = NULL,
  n_transitions = 0L,
  n_pauses = 1L,
  fps = n_transitions + n_pauses,
  width = NULL,
  height = NULL,
  ppi = NULL,
  new_device = TRUE,
  annotation_scale = NULL
)

Arguments

game

A list containing a parsed ppn game (as parsed by read_ppn())

file

Filename to save animation unless NULL in which case it uses the current graphics device.

annotate

If TRUE or "algebraic" annotate the plot with “algrebraic” coordinates, if FALSE or "none" don't annotate, if "cartesian" annotate the plot with “cartesian” coordinates.

...

Arguments to pmap_piece

.f

Low level graphics function to use e.g. grid.piece(), piece3d(), piece(), or piece_mesh().

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 file is NULL should we open up a new graphics device?

annotation_scale

Multiplicative factor that scales (stretches) any annotation coordinates. By default uses attr(df, "scale_factor") %||% 1.

Value

Nothing, as a side effect saves an animation of ppn game

See Also

piecepackr::animate_piece()

Examples

  game_file <- system.file("ppn/tic-tac-toe.ppn", package = "ppgames")
  game <- read_ppn(game_file)[[1]]
  if (require("gifski")) {
    animate_game(game, file = "tic-tac-toe.gif")
    unlink("tic-tac-toe.gif")
  }

piecepackr/ppgames documentation built on Jan. 17, 2025, 2:24 p.m.