Open trevorld opened 6 months ago
Wow, thanks for sharing, this is so cool!
It looks a little different for me in R Studio and I'm not sure why I'm getting the gaps between lines:
But I still like this much better than the default (which is just a matrix and not even visually recognizable as a maze, aside from the extra attr(,"class")
/ [1] "maze"
at the end).
I think I'll plan on adding bittermelon
to Suggests
and implementing the print method like this, so that it still does something if users don't have the right version:
print.maze <- function(x, ..., walls = FALSE, start = NULL, end = NULL) {
if(requireNamespace("bittermelon", quietly = TRUE) &&
packageVersion("bittermelon") >= "1.2.0-2"){
bm <- bittermelon::as_bm_bitmap(x, walls = walls, start = start, end = end)
print(bm, ...)
}else{
print.default(x)
}
}
Thanks again, this is great!
Cool!
It looks a little different for me in R Studio and I'm not sure why I'm getting the gaps between lines
You need the line spacing (often called line height) to be set to 1 for it to look good. I usually work in a Linux terminal where this is the default but it looks like RStudio sets this higher by default in their Console. I notice that the help for cli::boxx()
singles out RStudio for doing this but doesn't mention a fix.
Theoretically I think you can customize this but after a couple minutes searching couldn't find an example of someone actually doing this for the RStudio console (there is an example of doing it for the editor). The relevant CSS property is line-height
.
compress
argument to be ifelse(is.null(start), "vertical", "none")
instead of always "vertical"
. I don't think {bittermelon} currently has a good solution to distinctly display maze walls, paths, and solutions with a "vertical" compression.cli::is_utf8_output()
. Second best way is with l10n_info()[["UTF-8"]]
. With {bittermelon}
v1.2.0-3 by default will switch to ASCII characters if cli::is_utf8_output()
is FALSE
. A user can force this with options(cli.unicode = FALSE)
.by
argument in solve_maze()
from #4 is accepted {bittermelon}
should be able to improve the printing of maze solutions by using the new by = 0.5
option.Experimentally using the proposed new by = 0.5
parameter for solve_maze()
gives the following (non-compressed) output for maze solutions in my terminal:
{bittermelon}
v2.0.2 has just been published to CRAN.
Currently {bittermelon}
manually implements the proposed solve_maze(x, by = 0.5)
approach to help pretty print maze solutions.solve
argument to as_bm_bitmap.maze()
and as_bm_pixmap.maze()
that defaults to !is.null(start) && !is.null(end)
that lets you distinguish a maze solution path from its start/end (which aren't distinguished)as_bm_bitmap()
with compress = "none"
will continue to be most robust strategy that will gracefully degrade if a user lacks Unicode glyphs and or ASCII color code supportcli::is_utf8_output()
) and ASCII color codes (i.e. cli::num_ansi_colors() >= 256L
) then we can now pretty print mazes with solutions with the new as_bm_pixmap()
method and the new "bm_pixmap" classes print method:set.seed(42)
m <- mazing::maze(16L, 32L)
pal <- grDevices::palette.colors()
m |> as_bm_pixmap(start = "top", end = "bottom",
col = c(pal[6L], "white", pal[7L], pal[5L])) |>
bm_pad(sides = 1L) |>
print(compress = "vertical")
{bittermelon}
recently added anas_bm_bitmap.maze()
S3 method.{bittermelon}
to{mazing}
'sImports
orSuggests
fields but if you do you could add aprint.maze()
method to print{mazing}
mazes in the terminal.{mazing}
'splot.maze()
method (i.e. flip the matrices to "plot" in similar ways)