Learn R Programming

bittermelon (version 2.2.1)

bm_shift: Shift elements within bitmaps

Description

Shifts non-padding elements within bitmaps by trimming on a specified side and padding on the other while preserving the width and height of the original bitmap.

Usage

bm_shift(x, value, top = NULL, right = NULL, bottom = NULL, left = NULL)

# S3 method for bm_bitmap bm_shift(x, value = 0L, top = NULL, right = NULL, bottom = NULL, left = NULL)

# S3 method for bm_list bm_shift(x, ...)

# S3 method for bm_pixmap bm_shift( x, value = col2hex("transparent"), top = NULL, right = NULL, bottom = NULL, left = NULL )

# S3 method for `magick-image` bm_shift( x, value = "transparent", top = NULL, right = NULL, bottom = NULL, left = NULL )

# S3 method for nativeRaster bm_shift( x, value = col2int("transparent"), top = NULL, right = NULL, bottom = NULL, left = NULL )

# S3 method for raster bm_shift( x, value = "transparent", top = NULL, right = NULL, bottom = NULL, left = NULL )

Value

Depending on x either a bm_bitmap(), bm_font(), bm_list(), magick-image, "nativeRaster", bm_pixmap(), or raster object.

Arguments

x

Either a bm_bitmap(), bm_font(), bm_list(), "magick-image", "nativeRaster", bm_pixmap(), or "raster" object.

value

Value for the new pixels.

top

Number of pixels to shift towards the top side.

right

Number of pixels to shift towards the right side.

bottom

Number of pixels to shift towards the bottom side.

left

Number of pixels to shift towards the left side.

...

Additional arguments to be passed to or from methods.

Details

This function is a convenience wrapper around bm_trim() and bm_extend().

See Also

bm_trim() and bm_extend()

Examples

Run this code
font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
font <- read_hex(font_file)
capital_r <- font[[str2ucp("R")]]
print(capital_r)
capital_r <- bm_shift(capital_r, bottom = 2L, right = 1L)
print(capital_r)
corn <- farming_crops_16x16()$corn$portrait
print(bm_padding_lengths(corn))
corn_shifted <- bm_shift(corn, left = 1L, top = 2L)
if (cli::is_utf8_output() && cli::num_ansi_colors() >= 256L) {
  print(corn_shifted, bg = "cyan", compress = "v")
}

Run the code above in your browser using DataLab