

We use a switch statement for this, deciding which source channel to use based on the sourceChannel variable which has a holds a random number we generated earlier, either 0, 1 or 2. Now that the script has the RGB of the source pixel and RGB of the target pixel we can proceed to shift one of the channels. RGB channel values and one RGB channel value the new target color is two of the target two of the RGB channel values are required get the RGB values of the source pixelĬolor targetPixel = targetPixels Next the script isolates the RGB (red, green, blue) values for both the source and target pixels by using the formula above to access the pixel and then some Processing methods to extract the separate RGB channel values. In order to access a pixel at specific x/y coordinates in the image we use the formula below.

Processing stores image pixels in an array as illustrated in the image below.

If the horizontal shift plus the counter is wider than the image width we subtract the image width to wrap the shift around to the left of the image. It also adds that counter to the sourceXOffset to apply the horizontal shift. Within the row loop the script starts another counter to loop through the columns in that row, left-to-right. This variable drives a for loop around the channel shifting code as seen below. This script is able to apply the same channel shifting effect multiple times, the number of times is specified by the iterations variable, currently set to 5. shift the image horizontally true/false use result image as new source for iterations I’ve set up some settings variables to make the script easier to use, you can see these towards the top of the script under the comment of script settings. image path is relative to sketch directory It’s easiest to place the image in the same directory as the script file. In the script, which are referred to as sketches in Processing, you’ll need to change the following lines to point the script at the image you want to glitch. I’ve written a channel shifting script you can download here, you’ll have to unzip it once it’s downloaded. Once you’ve installed and opened Processing you can load the script by accessing the menu.Īnd navigating to the ChannelShiftGlitch.pde script file. To get started download and install the latest version of Processing, version 3.1.1 at the time of writing this.
