basicPieceGrobs: Piece Grob Functions

basicPieceGrobsR Documentation

Piece Grob Functions

Description

basicPieceGrob is the most common “grob” function that grid.piece uses to create grid graphical grob objects. picturePieceGrobFn is a function that returns a “grob” function that imports graphics from files found in its directory argument.

Usage

basicPieceGrob(piece_side, suit, rank, cfg = pp_cfg())

picturePieceGrobFn(directory, filename_fn = find_pp_file)

pyramidTopGrob(piece_side, suit, rank, cfg = pp_cfg())

previewLayoutGrob(piece_side, suit, rank, cfg = pp_cfg())

Arguments

piece_side

A string with piece and side separated by a underscore e.g. "coin_face"

suit

Number of suit (starting from 1).

rank

Number of rank (starting from 1)

cfg

Piecepack configuration list or pp_cfg object.

directory

Directory that picturePieceGrobFn will look in for piece graphics.

filename_fn

Function that takes arguments directory, piece_side, suit, rank, and optionally cfg and returns the (full path) filename of the image that the function returned by picturePieceGrobFn should import.

Examples


 if (requireNamespace("grid", quietly = TRUE) && piecepackr:::device_supports_unicode()) {
   cfg <- pp_cfg(list(grob_fn.tile=basicPieceGrob, invert_colors=TRUE))
   grid.piece("tile_face", suit=1, rank=3, cfg=cfg)
 }

 # May take more than 5 seconds on CRAN servers
 try({
   if (requireNamespace("grid", quietly = TRUE) && capabilities(c("cairo"))) {
     cfg <- pp_cfg(list(grob_fn.tile=basicPieceGrob, invert_colors=TRUE))
     directory <- tempdir()
     save_piece_images(cfg, directory=directory, format="svg", angle=0)
     cfg2 <- pp_cfg(list(grob_fn=picturePieceGrobFn(directory)))

     grid::grid.newpage()
     grid.piece("coin_back", suit=3, rank=5, cfg=cfg2)
   }
 })
 

piecepackr documentation built on Sept. 11, 2024, 9:09 p.m.