bm_clamp() “clamps” bm_bitmap() integers that lie outside an interval.
The default coerces a multiple-integer-valued bitmap
into a binary bitmap (as expected by most bitmap font formats).
For pixmap objects non-background pixels are all coerced to a single value.
Usage
bm_clamp(x, ...)
# S3 method for class 'bm_bitmap'
bm_clamp(x, lower = 0L, upper = 1L, value = upper, ...)
# S3 method for class 'bm_list'
bm_clamp(x, ...)
# S3 method for class 'bm_pixmap'
bm_clamp(x, value = col2hex("black"), bg = col2hex("transparent"), ...)
# S3 method for class '`magick-image`'
bm_clamp(x, value = "black", bg = "transparent", ...)
# S3 method for class 'nativeRaster'
bm_clamp(x, value = col2int("black"), bg = col2int("transparent"), ...)
# S3 method for class 'raster'
bm_clamp(x, value = "black", bg = "transparent", ...)Arguments
- x
Either a
bm_bitmap(),bm_font(),bm_list(), "magick-image", "nativeRaster",bm_pixmap(), or "raster" object.- ...
Additional arguments to be passed to or from methods.
- lower
Integer value. Any value below
lowerwill be clamped.- upper
Integer value. Any value above
upperwill be clamped.- value
Integer vector of length one or two of replacement value(s). If
valueis length one any values aboveupperare replaced byvaluewhile those belowlowerare replaced bylower. Ifvalueis length two any values aboveupperare replaced byvalue[2]and any values belowlowerare replaced byvalue[1]. For pixmap objects indicate requested non-background color.- bg
Bitmap background value.
Value
Depending on x either a bm_bitmap(), bm_font(), bm_list(), magick-image, "nativeRaster", bm_pixmap(), or raster object.
Examples
plus_sign <- matrix(0L, nrow = 9L, ncol = 9L)
plus_sign[5L, 3:7] <- 2L
plus_sign[3:7, 5L] <- 2L
plus_sign_glyph <- bm_bitmap(plus_sign)
print(plus_sign_glyph)
#> ░░░░░░░░░
#> ░░░░░░░░░
#> ░░░░▒░░░░
#> ░░░░▒░░░░
#> ░░▒▒▒▒▒░░
#> ░░░░▒░░░░
#> ░░░░▒░░░░
#> ░░░░░░░░░
#> ░░░░░░░░░
plus_sign_clamped <- bm_clamp(plus_sign_glyph)
print(plus_sign_clamped)
#> ░░░░░░░░░
#> ░░░░░░░░░
#> ░░░░█░░░░
#> ░░░░█░░░░
#> ░░█████░░
#> ░░░░█░░░░
#> ░░░░█░░░░
#> ░░░░░░░░░
#> ░░░░░░░░░
tulip <- farming_crops_16x16()$tulip$portrait
if (cli::is_utf8_output() && cli::num_ansi_colors() >= 8L) {
print(bm_clamp(tulip, "magenta"), compress = "v")
}
#> ▄▄ ▄███▄ ▄▄
#> ▀█████████▀
#> █████████
#> ███████
#> ▀███▀
#> ▄▄ █
#> ▀███▄██
#> █▀▀