generative js

master
Michael Murtaugh 2 years ago
parent 1866681540
commit f3bcec732b

@ -9,24 +9,36 @@ function choice (arr) {
return ret; return ret;
} }
fetch("terms.json") function make_phrase (nn, terms) {
.then(response => response.json()) nn.querySelector(".actor").innerHTML = choice(terms['actor']);
.then(terms => { nn.querySelector(".action").innerHTML = choice(terms['action']);
console.log("terms", terms); if (randint(0, 2) == 0) {
let call = document.querySelector("#call"); nn.querySelector(".prefix").innerHTML = choice(terms['prefix']);
let template = call.querySelector(".phrase"); } else {
for (var i=0; i<20; i++) { nn.querySelector(".prefix").remove();
let nn = template.cloneNode(true); }
call.appendChild(nn); nn.querySelector(".sort").innerHTML = choice(terms['sort']);
nn.querySelector(".actor").innerHTML = choice(terms['actor']); nn.querySelector(".media").innerHTML = choice(terms['media']);
nn.querySelector(".action").innerHTML = choice(terms['action']); }
if (randint(0, 2) == 0) {
nn.querySelector(".prefix").innerHTML = choice(terms['prefix']); const sleep = delaysecs => new Promise(resolve => setTimeout(resolve, delaysecs*1000));
} else {
nn.querySelector(".prefix").remove(); async function make_phrases () {
} let terms = await (await fetch("terms.json")).json();
nn.querySelector(".sort").innerHTML = choice(terms['sort']); // console.log("terms", terms);
nn.querySelector(".media").innerHTML = choice(terms['media']); let call = document.querySelector("#call");
let template = call.querySelector(".phrase");
template.remove();
while (true) {
let nn = template.cloneNode(true);
call.appendChild(nn);
make_phrase(nn, terms);
if (terms['actor'].length == 0 || terms['action'].length == 0 || terms['prefix'].length == 0 || terms['sort'].length == 0 || terms['media'].length == 0) {
console.log("out of terms, stopping");
break;
} }
template.style.visibility = "hidden"; await (sleep(0.1));
}); }
}
make_phrases();

Loading…
Cancel
Save