shadertoy.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!DOCTYPE html>
  2. <html xmlns='http://www.w3.org/1999/xhtml' lang='' xml:lang=''>
  3. <head>
  4. <meta charset='utf-8' />
  5. <meta name='viewport' content='width=device-width, user-scalable=no' />
  6. <link id='-gd-engine-icon' rel='icon' type='image/png' href='favicon.png' />
  7. <title>shadertoy</title>
  8. <style type='text/css'>
  9. body {
  10. touch-action: none;
  11. margin: 0;
  12. border: 0 none;
  13. padding: 0;
  14. text-align: center;
  15. background-color: black;
  16. }
  17. #canvas {
  18. display: block;
  19. margin: 0;
  20. color: white;
  21. }
  22. #canvas:focus {
  23. outline: none;
  24. }
  25. .godot {
  26. font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
  27. color: #e0e0e0;
  28. background-color: #3b3943;
  29. background-image: linear-gradient(to bottom, #403e48, #35333c);
  30. border: 1px solid #45434e;
  31. box-shadow: 0 0 1px 1px #2f2d35;
  32. }
  33. /* Status display
  34. * ============== */
  35. #status {
  36. position: absolute;
  37. left: 0;
  38. top: 0;
  39. right: 0;
  40. bottom: 0;
  41. display: flex;
  42. justify-content: center;
  43. align-items: center;
  44. /* don't consume click events - make children visible explicitly */
  45. visibility: hidden;
  46. }
  47. #status-progress {
  48. width: 366px;
  49. height: 7px;
  50. background-color: #38363A;
  51. border: 1px solid #444246;
  52. padding: 1px;
  53. box-shadow: 0 0 2px 1px #1B1C22;
  54. border-radius: 2px;
  55. visibility: visible;
  56. }
  57. @media only screen and (orientation:portrait) {
  58. #status-progress {
  59. width: 61.8%;
  60. }
  61. }
  62. #status-progress-inner {
  63. height: 100%;
  64. width: 0;
  65. box-sizing: border-box;
  66. transition: width 0.5s linear;
  67. background-color: #202020;
  68. border: 1px solid #222223;
  69. box-shadow: 0 0 1px 1px #27282E;
  70. border-radius: 3px;
  71. }
  72. #status-indeterminate {
  73. visibility: visible;
  74. position: relative;
  75. }
  76. #status-indeterminate > div {
  77. width: 4.5px;
  78. height: 0;
  79. border-style: solid;
  80. border-width: 9px 3px 0 3px;
  81. border-color: #2b2b2b transparent transparent transparent;
  82. transform-origin: center 21px;
  83. position: absolute;
  84. }
  85. #status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); }
  86. #status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); }
  87. #status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); }
  88. #status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); }
  89. #status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); }
  90. #status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); }
  91. #status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); }
  92. #status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); }
  93. #status-notice {
  94. margin: 0 100px;
  95. line-height: 1.3;
  96. visibility: visible;
  97. padding: 4px 6px;
  98. visibility: visible;
  99. }
  100. </style>
  101. </head>
  102. <body>
  103. <canvas id='canvas'>
  104. HTML5 canvas appears to be unsupported in the current browser.<br />
  105. Please try updating or use a different browser.
  106. </canvas>
  107. <div id='status'>
  108. <div id='status-progress' style='display: none;' oncontextmenu='event.preventDefault();'><div id ='status-progress-inner'></div></div>
  109. <div id='status-indeterminate' style='display: none;' oncontextmenu='event.preventDefault();'>
  110. <div></div>
  111. <div></div>
  112. <div></div>
  113. <div></div>
  114. <div></div>
  115. <div></div>
  116. <div></div>
  117. <div></div>
  118. </div>
  119. <div id='status-notice' class='godot' style='display: none;'></div>
  120. </div>
  121. <script type='text/javascript' src='shadertoy.js'></script>
  122. <script type='text/javascript'>//<![CDATA[
  123. const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"shadertoy","experimentalVK":false,"fileSizes":{"shadertoy.pck":48160,"shadertoy.wasm":14406428},"gdnativeLibs":[]};
  124. var engine = new Engine(GODOT_CONFIG);
  125. (function() {
  126. const INDETERMINATE_STATUS_STEP_MS = 100;
  127. var statusProgress = document.getElementById('status-progress');
  128. var statusProgressInner = document.getElementById('status-progress-inner');
  129. var statusIndeterminate = document.getElementById('status-indeterminate');
  130. var statusNotice = document.getElementById('status-notice');
  131. var initializing = true;
  132. var statusMode = 'hidden';
  133. var animationCallbacks = [];
  134. function animate(time) {
  135. animationCallbacks.forEach(callback => callback(time));
  136. requestAnimationFrame(animate);
  137. }
  138. requestAnimationFrame(animate);
  139. function setStatusMode(mode) {
  140. if (statusMode === mode || !initializing)
  141. return;
  142. [statusProgress, statusIndeterminate, statusNotice].forEach(elem => {
  143. elem.style.display = 'none';
  144. });
  145. animationCallbacks = animationCallbacks.filter(function(value) {
  146. return (value != animateStatusIndeterminate);
  147. });
  148. switch (mode) {
  149. case 'progress':
  150. statusProgress.style.display = 'block';
  151. break;
  152. case 'indeterminate':
  153. statusIndeterminate.style.display = 'block';
  154. animationCallbacks.push(animateStatusIndeterminate);
  155. break;
  156. case 'notice':
  157. statusNotice.style.display = 'block';
  158. break;
  159. case 'hidden':
  160. break;
  161. default:
  162. throw new Error('Invalid status mode');
  163. }
  164. statusMode = mode;
  165. }
  166. function animateStatusIndeterminate(ms) {
  167. var i = Math.floor(ms / INDETERMINATE_STATUS_STEP_MS % 8);
  168. if (statusIndeterminate.children[i].style.borderTopColor == '') {
  169. Array.prototype.slice.call(statusIndeterminate.children).forEach(child => {
  170. child.style.borderTopColor = '';
  171. });
  172. statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
  173. }
  174. }
  175. function setStatusNotice(text) {
  176. while (statusNotice.lastChild) {
  177. statusNotice.removeChild(statusNotice.lastChild);
  178. }
  179. var lines = text.split('\n');
  180. lines.forEach((line) => {
  181. statusNotice.appendChild(document.createTextNode(line));
  182. statusNotice.appendChild(document.createElement('br'));
  183. });
  184. };
  185. function displayFailureNotice(err) {
  186. var msg = err.message || err;
  187. console.error(msg);
  188. setStatusNotice(msg);
  189. setStatusMode('notice');
  190. initializing = false;
  191. };
  192. if (!Engine.isWebGLAvailable()) {
  193. displayFailureNotice('WebGL not available');
  194. } else {
  195. setStatusMode('indeterminate');
  196. engine.startGame({
  197. 'onProgress': function (current, total) {
  198. if (total > 0) {
  199. statusProgressInner.style.width = current/total * 100 + '%';
  200. setStatusMode('progress');
  201. if (current === total) {
  202. // wait for progress bar animation
  203. setTimeout(() => {
  204. setStatusMode('indeterminate');
  205. }, 500);
  206. }
  207. } else {
  208. setStatusMode('indeterminate');
  209. }
  210. },
  211. }).then(() => {
  212. setStatusMode('hidden');
  213. initializing = false;
  214. }, displayFailureNotice);
  215. }
  216. })();
  217. //]]></script>
  218. </body>
  219. </html>