animator.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>👾 Useless Robot Animator</title>
  7. <script src="./jquery.min.js"></script>
  8. <style>
  9. .circle {
  10. width: 20px;
  11. height: 20px;
  12. background-color: #525050;
  13. border-radius: 50%;
  14. display: inline-block;
  15. margin: 2px;
  16. cursor: pointer;
  17. }
  18. .circle.centerleft{
  19. border-right: 1px solid white;
  20. }
  21. .circle.centerright{
  22. border-left: 1px solid white;
  23. }
  24. .circle.active{
  25. background-color: #f55142;
  26. }
  27. #grid-container {
  28. display: flex;
  29. position: relative;
  30. flex-wrap: wrap;
  31. width: calc(32 * (20px + 2px * 2));
  32. }
  33. #dotmatrix{
  34. display: flex;
  35. flex-wrap: wrap;
  36. }
  37. html, body {
  38. height: 100%;
  39. margin: 0;
  40. display: flex;
  41. align-items: center;
  42. justify-content: center;
  43. background-color: #242424;
  44. font-family: Verdana, sans-serif;
  45. color: white;
  46. }
  47. .matrixModule{
  48. position: absolute;
  49. border: 1px solid #a3a3a3;
  50. width: calc(24px * 8);
  51. height: calc(24px * 8);
  52. pointer-events: none;
  53. }
  54. .matrixModule.one {
  55. top: 0;
  56. left: 0;
  57. }
  58. .matrixModule.two {
  59. top: 0;
  60. left: 192px;
  61. }
  62. .matrixModule.three {
  63. top: 0;
  64. left: 384px;
  65. }
  66. .matrixModule.four {
  67. top: 0;
  68. left: 576px;
  69. }
  70. .matrixModule.five {
  71. top: 192px;
  72. left: 0px;
  73. }
  74. .matrixModule.six {
  75. top: 192px;
  76. left: 192px;
  77. }
  78. .matrixModule.seven {
  79. top: 192px;
  80. left: 384px;
  81. }
  82. .matrixModule.eight {
  83. top: 192px;
  84. left: 576px;
  85. }
  86. button{
  87. background-color: white;
  88. color: #3b3b3b;
  89. border-radius: 0em;
  90. box-shadow: none;
  91. padding-top: 0.4em;
  92. padding-bottom: 0.4em;
  93. padding-left: 1em;
  94. padding-right: 1em;
  95. cursor: pointer;
  96. margin: 0.4em;
  97. margin-top: 0.6em;
  98. }
  99. </style>
  100. </head>
  101. <body>
  102. <div id="grid-container">
  103. <div id="layout">
  104. <div class="matrixModule one"></div>
  105. <div class="matrixModule two"></div>
  106. <div class="matrixModule three"></div>
  107. <div class="matrixModule four"></div>
  108. <div class="matrixModule five"></div>
  109. <div class="matrixModule six"></div>
  110. <div class="matrixModule seven"></div>
  111. <div class="matrixModule eight"></div>
  112. </div>
  113. <div id="dotmatrix"></div>
  114. <br>
  115. <div style="width: 100%; padding: 1em; ">
  116. <div style="float: right;">
  117. <button onclick="clearScreen();">Clear</button>
  118. <button onclick="loadDefault();">Load Default</button>
  119. <button onclick="downloadBinary();">Export Binary</button>
  120. <button onclick="openFilePicker()">Import Binary</button>
  121. <input type="file" id="fileInput" style="display: none;" accept=".bin" onchange="handleFile(event)">
  122. </div>
  123. <div style="padding-top: 0.8em;">
  124. 👾 Cute Useless Robot Animator
  125. </div>
  126. </div>
  127. </div>
  128. <script>
  129. let defaultTemplate = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,1,0,0,1,0,0,1,0,0,0,0,1,1,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  130. function generateCircleGrid(containerId) {
  131. const container = document.getElementById(containerId);
  132. if (!container) {
  133. console.error(`No element found with id "${containerId}"`);
  134. return;
  135. }
  136. // Clear the container if it already has content
  137. container.innerHTML = '';
  138. // Create a grid of circles
  139. const rows = 16;
  140. const cols = 32;
  141. for (let i = 0; i < rows; i++) {
  142. for (let j = 0; j < cols; j++) {
  143. $(container).append('<div class="circle" onClick="toggleThis(this);"></div>');
  144. }
  145. }
  146. }
  147. function getFrameAsIntArray(){
  148. let results = [];
  149. $(".circle").each(function(){
  150. let isActive = $(this).hasClass("active");
  151. if (isActive){
  152. results.push(1);
  153. }else{
  154. results.push(0);
  155. }
  156. });
  157. return results;
  158. }
  159. function drawFrameFromIntArray(frameArray){
  160. let counter = 0;
  161. $(".circle").each(function(){
  162. if (frameArray[counter] != undefined){
  163. let isActive = frameArray[counter] == 1;
  164. if (isActive){
  165. $(this).addClass('active');
  166. }else{
  167. $(this).removeClass('active');
  168. }
  169. }
  170. counter++;
  171. });
  172. }
  173. function loadDefault(){
  174. drawFrameFromIntArray(defaultTemplate);
  175. }
  176. function downloadBinary(){
  177. const bitArray = getFrameAsIntArray();
  178. const byteArray = [];
  179. for (let i = 0; i < bitArray.length; i += 8) {
  180. let byte = 0;
  181. for (let j = 0; j < 8; j++) {
  182. if (bitArray[i + j]) {
  183. byte |= 1 << (7 - j);
  184. }
  185. }
  186. byteArray.push(byte);
  187. }
  188. const blob = new Blob([new Uint8Array(byteArray)], { type: 'application/octet-stream' });
  189. const url = URL.createObjectURL(blob);
  190. const a = document.createElement('a');
  191. a.href = url;
  192. a.download = 'frame.bin';
  193. document.body.appendChild(a);
  194. a.click();
  195. document.body.removeChild(a);
  196. URL.revokeObjectURL(url);
  197. }
  198. function toggleThis(led){
  199. if (!$(led).hasClass('active')){
  200. $(led).addClass('active');
  201. }else{
  202. $(led).removeClass('active');
  203. }
  204. }
  205. // Call the function to generate the grid
  206. generateCircleGrid('dotmatrix');
  207. function clearScreen(){
  208. $(".circle.active").removeClass("active");
  209. }
  210. //Import functions
  211. function openFilePicker() {
  212. document.getElementById('fileInput').click();
  213. }
  214. function handleFile(event) {
  215. const file = event.target.files[0];
  216. if (file) {
  217. const reader = new FileReader();
  218. reader.onload = function(e) {
  219. const arrayBuffer = e.target.result;
  220. const byteArray = new Uint8Array(arrayBuffer);
  221. const bitArray = [];
  222. for (let byte of byteArray) {
  223. for (let i = 7; i >= 0; i--) {
  224. bitArray.push((byte >> i) & 1);
  225. }
  226. }
  227. renderBitArray(bitArray);
  228. };
  229. reader.readAsArrayBuffer(file);
  230. }
  231. }
  232. function renderBitArray(bitArray) {
  233. drawFrameFromIntArray(bitArray);
  234. }
  235. </script>
  236. </body>
  237. </html>