matt-dray / pixeltrix

:space_invader::computer_mouse: R package: make pixel art interactively in a plot window, get a matrix, make a gif
Other
21 stars 0 forks source link

Add class name to {pixeltrix} sprite objects #36

Closed trevorld closed 1 month ago

trevorld commented 1 month ago

In particular in the not too distant future {bittermelon} will be getting the ability to print sprites to the R terminal and it would be nice to be able to more easily write an as_bm_pixmap() S3 method for {pixeltrix} sprites in order to print/play with them too:

Screenshot from 2024-05-29 21-52-18

matt-dray commented 1 month ago

Thanks for the suggestion. {bittermelon} looks great and I look forward to its expansion.

trevorld commented 1 month ago

Awesome, thanks! Conversion from {pixeltrix} to {bittermelon} seems to be working now in https://github.com/trevorld/bittermelon/pull/65

library("bittermelon")
library("hexfont")
library("pixeltrix")
font <- hexfont::unifont(ucp = str2ucp("🐉"))
dragon <- as_bm_bitmap("🐉", font = font) |> 
    bm_glow() |>
    bm_extend(sides = 1L)
pt <- as.matrix(dragon, first_row_is_top = TRUE) |> 
    as_pixeltrix()
# class(pt)
# draw_pixels(pt)
pm <- as_bm_pixmap(pt)
print(pm, compress = "v")

image