xxxxxxxxxx
// Example Code
// TRY Incorperating the following variables in your code
// leftHandX,leftHandY,rightHandX,rightHandY,leftEyeX,leftEyeY,rightEyeX,rightEyeY
var c3
var c2
var c1
let i = j = 0
function setup() {
createCanvas(640, 480);
loadPoseNet()
//background(255);
}
function draw() {
background(vid.get())
fill(255, 0, 100, 100)
rect(0, 0, width, height)
// background(255)
let faceScale = (leftEyeX - rightEyeX) / width * 5
// console.log('scl:',faceScale)
buttercup(noseX, noseY, faceScale)
haircolor()
}
function haircolor(){
j = i
if (i >= j){
c1 = random(255)
c2 = random(255)
c3 = random(255)
}
//text("Current Second is : " + i, 50, 30);
i = second()
}
function buttercup(x, y, scl) {
translate(x, y - 100 * scl)
scale(scl)
// rotate(frameCount*0.01)
translate(-width / 2, -height / 2)
//hair outline
noFill()
stroke(0)
ellipse(400, 400, 660, 552)
fill(0)
//forehead
drawHair()
// //
strokeWeight(3)
stroke(0)
fill(255, 218, 185)
ellipse(400, 400, 630, 522)
//right eye outer white
fill(255)
circle(568, 380, 288)
//right eye green
fill(50, 205, 50)
circle(559, 380, 265)
//right eye black
fill(0)
circle(540, 380, 218)
//right eye inner white
fill(255)
circle(539, 380, 90)
//left eye outer white
fill(255)
circle(232, 380, 288)
//left eye green
fill(50, 205, 50)
circle(242, 380, 265)
//left eye black
fill(0)
circle(261, 380, 218)
//left eye inner white
fill(255)
circle(269, 380, 90)
//lips
noFill(0)
strokeWeight(3)
stroke(0)
arc(398, 530, 75, 63, 0, PI)
//her giant ass forhead lol
fill(c1, c2, c3)
arc(400, 300, 573, 350, PI, PI * 2)
strokeWeight(0)
fill(255, 218, 185)
beginShape()
vertex(375, 300)
vertex(425, 300)
vertex(400, 250)
endShape()
}
function drawHair() {
//hair sides
rightHair()
leftHair()
}
function rightHair() {
console.log('right hair')
fill(c1,c2,c3)
stroke(0, 0)
beginShape()
curveVertex(99, 331)
curveVertex(99, 331)
curveVertex(98, 378)
curveVertex(83, 441)
curveVertex(13, 490)
curveVertex(90, 531)
curveVertex(143, 555)
curveVertex(188, 572)
curveVertex(232, 585)
curveVertex(252, 589)
endShape()
}
function leftHair() {
stroke(0, 0)
fill(c1,c2,c3)
stroke(0, 0)
push()
translate(800, 0)
beginShape()
curveVertex(-99, 331)
curveVertex(-99, 331)
curveVertex(-98, 378)
curveVertex(-83, 441)
curveVertex(-13, 490)
curveVertex(-90, 531)
curveVertex(-143, 555)
curveVertex(-188, 572)
curveVertex(-232, 585)
curveVertex(-252, 589)
endShape()
pop()
}
// dont touch this code here
// 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')
}