xxxxxxxxxx
207
/*
Photos by @sodonechilling and @mitalibhasin on Instagram
*/
let img1, img2;
let d;
let inputCode = [];
let outputCode = [];
function preload() {
img1 = loadImage('img1.jpeg');
img2 = loadImage('img2.jpeg');
// colorMode(HSB);
}
function setup() {
createCanvas(img1.width, img2.height);
pixelDensity(1);
wCode("hello my name is salil.");
// console.log(inputCode);
img1.loadPixels();
for (let x = 0; x < 140; x++) {
for (let y = 0; y < 1; y++) {
let index = (x + y * 140);
let stuff = ReCode(inputCode[index]);
// console.log(stuff);
img1.set(x, y, color(stuff, 90, 55));
}
}
img1.updatePixels();
image(img1, 0, 0);
for (let x = 0; x < 140; x++) {
for (let y = 0; y < 1; y++) {
let index = (x + y * 140);
outputCode[index] = img1.get(x, y);
let checkThing = outputCode[index][0];
console.log(DeCode(checkThing));
}
}
save(img1);
}
function wCode(input) {
for (let x = 0; x < 140; x++) {
for (let y = 0; y < 1; y++) {
let index = (x + y * 140);
inputCode[index] = input.charAt(index);
}
}
}
function DeCode(arr) {
let count;
if (arr == 0) {
count = "a";
} else if (arr == 1) {
count = 'b';
} else if (arr == 2) {
count = 'c';
} else if (arr == 3) {
count = 'd';
} else if (arr == 4) {
count = 'e';
} else if (arr == 5) {
count = 'f';
} else if (arr == 6) {
count = 'g';
} else if (arr == 7) {
count = 'h';
} else if (arr == 8) {
count = 'i';
} else if (arr == 9) {
count = "j";
} else if (arr == 10) {
count = "k";
} else if (arr == 11) {
count = 'l';
} else if (arr == 12) {
count = 'm';
} else if (arr == 13) {
count = 'n';
} else if (arr == 14) {
count = 'o';
} else if (arr == 15) {
count = 'p';
} else if (arr == 16) {
count = 'q';
} else if (arr == 17) {
count = 'r';
} else if (arr == 18) {
count = 's';
} else if (arr == 19) {
count = "t";
} else if (arr == 20) {
count = "u";
} else if (arr == 21) {
count = 'v';
} else if (arr == 22) {
count = 'w';
} else if (arr == 23) {
count = 'x';
} else if (arr == 24) {
count = 'y';
} else if (arr == 25) {
count = 'z';
} else if (arr == 26) {
count = ' ';
} else if (arr == 27) {
count = '.';
} else {
count = "—"
}
return count;
}
function ReCode(arr) {
let count;
if (arr == "a") {
count = 0;
} else if (arr == "b") {
count = 1;
} else if (arr == "c") {
count = 2;
} else if (arr == "d") {
count = 3;
} else if (arr == "e") {
count = 4;
} else if (arr == "f") {
count = 5;
} else if (arr == "g") {
count = 6;
} else if (arr == "h") {
count = 7;
} else if (arr == "i") {
count = 8;
} else if (arr == "j") {
count = 9;
} else if (arr == "k") {
count = 10;
} else if (arr == "l") {
count = 11;
} else if (arr == "m") {
count = 12;
} else if (arr == "n") {
count = 13;
} else if (arr == "o") {
count = 14;
} else if (arr == "p") {
count = 15;
} else if (arr == "q") {
count = 16;
} else if (arr == "r") {
count = 17;
} else if (arr == "s") {
count = 18;
} else if (arr == "t") {
count = 19;
} else if (arr == "u") {
count = 20;
} else if (arr == "v") {
count = 21;
} else if (arr == "w") {
count = 22;
} else if (arr == "x") {
count = 23;
} else if (arr == "y") {
count = 24;
} else if (arr == "z") {
count = 25;
} else if (arr == " ") {
count = 26;
} else if (arr == ".") {
count = 27;
} else {
count = 255
}
return count;
}
function draw() {
// background(220);
}
/*
Sketchnotes
loadpixel method
/ bank[index] = img1.pixels[index];
// bank[index+1] = img1.pixels[index+1];
// bank[index+2] = img1.pixels[index+2];
// bank[index+3] = img1.pixels[index+3];
// console.log(img1.pixels[index+1]);
// bank[index] = [img1.pixels[index], pixels[img1.index + 1], pixels[img1.index + 2], pixels[img1.index + 3]];
// // bank[j] = img1.get(j, i);
// img1.set(j, i, color(0, 90, 102));
change image val
for (let x = 0; x < 140; x++) {
for (let y = 0; y < 1; y++) {
let col = img1.get(x, y);
img1.set(x, y, color(col[0], col[1], 255));
}
}
*/