xxxxxxxxxx
333
//Created by Rajshree Saraf and Daniel Ryan Johnston
//NYU ITP Fall 2020 Intro. to Computational Media
let tex;
let col;
let man;
let words = false;
let old = false;
let vibe = false;
let oth = false;
let d = 38;
let PoseNet;
let noseX = 0;
function preload() {
tex = loadImage('ettanew-07.png');
you = createCapture(VIDEO);
man = loadImage('ettanew-08.png');
col = loadImage('ettanew-09.png');
}
function setup() {
createCanvas(windowWidth-100, windowHeight-100);
// div.center();
pixelDensity(1);
// frameRate(5)
tex.resize(width, height);
col.resize(width, height);
man.resize(width, height);
you.size(width, height);
you.hide()
// col = createVideo("Comp_2.mp4")
// tex = createVideo("adj-5.mp4")
// tex.loop()
// tex.size(width, height);
// tex.hide()
// col.loop()
// col.size(width, height)
// col.hide()
poseNet = ml5.poseNet(you, modelReady);
poseNet.on('pose', gotPoses);
}
function draw() {
let c = 0
background(c)
tex.loadPixels();
man.loadPixels();
col.loadPixels();
you.loadPixels()
loadPixels();
for (let x = 0; x < width; x += 4) {
for (let y = 0; y < height; y++) {
let i = (x + y * width) * 4;
let i1 = ((x + 1) + y * width) * 4;
let i2 = ((x + 2) + y * width) * 4;
let i3 = ((x + 3) + y * width) * 4;
// camera on: balck and white, fourth pixel coloumn
// let br = (you.pixels[i3 + 0] + you.pixels[i3 + 1] + you.pixels[i3 + 2]) / 3
// if (br > 150){
// you.pixels[i3 + 0] = 255
// you.pixels[i3 + 1] = 255
// you.pixels[i3 + 2] = 255
// }
// else {
// you.pixels[i3 + 0] = 0
// you.pixels[i3 + 1] = 0
// you.pixels[i3 + 2] = 0
// }
// pixels[i3 + 0] = (tex.pixels[i3 + 0] * 35 / 255) + (man.pixels[i3 + 0] * 35 / 255) + (col.pixels[i3 + 0] * 35 / 255) + (you.pixels[i3 + 0] * 150 / 255)
// pixels[i3 + 1] = (tex.pixels[i3 + 1] * 35 / 255) + (man.pixels[i3 + 1] * 35 / 255) + (col.pixels[i3 + 1] * 35 / 255) + (you.pixels[i3 + 1] * 150 / 255)
// pixels[i3 + 2] = (tex.pixels[i3 + 2] * 35 / 255) + (man.pixels[i3 + 2] * 35 / 255) + (col.pixels[i3 + 2] * 35 / 255) + (you.pixels[i3 + 2] * 150 / 255)
if (noseX > 0 && noseX < width * 1.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 2 / d && noseX < width * 3.65 / d) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else if (noseX > width * 4 / d && noseX < width * 5.65 / d) {
//col
words = false;
old = false;
vibe = true;
oth = false;
} else if (noseX > width * 6 / d && noseX < width * 7.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 8 / d && noseX < width * 9.65 / d) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else if (noseX > width * 10 / d && noseX < width * 11.65 / d) {
//col
words = false;
old = false;
vibe = true;
oth = false;
} else if (noseX > width * 12 / d && noseX < width * 13.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 14 / d && noseX < width * 15.65 / d) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else if (noseX > width * 16 / d && noseX < width * 17.65 / d) {
//col
words = false;
old = false;
vibe = true;
oth = false;
} else if (noseX > width * 18 / d && noseX < width * 19.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 20 / d && noseX < width * 21.65 / d) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else if (noseX > width * 22 / d && noseX < width * 23.65 / d) {
//col
words = false;
old = false;
vibe = true;
oth = false;
} else if (noseX > width * 24 / d && noseX < width * 25.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 26 / d && noseX < width * 27.65 / d) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else if (noseX > width * 28 / d && noseX < width * 29.65 / d) {
//col
words = false;
old = false;
vibe = true;
oth = false;
} else if (noseX > width * 30 / d && noseX < width * 31.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 32 / d && noseX < width * 33.65 / d) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else if (noseX > width * 34 / d && noseX < width * 35.65 / d) {
//col
words = false;
old = false;
vibe = true;
oth = false;
} else if (noseX > width * 36 / d && noseX < width * 37.65 / d) {
//tex
words = true;
old = false;
vibe = false;
oth = false;
} else if (noseX > width * 38 / d && noseX < width) {
//man
words = false;
old = true;
vibe = false;
oth = false;
} else {
// default
words = false;
old = false;
vibe = false;
oth = true;
}
if (words == true) {
pixels[i + 0] = (tex.pixels[i + 0] * 126 / 255) + (man.pixels[i + 0] * 26 / 255) + (c * 103 / 255)
pixels[i + 1] = (tex.pixels[i + 1] * 126 / 255) + (man.pixels[i + 1] * 26 / 255) + (c * 103 / 255)
pixels[i + 2] = (tex.pixels[i + 2] * 126 / 255) + (man.pixels[i + 2] * 26 / 255) + (c * 103 / 255)
pixels[i1 + 0] = (tex.pixels[i1 + 0] * 140 / 255) + (col.pixels[i1 + 0] * 115 / 255)
pixels[i1 + 1] = (tex.pixels[i1 + 1] * 140 / 255) + (col.pixels[i1 + 0] * 115 / 255)
pixels[i1 + 2] = (tex.pixels[i1 + 2] * 140 / 255) + (col.pixels[i1 + 0] * 115 / 255)
pixels[i2 + 0] = (tex.pixels[i2 + 0] * 160 / 255) + (man.pixels[i2 + 0] * 47 / 255) + (col.pixels[i2 + 0] * 48 / 255)
pixels[i2 + 1] = (tex.pixels[i2 + 1] * 160 / 255) + (man.pixels[i2 + 1] * 47 / 255) + (col.pixels[i2 + 1] * 48 / 255)
pixels[i2 + 2] = (tex.pixels[i2 + 2] * 160 / 255) + (man.pixels[i2 + 2] * 47 / 255) + (col.pixels[i2 + 2] * 48 / 255)
}
if (vibe == true) {
pixels[i + 0] = (col.pixels[i + 0] * 200 / 255) + (tex.pixels[i + 0] * 22 / 255) + (man.pixels[i + 0] * 33 / 255)
pixels[i + 1] = (col.pixels[i + 1] * 200 / 255) + (tex.pixels[i + 1] * 22 / 255) + (man.pixels[i + 1] * 33 / 255)
pixels[i + 2] = (col.pixels[i + 2] * 200 / 255) + (tex.pixels[i + 2] * 22 / 255) + (man.pixels[i + 2] * 33 / 255)
pixels[i1 + 0] = (col.pixels[i1 + 0] * 126 / 255) + (man.pixels[i1 + 0] * 26 / 255) + (c * 103 / 255)
pixels[i1 + 1] = (col.pixels[i1 + 1] * 126 / 255) + (man.pixels[i1 + 1] * 26 / 255) + (c * 103 / 255)
pixels[i1 + 2] = (col.pixels[i1 + 2] * 126 / 255) + (man.pixels[i1 + 2] * 26 / 255) + (c * 103 / 255)
pixels[i2 + 0] = (col.pixels[i2 + 0] * 95 / 255) + (tex.pixels[i2 + 0] * 160 / 255)
pixels[i2 + 1] = (col.pixels[i2 + 1] * 95 / 255) + (tex.pixels[i2 + 1] * 160 / 255)
pixels[i2 + 2] = (col.pixels[i2 + 2] * 95 / 255) + (tex.pixels[i2 + 2] * 160 / 255)
}
if (old == true) {
pixels[i + 0] = (tex.pixels[i + 0] * 95 / 255) + (man.pixels[i + 0] * 160 / 255)
pixels[i + 1] = (tex.pixels[i + 1] * 95 / 255) + (man.pixels[i + 1] * 160 / 255)
pixels[i + 2] = (tex.pixels[i + 2] * 95 / 255) + (man.pixels[i + 2] * 160 / 255)
pixels[i1 + 0] = (man.pixels[i1 + 0] * 200 / 255) + (tex.pixels[i1 + 0] * 22 / 255) + (col.pixels[i1 + 0] * 33 / 255)
pixels[i1 + 1] = (man.pixels[i1 + 1] * 200 / 255) + (tex.pixels[i1 + 1] * 22 / 255) + (col.pixels[i1 + 1] * 33 / 255)
pixels[i1 + 2] = (man.pixels[i1 + 2] * 200 / 255) + (tex.pixels[i1 + 2] * 22 / 255) + (col.pixels[i1 + 2] * 33 / 255)
pixels[i2 + 0] = (man.pixels[i2 + 0] * 126 / 255) + (col.pixels[i2 + 0] * 26 / 255) + (c * 103 / 255)
pixels[i2 + 1] = (man.pixels[i2 + 0] * 126 / 255) + (col.pixels[i2 + 0] * 26 / 255) + (c * 103 / 255)
pixels[i2 + 2] = (man.pixels[i2 + 0] * 126 / 255) + (col.pixels[i2 + 0] * 26 / 255) + (c * 103 / 255)
}
if (oth == true) {
pixels[i + 0] = (man.pixels[i + 0] * 120 / 255) + (col.pixels[i + 0] * 120 / 255) + (c * 15 / 255)
pixels[i + 1] = (man.pixels[i + 1] * 120 / 255) + (col.pixels[i + 1] * 120 / 255) + (c * 15 / 255)
pixels[i + 2] = (man.pixels[i + 2] * 120 / 255) + (col.pixels[i + 2] * 120 / 255) + (c * 15 / 255)
pixels[i1 + 0] = (tex.pixels[i1 + 0] * 100 / 255) + (man.pixels[i1 + 0] * 120 / 255) + (c * 25 / 255)
pixels[i1 + 1] = (tex.pixels[i1 + 1] * 100 / 255) + (man.pixels[i1 + 1] * 120 / 255) + (c * 25 / 255)
pixels[i1 + 2] = (tex.pixels[i1 + 2] * 100 / 255) + (man.pixels[i1 + 2] * 120 / 255) + (c * 25 / 255)
pixels[i2 + 0] = (tex.pixels[i2 + 0] * 100 / 255) + (col.pixels[i2 + 0] * 120 / 255) + (c * 25 / 255)
pixels[i2 + 1] = (tex.pixels[i2 + 1] * 100 / 255) + (col.pixels[i2 + 1] * 120 / 255) + (c * 25 / 255)
pixels[i2 + 2] = (tex.pixels[i2 + 2] * 100 / 255) + (col.pixels[i2 + 2] * 120 / 255) + (c * 25 / 255)
}
}
}
updatePixels()
}
function gotPoses(poses) {
// console.log(poses);
if (poses.length > 0) {
let newX = poses[0].pose.keypoints[0].position.x;
// let newY = poses[0].pose.keypoints[0].position.y;
noseX = lerp(noseX, newX, 0.5);
// noseY = lerp(noseY, newY, 0.5);
}
}
function modelReady() {
console.log('model ready');
}