xxxxxxxxxx
44
/* jshint esversion: 10 */
const baseURL = "https://the-coding-train-api.vercel.app"
let cc = {
title: "Loading...",
originalVideo: {
name: ""
}
}
let anotherButton
let viewButton
async function setup() {
createCanvas(400, 400);
anotherButton = createButton("Find another contribution");
anotherButton.mousePressed(reset)
viewButton = createButton("OPEN")
viewButton.mousePressed(openLink)
reset()
rectMode(CENTER)
}
function draw() {
background(220);
textSize(30)
textAlign(CENTER, CENTER)
text(cc.title, width / 2, 50, width, height)
text("From: " + cc.originalVideo.name, width / 2, 150, width, height)
}
function openLink() {
open(cc.url)
}
async function reset() {
cc.title = 'Loading...'
cc.originalVideo.name = ''
cc = await getRandomContribution()
console.log(cc)
}
async function getRandomContribution() {
return await (await fetch(baseURL + '/challenge/randomContribution')).json()
}