Skip to content

Instantly share code, notes, and snippets.

@AidanNelson
Last active October 31, 2017 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AidanNelson/3d5059b332fe824a6512b7147be69b4a to your computer and use it in GitHub Desktop.
Save AidanNelson/3d5059b332fe824a6512b7147be69b4a to your computer and use it in GitHub Desktop.
function reduceColors(input, reductionValue){
input.loadPixels();
for (let x=0;x<input.width;x++){
for (let y=0;y<input.height;y++){
let pIndex = 4*(x+y*input.width);
//create variables for r,g,b values
let r = input.pixels[pIndex+0];
let g = input.pixels[pIndex+1];
let b = input.pixels[pIndex+2];
r = round(map(r,0,255,0,reductionValue));
g = round(map(g,0,255,0,reductionValue));
b = round(map(b,0,255,0,reductionValue));
//set those values
input.pixels[pIndex+0]=map(r,0,reductionValue,0,255);
input.pixels[pIndex+1]=map(g,0,reductionValue,0,255);
input.pixels[pIndex+2]=map(b,0,reductionValue,0,255);
}
}
input.updatePixels();
return input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment