Skip to content

Instantly share code, notes, and snippets.

@mlajtos
Created March 27, 2021 09:18
Show Gist options
  • Save mlajtos/27dedc2f0874cb93739397940f7123e9 to your computer and use it in GitHub Desktop.
Save mlajtos/27dedc2f0874cb93739397940f7123e9 to your computer and use it in GitHub Desktop.
Artbreeder Interpolation
// Automating Artbreeder Interpolation
// https://www.youtube.com/watch?v=Dhj59I6sus4
function range(start = 0, end = 1, num = 3) {
return Array(num)
.fill(null)
.map((v, i) => start + (i * (end - start)) / (num - 1));
}
function interpolateGene(gene = "mouthopen", values = range(-1, 1, 30)) {
const inputEl = document.querySelector(
`[data-name='${gene}'] input[type='number']`
);
const imageEl = document.querySelector("#main_image");
let currentIndex = 0;
const urls = [];
function onLoad() {
urls.push(imageEl.src);
currentIndex++;
setValue();
}
imageEl.addEventListener("load", onLoad);
function setValue() {
if (currentIndex < values.length) {
inputEl.value = values[currentIndex];
inputEl.dispatchEvent(new Event("change", { bubbles: true }));
} else {
const output = urls
.map((url, i) => {
const filename = `${String(i).padStart(4, "0")}.jpg`;
return `${filename} ${url}`;
})
.join("\n");
console.log(output);
imageEl.removeEventListener("load", onLoad);
}
}
setValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment