| render_piece {piecepackr} | R Documentation | 
Render image of game pieces
Description
render_piece() renders an image of game pieces to a file or graphics device.
It is a wrapper around pmap_piece() that can auto-size files and graphic devices,
apply axes offsets, annotate coordinates, and set up rayrender / rayvertex scenes.
Usage
render_piece(
  df,
  file = NULL,
  ...,
  .f = piecepackr::grid.piece,
  cfg = getOption("piecepackr.cfg", NULL),
  envir = getOption("piecepackr.envir", game_systems("sans")),
  width = NULL,
  height = NULL,
  ppi = 72,
  bg = "white",
  xoffset = NULL,
  yoffset = NULL,
  new_device = TRUE,
  dev = NULL,
  dev.args = list(res = ppi, bg = bg, units = "in"),
  annotate = FALSE,
  annotation_scale = NULL
)
Arguments
| df | A data frame of game piece information with (at least) the named columns “piece_side”, “x”, and “y”. | 
| file | Filename to save image unless  | 
| ... | Arguments to  | 
| .f | Low level graphics function to use e.g.  | 
| cfg | A piecepackr configuration list | 
| envir | Environment (or named list) of piecepackr configuration lists | 
| width | Width of image (in inches). Inferred by default. | 
| height | Height of image (in inches). Inferred by default. | 
| ppi | Resolution of image in pixels per inch. | 
| bg | Background color (use  | 
| xoffset | Number to add to the  | 
| yoffset | Number to add to the  | 
| new_device | If  | 
| dev | Graphics device function to use.  If  | 
| dev.args | Additional arguments to pass to  | 
| annotate | If  | 
| annotation_scale | Multiplicative factor that scales (stretches) any annotation coordinates.
By default uses  | 
Value
An invisible list of the dimensions of the image, as a side effect saves a graphic
See Also
This function is a wrapper around pmap_piece().
Examples
 df_board <- data.frame(piece_side = "board_face", suit = 3, rank = 5,
                        x = 3.0, y = 3.0, stringsAsFactors = FALSE)
 df_w <- data.frame(piece_side = "bit_face", suit = 6, rank = 1,
                    x = rep(1:5, 2), y = rep(1:2, each=5),
                    stringsAsFactors = FALSE)
 df_b <- data.frame(piece_side = "bit_face", suit = 1, rank = 1,
                    x = rep(1:5, 2), y = rep(4:5, each=5),
                    stringsAsFactors = FALSE)
 df <- rbind(df_board, df_w, df_b)
 df$cfg <- "checkers1"
 if (requireNamespace("grid", quietly = TRUE)) {
   render_piece(df, new_device = FALSE)
 }
 if (requireNamespace("grid", quietly = TRUE)) {
   grid::grid.newpage()
   render_piece(df, new_device = FALSE,
                op_scale = 0.5, trans = op_transform,
                annotate = "algrebraic")
 }
 ## Not run: # May take more than 5 seconds on CRAN servers
 if (require(rayvertex)) {
   envir3d <- game_systems("sans3d")
   render_piece(df, .f = piece_mesh, envir = envir3d,
                op_scale = 0.5, trans = op_transform)
 }
 
## End(Not run)