xxxxxxxxxx
47
let url = "https://api.datamuse.com/words?sl=fetch";
let word;
let img;
let myFont;
function preload() {
img = loadImage("fetch.jpeg");
myFont = loadFont("impact.ttf");
}
function setup() {
createCanvas(400, 400);
}
async function getDatamuse() {
let response = await fetch(url);
let data = await response.json();
let word = random(data).word;
return word;
}
async function draw() {
image(img, -50, 0, 500, 400);
whiteText();
text("Stop trying to make", 45, 55);
let word = await getDatamuse();
text(word, 145, 280);
text("happen", 145, 380);
frameRate(1);
}
function whiteText() {
stroke("black");
strokeWeight(4);
fill("white");
textFont(myFont);
textSize(40);
}
function blackText() {
stroke("white");
strokeWeight(4);
fill("black");
textFont(myFont);
textSize(40);
}