Open trevorld opened 1 month ago
Another possibly useful S3 method:
as.raster.pixeltrix <- function(x, ..., colours = attr(x, "colours")) {
if (nrow(x) > 0L && ncol(x) > 0L) {
cols <- as.character(colours)[as.integer(x) + 1L]
m <- matrix(cols, nrow = nrow(x), ncol = ncol(x))
as.raster(m)
} else {
as.raster(matrix(character(0L), nrow = nrow(x), ncol = ncol(x)))
}
}
In particular this should let {magick}
auto-import {pixeltrix}
sprites using magick::image_read()
and you can use grid::grid.raster(x, interpolate = FALSE)
and rasterGrob(x, interpolate = FALSE)
as an alternative for graphics...
as_pixeltrix()
becomes an S3 genericas_pixeltrix.matrix()
adds an optionalcolours
argument.Suggests
(you already use the core{grDevices}
elsewhere):