glitch_png: Create glitches by databending raw vectors.

View source: R/glitch_functions.R

glitch_pngR Documentation

Create glitches by databending raw vectors.

Description

A function for databending a raw vector by making stochastic changes. (Note that this currently works for PNG images, but other file types have not been tested.)

Usage

glitch_png(input_data, method = "far", n_changes = 5, tune = 100, noise = 20)

Arguments

input_data

A raw vector representing the file to databend.

method

A character string. Which method should be used for the databending. Either "far" (find and replace), which is the default, or "chops" (chance operations). These are explained below.

n_changes

A numeric value. How many unique elements F should be selected for replacement?

tune

A numeric value between 1 and 100. What percentage of the occurences of F should be replaced when using the "far" method?

noise

A numeric value. This sets the ceiling of how big the chunks that are selected when making changes using the "chops" method can be. The higher the value, the more data in the raw vector will be changed.

Details

There are some key differences between the two glitch methods. The "far" (find and replace) method databends the raw vector by randomly sampling unique observed values F and replacing them with another randomly sampled unique value R. .

The "chops" (chance operations) method databends the raw vector by randomly selecting N change points and randomly making a change M at each change point. The changes M can be one of the following operations with equal probability:

  • add: take all unique values of the raw vector, randomly sample a number of them, and then insert these in at the change point.

  • move: take a chunk of elements starting at the change point, delete them, and then reinsert them at a random point in the raw vector.

  • clone: as with move, but don’t delete the chunk, simply copy it to another location.

  • delete: take a chunk of elements starting at the change point and delete them.

This chance operations method uses a more interesting process for bending the data, but is less stable and occasionally breaks the underlying image resulting in grey blocks in the rendered image.

Value

A raw vector representing a modified version of the input vector.

See Also

For more description of the glitch methods, read my blog post at https://www.petejon.es/posts/2020-03-09-glitch-art-in-r/ which also links off to general resources on databending and glitch art.

Examples

data(demo_img1)
my_glitch1 <- glitch_png(demo_img1, method = "far",
                        n_changes = 3, tune = 5)

my_glitch2 <- glitch_png(demo_img1, method = "chops",
                        n_changes = 5, noise = 15)
## Not run: 
my_glitch1 %>%
  magick::image_read() %>%
  magick::image_scale(magick::geometry_size_pixels(width = 550)) %>%
  print()

## End(Not run)


pj398/glitchr documentation built on Aug. 18, 2022, 7:36 a.m.