xxxxxxxxxx
86
/*
Recreating Arcimboldo-ed Julia Child by Ken Knowlton, 2010
scr : http://www.asci.org/2016foodexhibition/foodknowlton.html
Part of Recreating the Past class by Zach Liberman at SFPC
Reference Code from Stacy Yuan
https://medium.com/stacys-itp-blog/final-concept-emoji-world-ff24dda35461
and Coding Challenge 49 in coding train
https://thecodingtrain.com/CodingChallenges/049-obamamosaic.html
*/
let cam;
let e
let emojiPal;
let emojiFruit = ["🍅","🍆","🌽","🍠","🍇","🍈","🍉","🍊","🍋","🍌","🍍","🍎","🍏","🍐","🍑","🍒","🍓","🥦","🥑","🥔","🌰"]
let emojiBread = ["🥜","🌰","🍞","🥐","🥨","🥞","🍔","🌭","🥪","🌮","🍘","🥠","🍩","🍪"]
let emojiArray = ["📧","Ⓜ️","🅾️","🎷","ℹ️"];
let move = 1;
let canvas;
function setup() {
canvas = createCanvas(800, 500);
let p = createP('Press Enter to change Emoji');
p.center('horizontal');
pixelDensity(1);
cam = createCapture(VIDEO);
cam.size(800,600);
cam.hide();
emojiPal = new Emoji();
emojiPal.create(emojiFruit);
}
function draw() {
background(245);
cam.loadPixels();
let pixelSize = 8;
for(let x=0; x < cam.width; x+=pixelSize){
for(let y=0; y<cam.height; y+=pixelSize){
let index = (x+y*cam.width)*4; // convert x&y to index //index = position in the array
// get the color of the pixel position
// draw a rect at the corresponding x and y pixel
let r = cam.pixels[index];
let g = cam.pixels[index+1];
let b = cam.pixels[index+2];
let col = color(r,g,b);
let bright = brightness(col)
let e = emojiPal.getClosest(r,g,b);
let cb = emojiPal.getClosestBright(bright);
//console.log(emojiPal.palette[4]);
noStroke();
// fill(bright);
// ellipse(x,y,pixelSize,pixelSize);
let size = map(mouseX,50,width-50,8,100);
textSize(size);
text(cb,x,y);
}
}
}
function keyPressed(){
if (keyCode === ENTER) {
if(move == 3){
emojiPal.palette.length = 0;
emojiPal.create(emojiFruit);
console.log("move3");
move =1;
}
else if(move == 2){
emojiPal.palette.length = 0;
emojiPal.create(emojiBread);
console.log("move2");
move++;
}else{
emojiPal.palette.length = 0;
emojiPal.create(emojiArray);
console.log("move1");
move++;
}
}
}