pattern_square: Square pattern matrix

View source: R/pattern_square.R

pattern_squareR Documentation

Square pattern matrix

Description

pattern_square() returns an integer matrix indicating where each color (or other graphical element) should be drawn on a rectangular grid for a specified square pattern type and subtype. names_square lists the currently supported square types (excluding those in names_weave).

Usage

pattern_square(type = "diagonal", subtype = NULL, nrow = 5L, ncol = 5L)

names_square

Arguments

type

Either "diagonal" (default), "diagonal_skew", "horizontal", "vertical", or any type in names_weave. See Details.

subtype

See Details. For "diagonal", "diagonal_skew", "horizontal", or "vertical" an integer of the desired number of colors (or other graphical elements).

nrow

Number of rows (height).

ncol

Number of columns (width).

Format

An object of class character of length 6.

Details

"horizontal", "vertical"

"horizontal" and "vertical" simply cycle through the colors either horizontally or vertically. Use subtype to indicate the (integer) number of colors (or other graphical elements). "horizontal" will produce horizontal stripes of color whereas "vertical" will produce vertical stripes.

"diagonal", "diagonal_skew"

"diagonal" and "diagonal_skew" simply cycle through the colors both horizontally and vertically. Use subtype to indicate the (integer) number of colors (or other graphical elements). If two colors are requested this provides the standard two-color checkerboard pattern. If there are more than three colors than "diagonal" will have colored diagonals going from top left to bottom right while "diagonal_skew" will have them going form bottom left to top right.

"square"

"square" attempts a uniform coloring using "square_tiling" before falling falling back on "diagonal". If subtype is 1L, 2L, 3L, or 4L uses "square_tiling" else uses "diagonal".

"square_tiling"

"square_tiling" supports uniform coloring for (non-staggered) square tilings. Use subtype to either indicate the (integer) number of colors or a string with four integers such as "1231" (will fill in a 2x2 matrix by row which will then be tiled). Supports up to a max of four colors.

any pattern from names_weave

We simply convert the logical matrix returned by pattern_weave() into an integer matrix by having any TRUE set to 1L and FALSE set to 2L. Hence the various weave patterns only support (up to) two-color patterns. See pattern_weave() for more details about supported type and subtype.

Value

A matrix of integer values indicating where the each color (or other graphical element) should be drawn on a rectangular grid. Indices ⁠[1,1]⁠ of the matrix corresponds to the bottom-left of the grid while indices ⁠[1,ncol]⁠ corresponds to the bottom-right of the grid. This matrix has a "pattern_square" subclass which supports a special print() method.

See Also

grid.pattern_regular_polygon() for drawing to a graphics device polygons in multiple color/size/shape patterns. pattern_weave() for more information on "weave" patterns.

Examples

 # supported square names
 print(names_square)

 # (main) diagonal has colors going from top left to bottom right
 diagonal <- pattern_square("diagonal", 4L, nrow = 7L, ncol = 9L)
 print(diagonal)

 # skew diagonal has colors going from bottom left to top right
 skew <- pattern_square("diagonal_skew", 4L, nrow = 7L, ncol = 9L)
 print(skew)

 horizontal <- pattern_square("horizontal", 4L, nrow = 8L, ncol = 8L)
 print(horizontal)

 vertical <- pattern_square("vertical", 4L, nrow = 8L, ncol = 8L)
 print(vertical)

 # uniform coloring using 4 colors
 color4 <- pattern_square("square_tiling", 4L, nrow = 7L, ncol = 9L)
 print(color4)

 # uniform coloring using 3 colors
 color3 <- pattern_square("square_tiling", 3L, nrow = 7L, ncol = 9L)
 print(color3)

 # also supports the various 'weave' patterns
 zigzag <- pattern_square("twill_zigzag", nrow = 15L, ncol = 9L)
 print(zigzag)


gridpattern documentation built on Oct. 26, 2023, 1:07 a.m.