Title: | Creates Generative Art Data |
---|---|
Description: | Create data that displays generative art when mapped into a 'ggplot2' plot. Functionality includes specialized data frame creation for geometric shapes, tools that define artistic color palettes, tools for geometrically transforming data, and other miscellaneous tools that are helpful when using 'ggplot2' for generative art. |
Authors: | Meghan Harris [aut, cre] |
Maintainer: | Meghan Harris <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-10 04:30:08 UTC |
Source: | https://github.com/meghansaha/artpack |
The artpack palette picker. The art_pals
function consists of 18 palettes: "arctic",
"beach", "bw", "brood", "cosmos", "explorer", "gemstones", "grays", "icecream", "imagination",
"majestic", "nature", "neon", "ocean", "plants", "rainbow", "sunnyside", "super"
art_pals(pal = NULL, n = 5, direction = "regular")
art_pals(pal = NULL, n = 5, direction = "regular")
pal |
A character string of the desired artpack palette. The 18 artpack palettes include:
|
n |
The numbers of colors desired in the output. Default is |
direction |
The direction of the palette Default is "regular". Only two options accepted: "regular" or "reverse" |
A Character Vector.
library(ggplot2) dots <- data.frame(x = c(1:10), y = 2.5) dots$fills <- art_pals("rainbow", 10) dots |> ggplot(aes(x, y)) + theme_void() + geom_point( shape = 21, fill = dots$fills, color = "#000000", size = 10, stroke = 2 ) dots_rev <- data.frame(x = c(1:10), y = 2.5) dots_rev$fills <- art_pals("rainbow", 10, "reverse") dots_rev |> ggplot(aes(x, y)) + theme_void() + geom_point( shape = 21, fill = dots_rev$fills, color = "#000000", size = 10, stroke = 2 )
library(ggplot2) dots <- data.frame(x = c(1:10), y = 2.5) dots$fills <- art_pals("rainbow", 10) dots |> ggplot(aes(x, y)) + theme_void() + geom_point( shape = 21, fill = dots$fills, color = "#000000", size = 10, stroke = 2 ) dots_rev <- data.frame(x = c(1:10), y = 2.5) dots_rev$fills <- art_pals("rainbow", 10, "reverse") dots_rev |> ggplot(aes(x, y)) + theme_void() + geom_point( shape = 21, fill = dots_rev$fills, color = "#000000", size = 10, stroke = 2 )
A tool for creating a data frame of values that create a circle with a specified radius when plotted.
The geom_path
and geom_polygon
geoms are recommended with this data for use in ggplot2
for generative art.
circle_data( x, y, radius, color = NULL, fill = NULL, n_points = 100, group_var = FALSE, group_prefix = "circle_" )
circle_data( x, y, radius, color = NULL, fill = NULL, n_points = 100, group_var = FALSE, group_prefix = "circle_" )
x |
Numeric value of length 1 - The center |
y |
Numeric value of length 1 - The center |
radius |
Numeric value of length 1 that must be greater than 0 - The radius of the circle. |
color |
Character value of length 1 - The color of the square's border. A valid |
fill |
Character value of length 1 - The color of the square. A valid |
n_points |
Numeric value. Default is 100. This determines how many points the square will have. This option can come in handy when using jitter options or other texture/illusion methods. Must be of length 1 and at least a value of 100. |
group_var |
Logical. Default is |
group_prefix |
Character string of length 1 - The prefix used for the |
A Tibble
# Creating one circle library(ggplot2) one_circle <- circle_data(x = 0, y = 0, radius = 5) # Plot The Data one_circle |> ggplot(aes(x, y)) + geom_path(color = "green") + coord_equal() # To create multiple circles, use your preferred method of iteration: # Creating two circles library(purrr) library(dplyr) # Make your specs x_vals <- c(0, 10) y_vals <- c(0, 0) radi <- c(1, 3) fills <- c("purple", "yellow") circle_n <- 1:2 # Prep for your iteration lst_circle_specs <- list( x_vals, y_vals, radi, fills, circle_n ) # Use `circle_data()` in your preferred iteration methods two_circles <- pmap(lst_circle_specs, ~ circle_data( x = ..1, y = ..2, radi = ..3, fill = ..4, color = "#000000", group_var = TRUE ) |> # circle_data adds a `group` variable if `group_var` = TRUE. # For multiple circles, a unique identifier should be added/pasted in. mutate(group = paste0(group, ..5))) |> list_rbind() # Plot the data two_circles |> ggplot(aes(x, y, group = group)) + theme(legend.position = "none") + geom_polygon( color = two_circles$color, fill = two_circles$fill ) + coord_equal() #Always use coord_equal() or coord_fixed for circles!
# Creating one circle library(ggplot2) one_circle <- circle_data(x = 0, y = 0, radius = 5) # Plot The Data one_circle |> ggplot(aes(x, y)) + geom_path(color = "green") + coord_equal() # To create multiple circles, use your preferred method of iteration: # Creating two circles library(purrr) library(dplyr) # Make your specs x_vals <- c(0, 10) y_vals <- c(0, 0) radi <- c(1, 3) fills <- c("purple", "yellow") circle_n <- 1:2 # Prep for your iteration lst_circle_specs <- list( x_vals, y_vals, radi, fills, circle_n ) # Use `circle_data()` in your preferred iteration methods two_circles <- pmap(lst_circle_specs, ~ circle_data( x = ..1, y = ..2, radi = ..3, fill = ..4, color = "#000000", group_var = TRUE ) |> # circle_data adds a `group` variable if `group_var` = TRUE. # For multiple circles, a unique identifier should be added/pasted in. mutate(group = paste0(group, ..5))) |> list_rbind() # Plot the data two_circles |> ggplot(aes(x, y, group = group)) + theme(legend.position = "none") + geom_polygon( color = two_circles$color, fill = two_circles$fill ) + coord_equal() #Always use coord_equal() or coord_fixed for circles!
Creates a dataframe of x
and y
points to visualize a square grid based on given x
and y
limits.
Providing a color palette and fill style are optional.
grid_maker( xlim, ylim, size, fill_pal = NULL, fill_style = "range", color_pal = NULL, color_style = "range" )
grid_maker( xlim, ylim, size, fill_pal = NULL, fill_style = "range", color_pal = NULL, color_style = "range" )
xlim |
A numeric vector with two X limits. A minimum and maximum limit for the X axis. Must be a length of 2. |
ylim |
A numeric vector with two Y limits. A minimum and maximum limit for the Y axis. Must be a length of 2. |
size |
A numeric input. The size of the grid. How many shapes will appear in a single row or column. Must be a length of 1, greater than 0, and less than or equal to the max |
fill_pal |
Optional. A character vector of 6 digit hexadecimal webcolor code, or |
fill_style |
Optional. A character input. "range" or "random". Determines how the fill color palette is mapped. |
color_pal |
Optional. A character vector of 6 digit hexadecimal webcolor code, or |
color_style |
Optional. A character input. "range" or "random". Determines how the border color palette is mapped. |
A Tibble
# Creating data for a grid: library(ggplot2) grid_data <- grid_maker( xlim = c(0, 50), ylim = c(0, 50), size = 10, fill_pal = c("turquoise", "black", "purple"), color_pal = c("black", "limegreen") ) ggplot() + geom_polygon( data = grid_data, aes(x, y, group = group), fill = grid_data$fill, color = grid_data$color ) + coord_equal()
# Creating data for a grid: library(ggplot2) grid_data <- grid_maker( xlim = c(0, 50), ylim = c(0, 50), size = 10, fill_pal = c("turquoise", "black", "purple"), color_pal = c("black", "limegreen") ) ggplot() + geom_polygon( data = grid_data, aes(x, y, group = group), fill = grid_data$fill, color = grid_data$color ) + coord_equal()
Convert Numbers into Padded Strings for Easier Group Numbering
group_numbers(numbers)
group_numbers(numbers)
numbers |
A numeric vector with a length of at least 1. |
A Character Vector
# Useful for easier group numbering so groups are ordered as intended # Expects a numeric vector of numbers to convert to padded numbers regular_numbers <- 1:19 padded_numbers <- group_numbers(regular_numbers) # The padding matters when creating labels for groupings # as numbers will be converted to characters if attached to strings. # Sorts as expected: sort(regular_numbers) # Does not as a character: sort(paste0("group_", regular_numbers)) # Will sort as expected when padded: sort(paste0("group_", padded_numbers))
# Useful for easier group numbering so groups are ordered as intended # Expects a numeric vector of numbers to convert to padded numbers regular_numbers <- 1:19 padded_numbers <- group_numbers(regular_numbers) # The padding matters when creating labels for groupings # as numbers will be converted to characters if attached to strings. # Sorts as expected: sort(regular_numbers) # Does not as a character: sort(paste0("group_", regular_numbers)) # Will sort as expected when padded: sort(paste0("group_", padded_numbers))
A tool for creating a data frame of values that create a circle packing design when plotted.
When the default circle_type
"whole" is used, the output should mapped with geom_polygon
in a ggplot. When "swirl" is used, the output should be mapped with geom_path
for the best results.
packer( n, min_x = 0, max_x = 100, min_y = 0, max_y = 100, big_r = 5, med_r = 3, small_r = 1, color_pal = NULL, color_type = "regular", circle_type = "whole" )
packer( n, min_x = 0, max_x = 100, min_y = 0, max_y = 100, big_r = 5, med_r = 3, small_r = 1, color_pal = NULL, color_type = "regular", circle_type = "whole" )
n |
The total number of circles you would like the function to attempt to create. A single numeric value with a minimum value of 10. |
min_x |
The minimum limit of the x-axis - the left 'border' of the canvas A single numeric value. |
max_x |
The maximum limit of the x-axis - the right 'border' of the canvas A single numeric value. |
min_y |
The minimum limit of the y-axis - the bottom 'border' of the canvas A single numeric value. |
max_y |
The maximum limit of the y-axis - the top 'border' of the canvas A single numeric value. |
big_r |
The radius used for your 'big' sized circles A single numeric value. |
med_r |
The radius used for your 'medium' sized circles. A single numeric value. |
small_r |
The radius used for your 'small' sized circles. A single numeric value. |
color_pal |
A vector of hex color codes that will be mapped to the data. |
color_type |
Default is "regular" - The colors will be mapped in order from big circles to small circles. "reverse" - The colors will be mapped in reversed order from small to big circles. "random" - The colors will be mapped randomly to any sized circle. |
circle_type |
Default is "whole" - Regular circles. "swirl" - circles are replaced with spirals. Spirals should be mapped with |
A Tibble
library(ggplot2) set.seed(0310) packed_circles <- packer( n = 50, big_r = 5, med_r = 3, small_r = 1, min_x = 0, max_x = 100, min_y = 0, max_y = 100 ) packed_circles packed_circles |> ggplot(aes(x, y, group = group)) + theme_void() + theme(plot.background = element_rect(fill = "black")) + geom_polygon(fill = "white", color = "red") + coord_equal()
library(ggplot2) set.seed(0310) packed_circles <- packer( n = 50, big_r = 5, med_r = 3, small_r = 1, min_x = 0, max_x = 100, min_y = 0, max_y = 100 ) packed_circles packed_circles |> ggplot(aes(x, y, group = group)) + theme_void() + theme(plot.background = element_rect(fill = "black")) + geom_polygon(fill = "white", color = "red") + coord_equal()
Rotates the x
and y
points in a given data frame by a given angle based on a designated anchor point.
rotator(data, x, y, angle = 5, anchor = "center", drop = FALSE)
rotator(data, x, y, angle = 5, anchor = "center", drop = FALSE)
data |
A data frame or tibble with at least |
x |
A numeric variable in |
y |
A numeric variable in |
angle |
The angle (in degrees) the points in |
anchor |
The anchor point for the rotation. Default is "center". Options include:"center", "bottom", "top", "left", and "right" |
drop |
Logical |
A data frame
library(ggplot2) original_square <- data.frame( x = c(0, 3, 3, 0, 0), y = c(0, 0, 3, 3, 0) ) rotated_square <- rotator(data = original_square, x = x, y = y, angle = 45, anchor = "center") ggplot()+ geom_path(data = original_square, aes(x,y), color = "red")+ geom_polygon(data = rotated_square, aes(x,y), fill = "purple")+ coord_equal()
library(ggplot2) original_square <- data.frame( x = c(0, 3, 3, 0, 0), y = c(0, 0, 3, 3, 0) ) rotated_square <- rotator(data = original_square, x = x, y = y, angle = 45, anchor = "center") ggplot()+ geom_path(data = original_square, aes(x,y), color = "red")+ geom_polygon(data = rotated_square, aes(x,y), fill = "purple")+ coord_equal()
A tool for creating a data frame of values that create a square with a specified size when plotted.
The geom_path
and geom_polygon
geoms are recommended with this data for use in ggplot2
for generative art.
square_data( x, y, size, color = NULL, fill = NULL, n_points = 100, group_var = FALSE, group_prefix = "square_" )
square_data( x, y, size, color = NULL, fill = NULL, n_points = 100, group_var = FALSE, group_prefix = "square_" )
x |
Numeric value of length 1 - The bottom left |
y |
Numeric value of length 1 - The bottom left |
size |
Numeric value of length 1 that must be greater than 0 - The size of the square. |
color |
Character value of length 1 - The color of the square's border. A valid |
fill |
Character value of length 1 - The color of the square. A valid |
n_points |
Numeric value. Default is 100. This determines how many points the square will have. This option can come in handy when using jitter options or other texture/illusion methods. Must be of length 1 and at least a value of 4. |
group_var |
Logical. Default is |
group_prefix |
Character string of length 1 - The prefix used for the |
A Tibble
# Creating one square library(ggplot2) one_square <- square_data(x = 0, y = 0, size = 5) # Plot The Data one_square |> ggplot(aes(x,y))+ geom_path(color = "green")+ coord_equal() # To create multiple squares, use your preferred method of iteration: # Creating two squares library(purrr) library(dplyr) # Make your specs x_vals <- c(0,4) y_vals <- c(0,0) sizes <- c(1,3) fills <- c("purple", "yellow") square_n <- 1:2 # Prep for your iteration lst_square_specs <- list( x_vals, y_vals, sizes, fills, square_n ) # Use `square_data()` in your preferred iteration methods two_squares <- pmap(lst_square_specs, ~square_data( x = ..1, y = ..2, size = ..3, fill = ..4, color = "#000000", group_var = TRUE ) |> # square_data adds a `group` variable if `group_var` = TRUE. # For multiple squares, a unique identifier should be added/pasted in. mutate(group = paste0(group,..5)) ) |> list_rbind() # Plot the data two_squares |> ggplot(aes(x, y, group = group))+ theme(legend.position = "none")+ geom_polygon(color = two_squares$color, fill = two_squares$fill) + coord_equal()
# Creating one square library(ggplot2) one_square <- square_data(x = 0, y = 0, size = 5) # Plot The Data one_square |> ggplot(aes(x,y))+ geom_path(color = "green")+ coord_equal() # To create multiple squares, use your preferred method of iteration: # Creating two squares library(purrr) library(dplyr) # Make your specs x_vals <- c(0,4) y_vals <- c(0,0) sizes <- c(1,3) fills <- c("purple", "yellow") square_n <- 1:2 # Prep for your iteration lst_square_specs <- list( x_vals, y_vals, sizes, fills, square_n ) # Use `square_data()` in your preferred iteration methods two_squares <- pmap(lst_square_specs, ~square_data( x = ..1, y = ..2, size = ..3, fill = ..4, color = "#000000", group_var = TRUE ) |> # square_data adds a `group` variable if `group_var` = TRUE. # For multiple squares, a unique identifier should be added/pasted in. mutate(group = paste0(group,..5)) ) |> list_rbind() # Plot the data two_squares |> ggplot(aes(x, y, group = group))+ theme(legend.position = "none")+ geom_polygon(color = two_squares$color, fill = two_squares$fill) + coord_equal()
A tool for making data frames filled with data that displays sine or cosine waves when graphed.
The geom_path
and geom_polygon
geoms are recommended with this data for use in ggplot2
for generative art.
wave_data( start, end, size = 1, type = "sin", orientation = "horizontal", freq = 3, n_points = 500, color = NULL, fill = NULL, group_var = FALSE, dampen = NULL, amplify = NULL )
wave_data( start, end, size = 1, type = "sin", orientation = "horizontal", freq = 3, n_points = 500, color = NULL, fill = NULL, group_var = FALSE, dampen = NULL, amplify = NULL )
start |
Numeric value. The starting point of the wave on the coordinate system. By default refers to the x-axis. Will refer to the y-axis if |
end |
Numeric value. The ending point of the wave on the coordinate system. By default refers to the x-axis. Will refer to the y-axis if |
size |
Numeric value. The height or width of the wave. Orientation is set to |
type |
String value. "sin" or "cos" for sine or cosine waves. |
orientation |
String value. Default is |
freq |
Numeric value. Default is 3 cycles per second. This affects how many "peaks" are created in the wave. Must be a positive numeric value. Must be of length 1. |
n_points |
Numeric value. Default is 500. This determines how many points each half of the wave will have. This option can come in handy when using jitter options or other texture/illusion methods. Must be of length 1. |
color |
Optional String Value. A 6 digit hexadecimal webcolor code, or |
fill |
Optional String Value. A 6 digit hexadecimal webcolor code, or |
group_var |
Logic value. |
dampen |
Optional. A factor in which to dampen the wave (make "flatter"). Must be of length 1. |
amplify |
Optional. A factor in which to amplify the wave (make "sharper"). Must be of length 1. |
A Tibble
library(ggplot2) wave_df <- wave_data( start = 0, end = 10, fill = "purple", color = "green" ) wave_df |> ggplot(aes(x, y)) + theme_void() + geom_polygon( fill = wave_df$fill, color = wave_df$color, linewidth = 3 ) + coord_equal()
library(ggplot2) wave_df <- wave_data( start = 0, end = 10, fill = "purple", color = "green" ) wave_df |> ggplot(aes(x, y)) + theme_void() + geom_polygon( fill = wave_df$fill, color = wave_df$color, linewidth = 3 ) + coord_equal()