Skip to contents

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 class 'bm_bitmap'
bm_shift(x, value = 0L, top = NULL, right = NULL, bottom = NULL, left = NULL)

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

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

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

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

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

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.

Value

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

Details

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

See also

Examples

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))
#>    top  right bottom   left 
#>      2      2      2      1 
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")
}
#>          
#>        
#>      
#>    
#> ▀▀▀    
#>       ▀▀    
#>                 
#>