xxxxxxxxxx
131
let zoff = 0; //increasing blobby jiggle!
let phase = 0; // how fast blobby turn
let noiseMax = 0.75; //how perfect the blob will be
let roff = 0;
let fillCol = 0;
let r = 10;
let g = 0;
let b = 255;
let inputBox;
let submit;
let predict;
let url = "https://text-magotchi.glitch.me/data"
// function preload() {
// // Get the most recent data
// let url = "https://text-magotchi.glitch.me/data"
// data = loadJSON(url);
// console.log(data.body);
// }
// fetch('https://text-magotchi.glitch.me/data')
// .then(response => response.json())
// .then(data => getResponse(data));
// .then(data => sensorValue = data);
// async function getData(data){
// let response = await fetch('url');
// //console.log(response);
// let json = await response.json();
// //console.log(json);
// return {json};
// }
function setup() {
createCanvas(600, 600);
//console.log(sensorData);
//canvas.position();
sentiment = ml5.sentiment('movieReviews', modelReady);
inputBox = createInput('Feed me words');
inputBox.position(width/2 , 600);
submit = createButton('Feed');
submit.position(width/2 + 130,600);
submit.mousePressed(getSentiment);
//getData();
}
function modelReady() {
// model is ready
console.log('model loaded');
}
function getSentiment() {
// get the values from the input
let txt = inputBox.value();
// make the prediction
const prediction = sentiment.predict(txt);
// display sentiment result on html page
console.log('Sentiment score: ' + prediction.score);
predict = prediction.score;
}
function draw() {
//guiding
if (mouseX > 10 && mouseY > 10) {
cursor('grab');
} else {
cursor('grab');
}
background(255);
translate(width/2, height/2);
noStroke();
fill(r,0,b,150);
//fill(c);
beginShape();
for (let a = 0; a < TWO_PI; a += 0.01) {
let xoff = map(cos(a + phase), -1, 1, 0, noiseMax);
let yoff = map(sin(a + phase), -1, 1, 0, noiseMax);
//let roff = map(sin(a)*0.001,-1,1,-200,200);
let r1 = map(noise(xoff, yoff, zoff), 0, 1, 100, 150);
//let r = random(100,150);
let x = r1 * cos(a);
let y = r1 * sin(a);
vertex(x, y);
}
endShape(CLOSE);
phase += 0.01;
zoff += 0.005;
//let score = sensorRead - predict;
let score = predict;
if (score >= 0 && score < 0.4){
phase += 0.01;
zoff += 1;
//r -= 1;
} else if (score >= 0.4 && score < 0.7 ){
phase += 0.05;
zoff += 0.1;
} else if (score >= 0.7 && score < 1){
phase += 0.1;
zoff += 0.01;
//r += 10;
}else{
phase += 0.01;
zoff += 0.005;
}
if (mouseIsPressed) {
noiseMax = 2;
text('Pet meee~',100,-100);
textSize(10);
b -= 5;
r += 5;
} else {
noiseMax = 0.75;
b += 1;
r -= 1;
}
}