Guest User

Untitled

a guest
Jul 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. (() => {
  2. const timeIncrements = Number.parseFloat(window.prompt("Time increments", 0.01));
  3. const frameCount = Number.parseInt(window.prompt("Frame count", 60 * 10));
  4.  
  5. const buttonDownload = document.querySelector('[data-ref="button-download"]');
  6. const inputSeed = document.getElementById('input-seed');
  7. const inputSharpness = document.getElementById('input-sharpness');
  8. const inputTime = document.getElementById('input-time');
  9.  
  10. let frames = 0;
  11.  
  12. const download = (filename) => {
  13. const canvas = document.querySelector('[data-component="image-renderer"]');
  14.  
  15. const anchor = document.createElement('a');
  16. anchor.style.display = 'none';
  17. anchor.download = filename;
  18. anchor.href = canvas.toDataURL('image/png');;
  19.  
  20. // Link has to be attached to DOM to work in Firefox
  21. document.body.appendChild(anchor);
  22.  
  23. // fire click
  24. anchor.click();
  25.  
  26. // Link has to be attached to DOM to work in Firefox
  27. requestAnimationFrame(() => document.body.removeChild(anchor));
  28. };
  29.  
  30. const observer = new MutationObserver((mutationsList) => mutationsList.forEach((mutation) => {
  31. if (buttonDownload.disabled) return;
  32.  
  33. const id = frames.toString().padStart(8, '0');
  34.  
  35. download(`${id}-${inputSeed.value}-${inputSharpness.value}.png`);
  36.  
  37. inputTime.value = (Number.parseFloat(inputTime.value) + timeIncrements).toFixed(4);
  38. inputTime.dispatchEvent(new Event('input', { bubbles: true }));
  39.  
  40. if (++frames === frameCount) {
  41. observer.disconnect();
  42. }
  43. }));
  44.  
  45. observer.observe(buttonDownload, {
  46. attributes: true,
  47. attributeFilter: ['disabled'],
  48. });
  49.  
  50. inputTime.dispatchEvent(new Event('input', { bubbles: true }));
  51. })();
Add Comment
Please, Sign In to add comment