xxxxxxxxxx
93
let button;
let mysound;
let sendText = "";
var area;
let areaCreated = false;
let input, inputText;
var retStr="";
function setup() {
createCanvas(400, 400);
input = createInput();
input.position(130, 250);
button = createButton('generate');
button.position(170, 300);
button.mousePressed(generateSong);
}
function draw() {
background(220);
textSize(32);
text("❤️", 100, 100);
text("💔", 200, 100);
text("🍔", 300, 100);
text("🤪", 100, 200);
text("🎄", 200, 200);
text("🎤", 300, 200);
}
async function requestData(str) {
//console.log(sendText);
const url = "https://runway-lyrics-api.glitch.me/runwaylyrics/:" + str;
console.log(url);
const response = await fetch(url);
const outputs = await response.json();
var retText = outputs.generated_text;
return outputs.generated_text.substring(1, retText.length);
}
async function generateSong() {
inputText = input.value();
//console.log(inputText,sendText);
if (sendText !== "" && inputText == "") {
retStr = await requestData(sendText);
sendText = "";
//createP(outputs.generated_text);
if(!areaCreated){
area = createElement('textarea',retStr);
area.elt.style = 'height:400px;width: 400px';
areaCreated = true;
}else{
area.elt.value = retStr;
}
}else if (sendText == "" && inputText !== "") {
retStr = await requestData(inputText);
inputText = "";
//console.log(retStr);
if(!areaCreated){
area = createElement('textarea',retStr);
area.elt.style = 'height:400px;width: 400px';
areaCreated = true;
}else{
area.elt.value = retStr;
}
} else {
console.log("make selection first");
}
}
function mousePressed() {
if (dist(mouseX, mouseY, 100, 100) <= 50) {
sendText = "love";
}
if (dist(mouseX, mouseY, 200, 100) <= 50) {
sendText = "broken heart";
}
if (dist(mouseX, mouseY, 300, 100) <= 50) {
sendText = "big mac";
}
if (dist(mouseX, mouseY, 100, 200) <= 50) {
sendText = "happy";
}
if (dist(mouseX, mouseY, 200, 200) <= 50) {
sendText = "christmas";
}
if (dist(mouseX, mouseY, 300, 200) <= 50) {
sendText = "sing";
}
}