Learn R Programming

bittermelon (version 2.2.1)

as_bm_pixmap: Cast to a pixmap matrix object

Description

as_bm_pixmap() casts an object to a [bm_pixmap()] object.

Usage

as_bm_pixmap(x, ...)

# S3 method for default as_bm_pixmap(x, ...)

# S3 method for array as_bm_pixmap(x, ...)

# S3 method for bm_bitmap as_bm_pixmap(x, ..., col = getOption("bittermelon.col", col_bitmap))

# S3 method for bm_pixmap as_bm_pixmap(x, ...)

# S3 method for glyph_bitmap as_bm_pixmap(x, ..., col = getOption("bittermelon.col", col_bitmap))

# S3 method for grob as_bm_pixmap(x, ..., width = 16L, height = 16L, png_device = NULL)

# S3 method for `lofi-matrix` as_bm_pixmap(x, ..., col = getOption("bittermelon.col", col_bitmap))

# S3 method for `magick-image` as_bm_pixmap(x, ...)

# S3 method for matrix as_bm_pixmap(x, ...)

# S3 method for maze as_bm_pixmap( x, ..., walls = FALSE, start = NULL, end = NULL, solve = !is.null(start) && !is.null(end), col = getOption("bittermelon.col", col_bitmap) )

# S3 method for pattern_square as_bm_pixmap(x, ..., col = getOption("bittermelon.col", col_bitmap))

# S3 method for pattern_weave as_bm_pixmap(x, ..., col = getOption("bittermelon.col", col_bitmap))

# S3 method for pixmapGrey as_bm_pixmap(x, ...)

# S3 method for pixmapIndexed as_bm_pixmap(x, ...)

# S3 method for pixmapRGB as_bm_pixmap(x, ...)

# S3 method for nativeRaster as_bm_pixmap(x, ...)

# S3 method for pixeltrix as_bm_pixmap(x, ...)

# S3 method for raster as_bm_pixmap(x, ...)

Value

A bm_pixmap() object.

Arguments

x

an Object

...

Potentially passed to other methods e.g. as_bm_pixmap.default() passes ... to as.raster().

col

Character vector of R color specifications.

width

Desired width of bitmap

height

Desired height of bitmap

png_device

A function taking arguments filename, width, and height that starts a graphics device that saves a png image with a transparent background. By default will use ragg::agg_png() if available else the “cairo” version of grDevices::png() if available else just grDevices::png().

walls

If TRUE the values of 1L denote the walls and the values of 0L denote the paths.

start, end

If not NULL mark the start and end as value 2L. See mazing::find_maze_refpoint().

solve

If TRUE then mark the solution path from start to end as value 3L. See mazing::solve_maze().

See Also

bm_pixmap(), is_bm_pixmap()

Examples

Run this code
crops <- farming_crops_16x16()
corn <- crops$corn$portrait
is_bm_pixmap(corn)
all.equal(corn, as_bm_pixmap(as.array(corn)))
all.equal(corn, as_bm_pixmap(as.raster(corn)))
if (requireNamespace("farver", quietly = TRUE)) {
  all.equal(corn, as_bm_pixmap(as.raster(corn, native = TRUE)))
}
if (requireNamespace("magick", quietly = TRUE)) {
  all.equal(corn, as_bm_pixmap(magick::image_read(corn)))
}

if (requireNamespace("mazing", quietly = TRUE) &&
    cli::is_utf8_output() &&
    cli::num_ansi_colors() >= 8L) {
  pal <- grDevices::palette.colors()
  pm <- as_bm_pixmap(mazing::maze(24L, 32L),
                     start = "top", end = "bottom",
                     col = c(pal[6], "white", pal[7], pal[5]))
  pm <- bm_pad(pm, sides = 1L)
  print(pm, compress = "v", bg = "white")
}
if (requireNamespace("gridpattern", quietly = TRUE) &&
    cli::is_utf8_output() &&
    cli::num_ansi_colors() >= 256L) {
  s <- gridpattern::pattern_square(subtype = 8L, nrow = 8L, ncol = 50L)
  pm <- as_bm_pixmap(s, col = grDevices::rainbow(8L))
  print(pm, compress = "vertical")
}

Run the code above in your browser using DataLab