xxxxxxxxxx
var c3
var c2
var c1
let i = j = 0
function setup() {
createCanvas(640, 480);
loadPoseNet()
//background(255);
}
function eyecolor(){
j = i
if (i >= j){
c1 = random(255)
c2 = random(255)
c3 = random(255)
}
//text("Current Second is : " + i, 50, 30);
i = second()
}
function draw() {
background(vid.get())
fill(0, 0, 255, 0)
rect(0, 0, width, height)
// background(255)
let faceScale = (leftEyeX - rightEyeX) / width * 5
// console.log('scl:',faceScale)
stewie(noseX, noseY, faceScale)
eyecolor()
}
function stewie(x, y, scl) {
translate(x, y - 100 * scl)
scale(scl)
// rotate(frameCount*0.01)
translate(-width / 2, -height / 2)
//head
fill(229,174,127)
ellipse(402,258,589,388)
// left ear
fill(204,149,102)
ellipse(97,258,37,51)
//right ear
fill(204,149,102)
ellipse(706,258,37,51)
// right eye
fill(c1,c2,c3)
ellipse(270, 274, 116, 116)
// right eyeball
fill(255,0,0)
circle(270,274,25)
//left eye
fill(c1,c2,c3)
ellipse(564,274, 116, 116)
// left eyeball
fill(255,0,0)
circle(564,274,25)
//right eyebrow
strokeWeight(5)
line(235,200,300,200)
//left eyebrow
line(535,200,600,200)
//nose
line(450,310,420,260)
line(450,310,420,310)
//mouth
fill(0)
beginShape()
curveVertex(400,400)
curveVertex(400,400)
curveVertex(410,410)
curveVertex(420,415)
curveVertex(430,417)
curveVertex(440,417)
curveVertex(450,415)
curveVertex(460,410)
curveVertex(470,400)
curveVertex(470,400)
endShape()
}
// poseNet Variables
let vid
let noseX = noseY = rightHandX = rightHandY = leftHandX = leftHandY = leftEyeX = leftEyeY = rightEyeX = rightEyeY = 0
let img;
let poseNet;
let poses = [];
function loadPoseNet() {
vid = createCapture(640, 480)
vid.hide()
poseNet = ml5.poseNet(vid, modelLoaded);
// set some options
let options = {
imageScaleFactor: 1,
minConfidence: 0.25
}
// Listen to new 'pose' events
poseNet.on("pose", function(results) {
poses = results;
if (!poses[0]) return
let pose = poses[0].pose
if (pose) {
noseX = updateValue('nose', 'x', pose, noseX)
noseY = updateValue('nose', 'y', pose, noseY)
rightHandX = updateValue('rightWrist', 'x', pose, rightHandX)
rightHandY = updateValue('rightWrist', 'y', pose, rightHandY)
leftHandX = updateValue('leftWrist', 'x', pose, leftHandX)
leftHandY = updateValue('leftWrist', 'y', pose, leftHandY)
leftEyeX = updateValue('leftEye', 'x', pose, leftEyeX)
leftEyeY = updateValue('leftEye', 'y', pose, leftEyeY)
rightEyeX = updateValue('rightEye', 'x', pose, rightEyeX)
rightEyeY = updateValue('rightEye', 'y', pose, rightEyeY)
}
});
}
function updateValue(key1, key2, kp, curr) {
if (kp[key1].confidence > 0.2) {
return (kp[key1][key2]-curr)*0.5+curr
}
return curr
}
function modelLoaded() {
console.log('model is loaded')
}