basicPieceGrobs: Piece Grob Functions

Description Usage Arguments Examples

Description

basicPieceGrob, pyramidTopGrob, and previewLayoutGrob are the default “grob” functions 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

1
2
3
4
5
6
7
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 is_mac <- tolower(Sys.info()[["sysname"]]) == "darwin"
 if (require("grid") && capabilities("cairo") && !is_mac) {
    cfg <- pp_cfg(list(invert_colors=TRUE))

    pushViewport(viewport(width=unit(2, "in"), height=unit(2, "in")))
    grid.draw(basicPieceGrob("tile_face", suit=1, rank=3))
    popViewport()

    grid.newpage()
    pushViewport(viewport(width=unit(0.75, "in"), height=unit(0.75, "in")))
    grid.draw(basicPieceGrob("coin_back", suit=2, rank=0, cfg=cfg))
    popViewport()

    grid.newpage()
    pushViewport(viewport(width=unit(6, "in"), height=unit(6, "in")))
    grid.draw(previewLayoutGrob("preview_layout", suit=5, rank=0, cfg=cfg))
    popViewport()

    grid.newpage()
    pushViewport(viewport(width=unit(0.75, "in"), height=unit(0.75, "in")))
    grid.draw(pyramidTopGrob("pyramid_top", suit=3, rank=5))
    popViewport()

    
        directory <- tempdir()
        save_piece_images(cfg, directory=directory, format="svg", angle=0)
        cfg2 <- pp_cfg(list(grob_fn=picturePieceGrobFn(directory)))

        grid.newpage()
        pushViewport(viewport(width=unit(0.75, "in"), height=unit(0.75, "in")))
        grid.draw(pyramidTopGrob("pyramid_top", suit=3, rank=5, cfg=cfg2))
        popViewport()
    
 }

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