bm_flip() flips (reflects) bitmaps horizontally, vertically, or both.
It can flip the entire bitmap or just the glyph in place.
Usage
bm_flip(x, direction = "vertical", in_place = FALSE, value)
# S3 method for class 'bm_bitmap'
bm_flip(x, direction = "vertical", in_place = FALSE, value = 0L)
# S3 method for class 'bm_list'
bm_flip(x, ...)
# S3 method for class 'bm_pixmap'
bm_flip(
x,
direction = "vertical",
in_place = FALSE,
value = col2hex("transparent")
)
# S3 method for class '`magick-image`'
bm_flip(x, direction = "vertical", in_place = FALSE, value = "transparent")
# S3 method for class 'nativeRaster'
bm_flip(
x,
direction = "vertical",
in_place = FALSE,
value = col2int("transparent")
)
# S3 method for class 'raster'
bm_flip(x, direction = "vertical", in_place = FALSE, value = "transparent")Arguments
- x
Either a
bm_bitmap(),bm_font(),bm_list(), "magick-image", "nativeRaster",bm_pixmap(), or "raster" object.- direction
Either "vertical" or "v", "horizontal" or "h", OR "both" or "b".
- in_place
If
TRUEflip the glyphs in place (without changing any background padding).- value
Background padding value (to use if
in_placeisTRUE)- ...
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.
Examples
font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
font <- read_hex(font_file)
# Print upside down
bml <- as_bm_list("RSTATS", font = font)
bml <- bm_flip(bml, "both")
bm <- bm_call(bml, cbind, direction = "RTL")
print(bm)
#> ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
#> ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
#> ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
#> ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
#> ░░██████░░░██░░░░██░░░██░░░██░░░░░██████░██░░░██
#> ░██░░░░░░░░██░░░░██░░░██░░░██░░░░██░░░░░░██░░░██
#> ░██░░░░░░░░██░░░░██░░░██░░░██░░░░██░░░░░░██░░░██
#> ░██░░░░░░░░██░░░░██░░░██░░░██░░░░██░░░░░░██░░░██
#> ░██░░░░░░░░██░░░░██░░░██░░░██░░░░██░░░░░░██░░░██
#> ░░█████░░░░██░░░░███████░░░██░░░░░█████░░░██████
#> ░░░░░░██░░░██░░░░██░░░██░░░██░░░░░░░░░██░██░░░██
#> ░░░░░░██░░░██░░░░██░░░██░░░██░░░░░░░░░██░██░░░██
#> ░░░░░░██░░░██░░░░██░░░██░░░██░░░░░░░░░██░██░░░██
#> ░██████░████████░░█████░████████░██████░░░██████
#> ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
#> ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
# Can also modify glyphs "in place"
exclamation <- font[[str2ucp("!")]]
exclamation_flipped <- bm_flip(exclamation, in_place = TRUE)
print(exclamation_flipped)
#> ░░░░░░░░
#> ░░░░░░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░░░░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░██░░░
#> ░░░░░░░░
#> ░░░░░░░░
#> ░░░░░░░░
#> ░░░░░░░░
crops <- farming_crops_16x16()
corn <- crops$corn$portrait
corn_fh <- bm_flip(corn, "h")
if (cli::is_utf8_output() && cli::num_ansi_colors() >= 256L) {
print(corn_fh, compress = "v")
}
#>
#> █▀▄▄▀▀▄
#> ▄▀▀█▀▀▀▀█
#> ▄▀▀▀█▀█▀▀▀▄
#> ████▀▀▀▀█▀▀▀▄
#> ██▀▀▀▀▀▀▀ ▀▀▀
#> ▀▀▀▀▀▀
#>