xxxxxxxxxx
95
// text animation inspired by http://www.generative-gestaltung.de/2/sketches/?01_P/P_2_3_3_01
'use strict';
let video;
let poseNet;
let noseX = 0;
let noseY = 0;
let eyelX = 0;
let eyelY = 0;
var x = 0;
var y = 0;
var stepSize = 9.0;
var font = 'Georgia';
var letters = 'مریمی';
var fontSizeMin = 8;
var angleDistortion = 0.0;
var counter = 0;
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelReady);
poseNet.on('pose', gotPoses);
background(139,0,139);
textFont(font);
textAlign(LEFT);
fill(255);
}
function gotPoses(poses) {
if (poses.length > 0) {
let pose = poses[0].pose;
noseX = lerp(noseX, pose.nose.x, 0.5);
noseY = lerp(noseY, pose.nose.y, 0.5);
eyelX = lerp(eyelX, pose.leftEye.x, 0.5);
eyelY = lerp(eyelY, pose.leftEye.y, 0.5);
}
}
function modelReady() {
console.log('model ready');
}
function draw() {
//push();
//translate(width,0);
//scale(-1, 1);
image(video,0, 410,100,70);
tint(139,0,139,90);
//pop();
// if (mouseIsPressed) {
var d = dist(x,y,noseX,noseY);
textSize(fontSizeMin + d / 2);
var newLetter = letters.charAt(counter);
stepSize = textWidth(newLetter);
if (d > stepSize) {
var angle = atan2(noseY - y, noseX - x);
push();
translate(x, y);
rotate(angle + random(angleDistortion));
text(newLetter, 0, 0);
pop();
counter++;
if (counter >= letters.length) counter = 0;
x = x + cos(angle) * stepSize;
y = y + sin(angle) * stepSize;
}
// }
let d1 = dist(noseX, noseY, eyelX, eyelY);
//ellipse(mouseX, mouseY, d1);
//fill(0,0,255);
//ellipse(eyelX, eyelY, 50);
}