Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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