Cast bitmap/pixmap objects to a (normal) matrix
Source:R/as.matrix.bm_matrix.R
as.matrix.bm_matrix.Rdas.matrix.bm_matrix() casts bm_bitmap() objects to a (normal) integer matrix
and bm_pixmap() objects to a (normal) character matrix (of color strings).
Note unless first_row_is_top = TRUE the bottom left pixel will still be
represented by the pixel in the first row and first column
(i.e. these methods simply remove the class names).
Usage
# S3 method for class 'bm_matrix'
as.matrix(x, first_row_is_top = FALSE, ...)Arguments
- x
Either a
bm_bitmap()orbm_pixmap()object.- first_row_is_top
If
TRUEthe first row of the matrix will represent the top of the bitmap (likegrDevices::as.raster()objects). IfFALSEthe first row of the matrix will represent the bottom of the bitmap (likebm_bitmap()andbm_pixmap()objects).- ...
Currently ignored.
Value
Either an integer matrix if x is a bm_bitmap() object
or a character matrix if x is a bm_pixmap() object.
Examples
space_matrix <- matrix(0L, ncol = 8L, nrow = 8L)
space_glyph <- bm_bitmap(space_matrix)
print(space_glyph, px = ".")
#> ........
#> ........
#> ........
#> ........
#> ........
#> ........
#> ........
#> ........
print(as.matrix(space_glyph))
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 0 0 0 0 0 0 0 0
#> [2,] 0 0 0 0 0 0 0 0
#> [3,] 0 0 0 0 0 0 0 0
#> [4,] 0 0 0 0 0 0 0 0
#> [5,] 0 0 0 0 0 0 0 0
#> [6,] 0 0 0 0 0 0 0 0
#> [7,] 0 0 0 0 0 0 0 0
#> [8,] 0 0 0 0 0 0 0 0