suppressPackageStartupMessages({ library(dplyr) library(magick) library(nonogram) }) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 7, fig.height=6 )
To make, print and solve your own nonograms, you just need to create a puzzle string.
The puzzle string
format used to define puzzles is quite simple:
puzzle_string <- "3:1:1,1-3:1:1,1" solution <- solve_puzzle(puzzle_string) create_puzzle_plot(puzzle_string, solution)
library(magick) im <- magick::image_read(system.file("img", "Rlogo.jpg", package="jpeg")) im <- im %>% image_quantize(max=2, colorspace = 'gray', dither=TRUE) %>% image_scale(geometry = geometry_size_pixels(width=25, height=20, preserve_aspect=FALSE)) im
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Manipulating the image data to to matrix and then threshold, invert + tranpose #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mat <- t(1L - 1L * (im[[1]][1,,] > 180)) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # nonogram has a method for plotting a matrix in a standard way #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ nonogram::create_matrix_plot(mat)
Puzzles in nonogram
are represented in 2 ways:
puzzles
- list objects with vectors of clues for each row and each columnpuzzle_strings
- compact character representations of the puzzles:
-
puzzle <- create_puzzle_from_matrix(mat) puzzle_string <- convert_puzzle_to_puzzle_string(puzzle)
cat("> puzzle") deparse(puzzle) %>% paste(collapse="\n") %>% cat() cat('> puzzle_string') strwrap(puzzle_string, width = 60) %>% cat
create_puzzle_plot(puzzle, mat, show_clues=TRUE)
create_puzzle_plot(puzzle, show_clues=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.