render_piece: Render image of game pieces

Description Usage Arguments Value See Also Examples

View source: R/render_piece.R

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 scenes.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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 animation unless NULL in which case it either uses the current graphics device or opens a new device (depending on new_device argument).

...

Arguments to pmap_piece()

.f

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

cfg

A piecepackr configuration list

envir

Environment (or named list) of piecepackr configuration lists

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.

bg

Background color (use "transparent" for transparent)

xoffset

Number to add to the x column in df. Inferred by default.

yoffset

Number to add to the y column in df. Inferred by default.

new_device

If file is NULL should we open up a new graphics device?

dev

Graphics device function to use. If NULL infer a reasonable choice.

dev.args

Additional arguments to pass to dev (besides filename, width, and height). Will filter out any names that aren't in formals(dev).

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.

annotation_scale

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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 df_board <- data.frame(piece_side = "board_face", suit = 3, rank = 8,
                        x = 4.5, y = 4.5, stringsAsFactors = FALSE)
 df_w <- data.frame(piece_side = "bit_face", suit = 6, rank = 1,
                    x = rep(1:8, 2), y = rep(1:2, each=8),
                    stringsAsFactors = FALSE)
 df_b <- data.frame(piece_side = "bit_face", suit = 1, rank = 1,
                    x = rep(1:8, 2), y = rep(7:8, each=8),
                    stringsAsFactors = FALSE)
 df <- rbind(df_board, df_w, df_b)
 df$cfg <- "checkers1"

 render_piece(df)
 render_piece(df, op_scale = 0.5, trans = op_transform, annotate = "algrebraic")
 ## Not run:  # Takes a while to render
 if (require(rayrender)) {
   envir3d <- game_systems("sans3d")
   render_piece(df, .f = piece, envir = envir3d,
                op_scale = 0.5, trans = op_transform,
                samples = 300, clamp_value = 1)
 }
 
## End(Not run)

trevorld/piecepack documentation built on July 22, 2021, 3:26 a.m.