Title: | Make ASCII Art From Images |
---|---|
Description: | Takes an arbitrary image as input and constructs an text-based approximation to the image using the imager package. |
Authors: | Danielle Navarro [aut, cre] |
Maintainer: | Danielle Navarro <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-10-28 05:35:59 UTC |
Source: | https://github.com/djnavarro/asciify |
Specifies path to one of the data files in the package
ascii_data(file)
ascii_data(file)
file |
Name of file as a character string |
This is a convenience function that returns the path to one of the external data files bundled in the asciify package. There are only four such files: "bayes.png", "unicorn.png", "heart.jpg", "rain.html"
Path to file as a character string
ascii_data("bayes.png") ascii_data("unicorn.png") ascii_data("heart.jpg") ascii_data("rain.html")
ascii_data("bayes.png") ascii_data("unicorn.png") ascii_data("heart.jpg") ascii_data("rain.html")
Converts an ASCII map to a matrix
ascii_grid(image_map)
ascii_grid(image_map)
image_map |
Map from ascii_map |
A matrix
bayes_img <- ascii_data("bayes.png") # path to the bayes image bayes_map <- ascii_map(bayes_img) # construct ASCII map bayes_grid <- ascii_grid(bayes_map) # make grid
bayes_img <- ascii_data("bayes.png") # path to the bayes image bayes_map <- ascii_map(bayes_img) # construct ASCII map bayes_grid <- ascii_grid(bayes_map) # make grid
Creates ASCII art from an image
ascii_map(file, alphabet = letters, rescale = NULL, threshold = 0.5)
ascii_map(file, alphabet = letters, rescale = NULL, threshold = 0.5)
file |
A character string specifying the path to the file |
alphabet |
A character vector that lists the set of characters to use |
rescale |
Scale to resize image to (if NULL, sets maximum size of 100x100) |
threshold |
Lightness value at which to truncate |
This is the workhorse function for the package. The user specifies the path to the image fil' as a character vector, and the function returns a tibble specifying the map. You can customise the set of characters used to render the image by changing the alphabet argument. The amount of whitespace in the ASCII image depends on the threshold parameter, which specifies the maximum brightness (in greyscale terms, from 0 to 1) at which the relevant cell in the output will be mapped to a character. Pixels in the image brighter than the threshold are automatically mapped to whitespace. Finally, you can "rescale" the input image. By default, images are rescaled so that the largest dimension is 100 pixels, but you can choose any rescaling factor you want. If your original image is 600x400 you could specify rescale = .1 which would result in a character map that is 60x40 characters is size
The function returns a tibble with three variables. The x and y variables specify co-ordinates on the grid, and the label variable specifies the character that should be shown at that point. Whitespace characters are not included in the output.
bayes_img <- ascii_data("bayes.png") bayes_map <- ascii_map(file = bayes_img) bayes_map
bayes_img <- ascii_data("bayes.png") bayes_map <- ascii_map(file = bayes_img) bayes_map
Plots an ASCII character map
ascii_plot(image_map, charsize = 4)
ascii_plot(image_map, charsize = 4)
image_map |
A tibble specifying a character map |
charsize |
Size of the characters |
A simple plotting function for a character map. It takes a tibble as input, in the form output by the ascii_map function, and plots it using ggplot2. The charsize argument allows you to customise the size of the characters in the plot
A ggplot object.
bayes_img <- ascii_data("bayes.png") bayes_map <- ascii_map(file = bayes_img) ascii_plot(bayes_map)
bayes_img <- ascii_data("bayes.png") bayes_map <- ascii_map(file = bayes_img) ascii_plot(bayes_map)
Writes an ASCII grid to an HTML file with the rain animation
ascii_rain(text_grid, file, fontsize = "5px", lineheight = "4px", turnon = 0.1, turnoff = 0.025)
ascii_rain(text_grid, file, fontsize = "5px", lineheight = "4px", turnon = 0.1, turnoff = 0.025)
text_grid |
Matrix from ascii_grid |
file |
Path to HMTL file |
fontsize |
How big is the text |
lineheight |
How tall is a line |
turnon |
Animation parameter |
turnoff |
Animation parameter |
A matrix, invisibly
## Not run: bayes_img <- ascii_data("bayes.png") # path to the bayes image bayes_map <- ascii_map(bayes_img) # construct ASCII map bayes_grid <- ascii_grid(bayes_map) # make grid ascii_rain(bayes_grid, file = "bayes_rain.html") ## End(Not run)
## Not run: bayes_img <- ascii_data("bayes.png") # path to the bayes image bayes_map <- ascii_map(bayes_img) # construct ASCII map bayes_grid <- ascii_grid(bayes_map) # make grid ascii_rain(bayes_grid, file = "bayes_rain.html") ## End(Not run)
Writes an ASCII grid to text file
ascii_text(text_grid, file)
ascii_text(text_grid, file)
text_grid |
Matrix from ascii_grid |
file |
Path to text file |
A matrix, invisibly
## Not run: bayes_img <- ascii_data("bayes.png") # path to the bayes image bayes_map <- ascii_map(bayes_img) # construct ASCII map bayes_grid <- ascii_grid(bayes_map) # make grid ascii_text(bayes_grid, file = "bayes_grid.txt") ## End(Not run)
## Not run: bayes_img <- ascii_data("bayes.png") # path to the bayes image bayes_map <- ascii_map(bayes_img) # construct ASCII map bayes_grid <- ascii_grid(bayes_map) # make grid ascii_text(bayes_grid, file = "bayes_grid.txt") ## End(Not run)