Skip to contents

bm_rotate() losslessly rotates bitmaps by 0, 90, 180, or 270 degrees. If 90 or 270 degrees are indicated the width and height of the bitmap will be flipped unless in_place is TRUE.

Usage

bm_rotate(x, angle = 0L, clockwise = TRUE, in_place = FALSE, value)

# S3 method for class 'bm_bitmap'
bm_rotate(x, angle = 0L, clockwise = TRUE, in_place = FALSE, value = 0L)

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

# S3 method for class 'bm_pixmap'
bm_rotate(
  x,
  angle = 0L,
  clockwise = TRUE,
  in_place = FALSE,
  value = col2hex("transparent")
)

# S3 method for class '`magick-image`'
bm_rotate(
  x,
  angle = 0L,
  clockwise = TRUE,
  in_place = FALSE,
  value = "transparent"
)

# S3 method for class 'nativeRaster'
bm_rotate(
  x,
  angle = 0L,
  clockwise = TRUE,
  in_place = FALSE,
  value = col2int("transparent")
)

# S3 method for class 'raster'
bm_rotate(
  x,
  angle = 0L,
  clockwise = TRUE,
  in_place = FALSE,
  value = "transparent"
)

Arguments

x

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

angle

Angle to rotate bitmap by.

clockwise

If TRUE rotate bitmaps clockwise. Note Unicode's convention is to rotate glyphs clockwise i.e. the top of the "BLACK CHESS PAWN ROTATED NINETY DEGREES" glyph points right.

in_place

If TRUE rotate the glyphs in place (without changing any background padding).

value

Background padding value (to use if in_place is TRUE)

...

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.

See also

bm_distort() can do other (distorted) rotations by careful use of its vp grid::viewport() argument.

Examples

# as_bm_list.character()
font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
font <- read_hex(font_file)
capital_r <- font[[str2ucp("R")]]
print(bm_rotate(capital_r, 90))
#> ░░░░██████████░░
#> ░░░░██████████░░
#> ░░░░░░░░░█░░░█░░
#> ░░░░░░░░░█░░░█░░
#> ░░░░░░░░░█░░░█░░
#> ░░░░██████████░░
#> ░░░░█████░███░░░
#> ░░░░░░░░░░░░░░░░
print(bm_rotate(capital_r, 180))
#> ░░░░░░░░
#> ░░░░░░░░
#> ░░░░░░░░
#> ░░░░░░░░
#> ░██░░░██
#> ░██░░░██
#> ░██░░░██
#> ░██░░░██
#> ░██░░░██
#> ░░██████
#> ░██░░░██
#> ░██░░░██
#> ░██░░░██
#> ░░██████
#> ░░░░░░░░
#> ░░░░░░░░
print(bm_rotate(capital_r, 270))
#> ░░░░░░░░░░░░░░░░
#> ░░░███░█████░░░░
#> ░░██████████░░░░
#> ░░█░░░█░░░░░░░░░
#> ░░█░░░█░░░░░░░░░
#> ░░█░░░█░░░░░░░░░
#> ░░██████████░░░░
#> ░░██████████░░░░
print(bm_rotate(capital_r, 90, clockwise = FALSE))
#> ░░░░░░░░░░░░░░░░
#> ░░░███░█████░░░░
#> ░░██████████░░░░
#> ░░█░░░█░░░░░░░░░
#> ░░█░░░█░░░░░░░░░
#> ░░█░░░█░░░░░░░░░
#> ░░██████████░░░░
#> ░░██████████░░░░

corn <- farming_crops_16x16()$corn$portrait
corn_180 <- bm_rotate(corn, 180)
if (cli::is_utf8_output() && cli::num_ansi_colors() >= 256L) {
  print(corn_180, compress = "v")
}
#>                 
#>    ▀▀       
#>    ▄▄▄ 
#>    
#>      
#>        
#>          
#>