xxxxxxxxxx
198
var font, r, g, b, wordIndex, system, fontsize = 60
let video;
let poseNet;
let poses = [];
let FearPool = [
"Expectations",
"Financial Responsibility",
"Student Loan",
"Failing P Comp ",
"Looking dumb in front of the class",
"GLOBAL WARMING",
"Finials in 4 weeks",
"Unplanned Pregnancy",
"Can’t find a job",
"Loneliness",
"Losing family",
"Breakups",
"Long-distance relationship",
"Competition",
"Hangover",
"Bored in life",
"Violence",
"Intolerance",
"Fascism",
"Having a stalker",
"Pizza with Pineapples",
"Warm beer",
"Hatred",
"PTSD",
"Sleep Paralysis",
"Street food with strang looking meat",
"Paralyzed by fear",
]
function setup() {
createCanvas(640, 480);
textSize(fontsize);
textAlign(CENTER, CENTER);
r = random(0, 255);
g = random(0, 255);
b = random(0, 255);
wordIndex = floor(random(0, 26));
createCanvas(640, 480);
system = new ParticleSystem(createVector(200, 200));
video = createCapture(VIDEO);
video.size(width, height);
// Create a new poseNet method with a single detection
poseNet = ml5.poseNet(video, modelReady);
// This sets up an event that fills the global variable "poses"
// with an array every time new poses are detected
poseNet.on('pose', function(results) {
poses = results;
});
// Hide the video element, and just show the canvas
video.hide();
}
function modelReady() {
select('#status').html('Model Loaded');
}
function draw() {
image(video, 0, 0, width, height);
// We can call both functions to draw all keypoints and the skeletons
drawExpectations();
// Loop through all the poses detected
for (let i = 0; i < poses.length; i++) {
// For each pose detected, loop through all the keypoints
let pose = poses[i].pose;
// A keypoint is an object describing a body part (like rightArm or leftShoulder)
let nose = pose.keypoints[0];
let leftEar = pose.keypoints[3];
let sparkleRadius = dist(nose.position.x, nose.position.y, leftEar.position.x, leftEar.position.y);
// Only draw an ellipse is the pose probability is bigger than 0.2
if (nose.score > 0.2) {
system.origin.x = nose.position.x;
system.origin.y = nose.position.y;
system.addParticle();
system.run();
}
}
console.log(poses.length);
}
var Particle = function(position) {
this.acceleration = createVector(0, 0.05);
this.velocity = createVector(random(-1.5, 1.5), random(-2, 2));
this.position = position.copy();
this.lifespan = 190;
};
Particle.prototype.run = function() {
this.update();
this.display();
};
// Method to update position
Particle.prototype.update = function() {
this.velocity.add(this.acceleration);
this.position.add(this.velocity);
this.lifespan -= 2;
};
// Method to display
Particle.prototype.display = function() {
stroke(200, this.lifespan);
noStroke();
//fill(127, this.lifespan);
fire(this.position.x, this.position.y, this.lifespan);
};
// Is the particle still useful?
Particle.prototype.isDead = function() {
return this.lifespan < 0;
};
var ParticleSystem = function(position) {
this.origin = position.copy();
this.particles = [];
};
ParticleSystem.prototype.addParticle = function() {
this.particles.push(new Particle(this.origin));
};
ParticleSystem.prototype.run = function() {
for (var i = this.particles.length - 1; i >= 0; i--) {
var p = this.particles[i];
p.run();
if (p.isDead()) {
this.particles.splice(i, 1);
}
}
};
function fire(firex, firey, lifespan) {
fill(255, 164, 7, lifespan - 120);
ellipse(firex + random(5), firey, 21, 23);
fill(255, 126, 7, lifespan - 80);
ellipse(firex + random(2), firey, 14, 16);
fill(255, 160, 28, lifespan - 50);
ellipse(firex, firey, 6, 8);
fill(255, 75, 48, lifespan - 40);
ellipse(firex + random(2), firey, 4, 6);
fill(255, 58, 28, lifespan - 20);
ellipse(firex, firey + random(2), 3, 5 + random(2));
}
function drawExpectations() {
for (let i = 0; i < poses.length; i++) {
let pose = poses[i].pose;
let leftShoulder = pose.keypoints[5];
let rightShoulder = pose.keypoints[6];
let leftElbow = pose.keypoints[7];
let rightElbow = pose.keypoints[8];
let leftWrist = pose.keypoints[9];
let rightWrist = pose.keypoints[10];
let leftHip = pose.keypoints[11];
let rightHip = pose.keypoints[12];
strokeWeight(3);
stroke(255);
noFill();
let shoulderDist = dist(leftShoulder.position.x, leftShoulder.position.y, rightShoulder.position.x, rightShoulder.position.y) / 2;
let hipDist = dist(leftHip.position.x, leftHip.position.y, rightHip.position.x, rightHip.position.y) / 2;
let topX = rightShoulder.position.x + shoulderDist;
let topY = rightShoulder.position.y;
let bottomX = rightHip.position.x + hipDist;
let bottomY = rightHip.position.y;
wordIndex=floor(random(0,26));
fill(r, g, b);
textAlign(CENTER,CENTER);
text(FearPool[wordIndex], random(topX, bottomX), random(topY, bottomY));
}
}