Title: | A Simple Interactive Pixel Art Editor |
---|---|
Description: | A very simple 'pixel art' tool that lets you click squares interactively in a plot window and returns your final image as a matrix. Provide multiple frames to create an animated gif. |
Authors: | Matt Dray [aut, cre] |
Maintainer: | Matt Dray <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.2 |
Built: | 2024-11-28 02:52:48 UTC |
Source: | https://github.com/matt-dray/pixeltrix |
Functions to check if an object is of 'pixeltrix' class, or coerce to it if possible.
as_pixeltrix(m) is_pixeltrix(m)
as_pixeltrix(m) is_pixeltrix(m)
m |
A matrix of integers to coerce. |
To be successfully coerced, m
must be a matrix composed only of
integers.
as_pixeltrix
returns an object of class 'pixeltrix' if
possible. is_pixeltrix
returns TRUE
if the object has class
'pixeltrix', otherwise FALSE
. If coerced, a named character-vector
attribute, 'colours', is also added, which maps the matrix values to a
gradated palette of greys in hex form.
m <- matrix(c(0L, 1L, 1L, 0L), 2, 2) is_pixeltrix(m) m m <- as_pixeltrix(m) is_pixeltrix(m) m
m <- matrix(c(0L, 1L, 1L, 0L), 2, 2) is_pixeltrix(m) m m <- as_pixeltrix(m) is_pixeltrix(m) m
Opens an interactive plot with a grid of squares ('pixels') that you can click to cycle through. Returns a matrix 'blueprint' of your image.
click_pixels( n_rows = 8L, n_cols = 8L, n_states = 2L, colours = NULL, grid = TRUE )
click_pixels( n_rows = 8L, n_cols = 8L, n_states = 2L, colours = NULL, grid = TRUE )
n_rows |
Integer. The number of pixels high that the plot should be. Numeric values are coerced to integer. |
n_cols |
Integer. The number of pixels wide that the plot should be. Numeric values are coerced to integer. |
n_states |
Integer. The number of states that a pixel can be cycled through with successive clicks. Numeric values are coerced to integer. See details. |
colours |
Character vector. As many named/hex colours as 'n_state'. Each click in the interactive plot will cycle a pixel through these colours. Defaults to NULL, which generates a gradation from white to dark grey. See details. |
grid |
Logical. Should a black boundary line be placed around the pixels to help differentiate between them? Defaults to TRUE. |
Click repeatedly the pixels in the interactive plotting window to cycle through the provided number of 'states'. The initial state value is 0 and successive clicks increase it by 1, wrapping back to 0 once the maximum number of states is exceeded. Press the ESCAPE key to exit the interactive mode.
If your editor opens a separate graphics window (i.e. not RStudio),
each click may result in a brief flash as the image refreshes, while a
resized window may return to its original dimensions. You may also hear a
bell sound on click, which you can disable by setting
options(locatorBell = FALSE)
.
A 'pixeltrix'-class matrix. The zero-indexed values correspond to the state of each pixel, which is determined by the number of clicks a user gave each pixel. Has a named character-vector attribute, 'colours', which maps the matrix values to hex colours provided by the user (or a gradated set of greys provided by default when the 'colours' argument is NULL).
## Not run: # Create a 16 x 16 pixel matrix with 3 possible pixel states my_matrix <- click_pixels( n_rows = 16L, n_cols = 16L, n_states = 3L, colours = c("blue", "#FF0000", "yellow") ) ## End(Not run)
## Not run: # Create a 16 x 16 pixel matrix with 3 possible pixel states my_matrix <- click_pixels( n_rows = 16L, n_cols = 16L, n_states = 3L, colours = c("blue", "#FF0000", "yellow") ) ## End(Not run)
Opens a plot window and draws a provided matrix. Designed for use with the
output from click_pixels
(or edit_pixels
).
draw_pixels(m, colours = NULL)
draw_pixels(m, colours = NULL)
m |
A matrix of integers. The maximum value is assumed to be the number of pixel states desired. Override by supplying a 'n_states' value larger than the maximum in the matrix. |
colours |
Character vector. As many named/hex colours as unique state
values in 'm'. Each click in the interactive plot will cycle a pixel
through these colours. Defaults to NULL, which results in an attempt to
find and use the 'colours' attribute (a named character vector) of the
input matrix, 'm', which is added by default to matrices created
with |
Nothing.
## Not run: my_matrix <- click_pixels(n_states = 3L) draw_pixels(my_matrix, c("black", "#0000FF", "green")) # a colour per state ## End(Not run)
## Not run: my_matrix <- click_pixels(n_states = 3L) draw_pixels(my_matrix, c("black", "#0000FF", "green")) # a colour per state ## End(Not run)
Opens an interactive plotting canvas with a grid of clickable squares
('pixels') that represent the cells of a matrix provided by the user,
ideally the output from click_pixels
.
edit_pixels(m, n_states = NULL, colours = NULL, grid = TRUE)
edit_pixels(m, n_states = NULL, colours = NULL, grid = TRUE)
m |
A matrix of integers. The maximum value is assumed to be the number of pixel states desired. Override by supplying a 'n_states' value larger than the maximum in the matrix. |
n_states |
Integer. The number of states that a pixel can be cycled
through with successive clicks. Numeric values are coerced to integer.
Defaults to NULL, which results in an attempt to find and use the
'n_states' attribute (integer) of the input matrix, 'm'. The attribute is
added by default to matrices created with |
colours |
Character vector. As many named/hex colours as 'n_state'. Each
click in the interactive plot will cycle a pixel through these colours.
Defaults to NULL, which results in an attempt to find and use the
'colours' attribute (a named character vector) of the input matrix, 'm'.
This attribute is added by default to matrices created with
|
grid |
Logical. Should a black boundary line be placed around the pixels to help differentiate between them? Defaults to TRUE. |
Click repeatedly the pixels in the interactive plotting window to cycle through the provided number of 'states'. The initial state value is 0 and successive clicks increase it by 1, wrapping back to 0 once the maximum number of states is exceeded. Press the ESCAPE key to exit the interactive mode.
If your editor opens a separate graphics window (i.e. not RStudio),
each click may result in a brief flash as the image refreshes, while a
resized window may return to its original dimensions. You may also hear a
bell sound on click, which you can disable by setting
options(locatorBell = FALSE)
.
A 'pixeltrix'-class matrix. The zero-indexed values correspond to the state of each pixel, which is determined by the number of clicks a user gave each pixel. Has a named character-vector attribute, 'colours', which maps the matrix values to hex colours provided by the user (or a gradated set of greys provided by default when the 'colours' argument is NULL).
## Not run: # Create a 3 x 4 pixel matrix with 3 possible states to cycle through my_matrix <- click_pixels( n_rows = 3L, n_cols = 4L, n_states = 3L, colours = c("white", "red", "#0000FF") ) .# Update the original matrix my_matrix_edited <- edit_pixels(m = my_matrix) # Update the original matrix with additional state, different colours my_matrix_augmented <- edit_pixels( m = my_matrix, n_states = 4L, # one more than in the original colours = c("bisque3", "orchid", "chartreuse", "olivedrab") ) ## End(Not run)
## Not run: # Create a 3 x 4 pixel matrix with 3 possible states to cycle through my_matrix <- click_pixels( n_rows = 3L, n_cols = 4L, n_states = 3L, colours = c("white", "red", "#0000FF") ) .# Update the original matrix my_matrix_edited <- edit_pixels(m = my_matrix) # Update the original matrix with additional state, different colours my_matrix_augmented <- edit_pixels( m = my_matrix, n_states = 4L, # one more than in the original colours = c("bisque3", "orchid", "chartreuse", "olivedrab") ) ## End(Not run)
Opens a new interactive plotting canvas with a grid of clickable squares ('pixels'). When finished, the user is prompted to provide another.
frame_pixels( n_rows = 8L, n_cols = 8L, n_states = 2L, colours = NULL, grid = TRUE )
frame_pixels( n_rows = 8L, n_cols = 8L, n_states = 2L, colours = NULL, grid = TRUE )
n_rows |
Integer. The number of pixels high that the plot should be. Numeric values are coerced to integer. |
n_cols |
Integer. The number of pixels wide that the plot should be. Numeric values are coerced to integer. |
n_states |
Integer. The number of states that a pixel can be. Click a pixel to cycle through the states. Numeric values are coerced to integer. See details. |
colours |
Character vector. As many named/hex colours as n_state. Each
click in the interactive plot will cycle a pixel through these colours.
Defaults to NULL, which results in an attempt to find and use the
'colours' attribute (named character vector) of the input matrix, 'm'.
This attribute is added by default to matrices created with
|
grid |
Logical. Should a boundary line be placed around the pixels to make them easier to differentiate between them? Defaults to TRUE. |
Click the pixels in the plotting window repeatedly to cycle through a number of 'states'. Successive clicks increase the state value by 1 (wrapping back to 0, the default when the canvas is first plotted) and make the pixel darker grey in colour. Press the ESCAPE key to exit the mode. You'll be prompted interactively in the console to add a new frame or not. If you refuse a new frame, you'll be returned a list of matrices, each of which contain the state values of each pixel for each frame of your animation.
If your editor opens a separate graphics window (i.e. not RStudio),
each click may result in a brief flash as the image refreshes, while a
resized window may return to its original dimensions. You may also hear a
bell sound on click, which you can disable by setting
options(locatorBell = FALSE)
.
A list of matrices.
## Not run: # Begin interactive sequence to create animation frames my_frames <- frame_pixels( n_rows = 16L, n_cols = 16L, n_states = 3L, colours = c("grey25", "green", "#0000FF") ) ## End(Not run)
## Not run: # Begin interactive sequence to create animation frames my_frames <- frame_pixels( n_rows = 16L, n_cols = 16L, n_states = 3L, colours = c("grey25", "green", "#0000FF") ) ## End(Not run)
Plots (using draw_pixels
) each matrix from a list (ideally
created using frame_pixels
) and writes it to an animated GIF.
Requires the 'gifski' package.
gif_pixels(frames, colours = NULL, file, ...)
gif_pixels(frames, colours = NULL, file, ...)
frames |
A list of matrices. preferably produced by |
colours |
A character vector of named colours. One for each unique value
in the matrices of the 'frames' list. The order you provide the colours
matches the sorted order of the values in the matrix. Defaults to NULL,
which means colours will be extracted from the 'colours' attribute of the
matrices (which is added to the object when using the recommended
|
file |
A filepath expressed as a character vector, ending with extension '.gif'. This is where the output animation will be written. |
... |
Parameters to pass to |
Nothing.
## Not run: # Begin interactive sequence to create animation frames my_frames <- frame_pixels( n_rows = 16L, n_cols = 16L, n_states = 3L, colours = c("grey25", "green", "#0000FF") ) # Write list of matrices to gif (requires 'gifski' installation) gif_pixels( frames = my_frames, file = "example.gif", # location to write GIF delay = 0.1 # passed to gifski::save_gif() ) ## End(Not run)
## Not run: # Begin interactive sequence to create animation frames my_frames <- frame_pixels( n_rows = 16L, n_cols = 16L, n_states = 3L, colours = c("grey25", "green", "#0000FF") ) # Write list of matrices to gif (requires 'gifski' installation) gif_pixels( frames = my_frames, file = "example.gif", # location to write GIF delay = 0.1 # passed to gifski::save_gif() ) ## End(Not run)
A matrix output from click_pixels
that represents the
text of the pixeltrix package logo, which is the word 'pixeltrix' written
in a font with letters that are 3 by 3 pixels.
logo
logo
A 'pixeltrix'-class matrix with 10 rows and 21 columns, taking integers from 0 to 2.
## Not run: # Plot the matrix as an image draw_pixels(m = pixeltrix::logo) ## End(Not run)
## Not run: # Plot the matrix as an image draw_pixels(m = pixeltrix::logo) ## End(Not run)
A list of matrices output from frame_pixels
that represent the
pixels of the Mario sprite from Super Mario Bros. Each matrix is a step in
the walk cycle.
mario_frames
mario_frames
A list of 'pixeltrix'-class matrices, each with 16 rows and 16 columns, taking integers from 0 to 2.
Super Mario Bros (1983), Nintendo.
## Not run: # Write the list of matrices to a gif gif_pixels( frames = pixeltrix::mario_frames, file = "mario.gif", delay = 0.15 # passed to gifski::save_gif() ) ## End(Not run)
## Not run: # Write the list of matrices to a gif gif_pixels( frames = pixeltrix::mario_frames, file = "mario.gif", delay = 0.15 # passed to gifski::save_gif() ) ## End(Not run)
A matrix output from click_pixels
that represents the pixels of
a player sprite from Pokémon.
pkmn_sprite
pkmn_sprite
A 'pixeltrix'-class matrix with 16 rows and 14 columns, taking integers from 0 to 2.
Hand-copied from Pokemon (1996), The Pokemon Company.
## Not run: # Plot the matrix as an image draw_pixels( m = pixeltrix::pkmn_sprite, colours = c("#9bbc0f", "#8bac0f", "#306230") ) ## End(Not run)
## Not run: # Plot the matrix as an image draw_pixels( m = pixeltrix::pkmn_sprite, colours = c("#9bbc0f", "#8bac0f", "#306230") ) ## End(Not run)