Last active
October 31, 2017 14:09
-
-
Save AidanNelson/3d5059b332fe824a6512b7147be69b4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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