pp_shape()
creates an R6 object with methods for creating various shape based grobs.
pp_shape(label = "rect", theta = 90, radius = 0.2, back = FALSE)
label | Label of the shape. One of
|
---|---|
theta |
|
radius |
|
back | Whether the shape should be reflected across a vertical line in the middle of the viewport. |
pp_shape
objects serve the following purposes:
Make it easier for developers to customize game piece appearances
either through a "grob_fn" or "op_grob_fn" styles in pp_cfg()
or manipulate a piece post drawing via functions like grid::grid.edit()
.
Used internally to generate piecepackr
's built-in game piece grobs.
pp_shape
R6 Class Method Argumentsmat_width
Numeric vector of mat widths.
clip
“clip grob” to perform polyclip operation with.
See grid.polyclip
for more info.
op
Polyclip operation to perform.
See grid.polyclip
for more info.
name
Grid grob name
value.
gp
Grid gpar
list. See gpar
for more info.
vp
Grid viewport or NULL
.
pp_shape
R6 Class Methodscheckers(name = NULL, gp = gpar(), vp = NULL)
Returns a grob of checkers for that shape.
gridlines(name = NULL, gp = gpar(), vp = NULL)
Returns a grob of gridlines for that shape.
hexlines(name = NULL, gp = gpar(), vp = NULL)
Returns a grob of hexlines for that shape.
mat(mat_width = 0, name = NULL, gp = gpar(), vp = NULL)
Returns a grob for a matting “mat” for that shape.
polyclip(clip, op = "intersection", name = NULL, gp = gpar(), vp = NULL)
Returns a grob that is an “intersection”, “minus”, “union”, or “xor” of another grob.
Note unlike gridGeometry::polyclipGrob
it can directly work with a pieceGrob
"clip grob" argument.
shape(name = NULL, gp = gpar(), vp = NULL)
Returns a grob of the shape.
pp_shape
R6 Class Active Bindingslabel
The shape's label.
theta
The shape's theta.
radius
The shape's radius.
back
A boolean of whether this is the shape's “back” side.
npc_coords
A named list of “npc” coordinates along the perimeter of the shape.
if (require("grid")) { gp <- gpar(col="black", fill="yellow") rect <- pp_shape(label="rect") convex6 <- pp_shape(label="convex6") circle <- pp_shape(label="circle") pushViewport(viewport(x=0.25, y=0.75, width=1/2, height=1/2)) grid.draw(rect$shape(gp=gp)) grid.draw(rect$gridlines(gp=gpar(col="blue", lex=4))) grid.draw(rect$hexlines(gp=gpar(col="green"))) popViewport() pushViewport(viewport(x=0.75, y=0.75, width=1/2, height=1/2)) grid.draw(convex6$shape(gp=gp)) grid.draw(convex6$checkers(gp=gpar(fill="blue"))) popViewport() pushViewport(viewport(x=0.25, y=0.25, width=1/2, height=1/2)) grid.draw(circle$shape(gp=gp)) grid.draw(circle$mat(mat_width=0.2, gp=gpar(fill="blue"))) popViewport() pushViewport(viewport(x=0.75, y=0.25, width=1/2, height=1/2)) grid.draw(rect$shape(gp=gp)) grid.draw(rect$mat(mat_width=c(0.2, 0.1, 0.3, 0.4), gp=gpar(fill="blue"))) popViewport() grid.newpage() gp <- gpar(col="black", fill="yellow") vp <- viewport(x=1/4, y=1/4, width=1/2, height=1/2) grid.draw(pp_shape("halma")$shape(gp=gp, vp=vp)) vp <- viewport(x=3/4, y=1/4, width=1/2, height=1/2) grid.draw(pp_shape("pyramid")$shape(gp=gp, vp=vp)) vp <- viewport(x=3/4, y=3/4, width=1/2, height=1/2) grid.draw(pp_shape("kite")$shape(gp=gp, vp=vp)) vp <- viewport(x=1/4, y=3/4, width=1/2, height=1/2) grid.draw(pp_shape("meeple")$shape(gp=gp, vp=vp)) grid.newpage() vp <- viewport(x=1/4, y=1/4, width=1/2, height=1/2) grid.draw(pp_shape("convex3", 0)$shape(gp=gp, vp=vp)) vp <- viewport(x=3/4, y=1/4, width=1/2, height=1/2) grid.draw(pp_shape("convex4", 90)$shape(gp=gp, vp=vp)) vp <- viewport(x=3/4, y=3/4, width=1/2, height=1/2) grid.draw(pp_shape("convex5", 180)$shape(gp=gp, vp=vp)) vp <- viewport(x=1/4, y=3/4, width=1/2, height=1/2) grid.draw(pp_shape("convex6", 270)$shape(gp=gp, vp=vp)) grid.newpage() vp <- viewport(x=1/4, y=1/4, width=1/2, height=1/2) grid.draw(pp_shape("concave3", 0, 0.1)$shape(gp=gp, vp=vp)) vp <- viewport(x=3/4, y=1/4, width=1/2, height=1/2) grid.draw(pp_shape("concave4", 90, 0.2)$shape(gp=gp, vp=vp)) vp <- viewport(x=3/4, y=3/4, width=1/2, height=1/2) grid.draw(pp_shape("concave5", 180, 0.3)$shape(gp=gp, vp=vp)) vp <- viewport(x=1/4, y=3/4, width=1/2, height=1/2) grid.draw(pp_shape("concave6", 270)$shape(gp=gp, vp=vp)) }