xxxxxxxxxx
75
let positions;
let videoInput;
let e1, e2, e3
function setup() {
cnv = createCanvas(720, 400);
cnv.position(0, 0)
noStroke();
e1 = new Eye(250, 16, 120);
e2 = new Eye(164, 185, 80);
e3 = new Eye(420, 230, 220);
// setup camera capture
videoInput = createCapture(VIDEO);
videoInput.size(displayWidth, displayHeight);
videoInput.position(0, 0);
// setup tracker
ctracker = new clm.tracker();
ctracker.init(pModel);
ctracker.start(videoInput.elt);
}
function draw() {
background(102);
// // flip camera to match head movement
// if (videoInput) {
// translate(videoInput.width, 0);
// scale(-1, 1);
// }
// // get array of face marker positions [x, y] format
// positions = ctracker.getCurrentPosition();
// if (positions) {
// outputX = positions[62][0];
// outputY = positions[62][1];
e1.update(mouseX, mouseY);
e2.update(mouseX, mouseY);
e3.update(mouseX, mouseY);
e1.display();
e2.display();
e3.display();
// }
}
function Eye(tx, ty, ts) {
this.x = tx;
this.y = ty;
this.size = ts;
this.angle = 0;
this.update = function(mx, my) {
this.angle = atan2(my - this.y, mx - this.x);
};
this.display = function() {
push();
translate(this.x, this.y);
fill(255);
ellipse(0, 0, this.size, this.size);
rotate(this.angle);
fill(153, 204, 0);
ellipse(this.size / 4, 0, this.size / 2, this.size / 2);
pop();
};
}