xxxxxxxxxx
var img;
var emoji_brightest, emoji_bright,emoji_mid, emoji_dark, emoji_darkest;
function preload() {
//img = loadImage("Portrait.jpg");
emoji_brightest = loadImage("Shell.png");
emoji_bright = loadImage("Shirt.png");
emoji_mid = loadImage("Sun.png");
emoji_dark = loadImage("Woman_Surfing.png");
emoji_darkest = loadImage("Sunglasses.png");
}
function setup() {
createCanvas(1280,720);
img = createCapture(VIDEO);
img.size(1280,720);
img.hide();
//noLoop();
}
function draw() {
//image(img, 0, 0);
background(40);
img.loadPixels();
for (var y=0; y<img.height; y+=20)
{
for (var x=0; x<img.width; x+=20)
{
//var pix = red(img.get(x, y));
// Fast but complicated
var pix = img.pixels[(y*img.width+x)*4];
if (pix <= 51)
image(emoji_darkest, x, y, 20, 20);
else if (pix > 50 && pix < 102)
image(emoji_dark, x, y, 20, 20);
else if (pix > 101 && pix < 153)
image(emoji_mid, x, y, 20, 20);
else if (pix > 152 && pix < 204)
image(emoji_bright, x, y, 20, 20);
else if (pix >203 && pix <= 255)
{
image(emoji_brightest, x, y, 20,20);
}
}
}
}