Skip to content

Instantly share code, notes, and snippets.

@timseverien
Last active January 3, 2019 07:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timseverien/b1771dc4f09abce961faacc6ac2f2528 to your computer and use it in GitHub Desktop.
Save timseverien/b1771dc4f09abce961faacc6ac2f2528 to your computer and use it in GitHub Desktop.

neural-abstract-art-image-sequence.js can be used to download a sequence of images from Abstract Art by a Neural Network.

Using software like VirtualDub, you can import the image sequence and turn it into a video.

Usage

Pasting the contents of neural-abstract-art-image-sequence.js in the developer tools console of your favourite browser should work.

(() => {
const timeIncrements = Number.parseFloat(window.prompt("Time increments", 0.01));
const frameCount = Number.parseInt(window.prompt("Frame count", 60 * 10));
const buttonDownload = document.querySelector('[data-ref="button-download"]');
const inputSeed = document.getElementById('input-seed');
const inputSharpness = document.getElementById('input-sharpness');
const inputTime = document.getElementById('input-time');
let frames = 0;
const download = (filename) => {
const canvas = document.querySelector('[data-component="image-renderer"]');
const anchor = document.createElement('a');
anchor.style.display = 'none';
anchor.download = filename;
anchor.href = canvas.toDataURL('image/png');;
// Link has to be attached to DOM to work in Firefox
document.body.appendChild(anchor);
// fire click
anchor.click();
// Link has to be attached to DOM to work in Firefox
requestAnimationFrame(() => document.body.removeChild(anchor));
};
const observer = new MutationObserver((mutationsList) => mutationsList.forEach((mutation) => {
if (buttonDownload.disabled) return;
const id = frames.toString().padStart(8, '0');
download(`${inputSeed.value}-${inputSharpness.value}-${id}.png`);
inputTime.value = (Number.parseFloat(inputTime.value) + timeIncrements).toFixed(4);
inputTime.dispatchEvent(new Event('input', { bubbles: true }));
if (++frames === frameCount) {
observer.disconnect();
}
}));
observer.observe(buttonDownload, {
attributes: true,
attributeFilter: ['disabled'],
});
inputTime.dispatchEvent(new Event('input', { bubbles: true }));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment