Advertisement
Guest User

paste

a guest
Apr 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. // Make setInterval still work when we aren't looking
  2. (function(s){var w,f={},o=window,l=console,m=Math,z='postMessage',p=0,r='hasOwnProperty',y=[].slice,x='fail',v=o.Worker;function d(){do{p=0x7FFFFFFF>p?p+1:0}while(f[r](p));return p}if(!/MSIE 10/i.test(navigator.userAgent)){try{s=o.URL.createObjectURL(new Blob(["var f={},p=postMessage,r='hasOwnProperty';onmessage=function(e){var d=e.data,i=d.i,t=d[r]('t')?d.t:0;switch(d.n){case'a':f[i]=setInterval(function(){p(i)},t);break;case'b':if(f[r](i)){clearInterval(f[i]);delete f[i]}break;case'c':f[i]=setTimeout(function(){p(i);if(f[r](i))delete f[i]},t);break;case'd':if(f[r](i)){clearTimeout(f[i]);delete f[i]}break}}"]))}catch(e){}}if(typeof(v)!=='undefined'){try{w=new v(s);o.setInterval=function(c,t){var i=d();f[i]={c:c,p:y.call(arguments,2)};w[z]({n:'a',i:i,t:t});return i};o.clearInterval=function(i){if(f[r](i))delete f[i],w[z]({n:'b',i:i})};o.setTimeout=function(c,t){var i=d();f[i]={c:c,p:y.call(arguments,2),t:!0};w[z]({n:'c',i:i,t:t});return i};o.clearTimeout=function(i){if(f[r](i))delete f[i],w[z]({n:'d',i:i})};w.onmessage=function(e){var i=e.data,c,n;if(f[r](i)){n=f[i];c=n.c;if(n[r]('t'))delete f[i]}if(typeof(c)=='string')try{c=new Function(c)}catch(k){}if(typeof(c)=='function')c.apply(o,n.p)}}catch(e){l.log(x)}}else l.log(x)})('http://colorthis.space/HackTimerWorker.min.js');
  3.  
  4. var colors = ["rgb(255, 255, 255)","rgb(228, 228, 228)","rgb(136, 136, 136)","rgb(34, 34, 34)","rgb(255, 167, 209)","rgb(229, 0, 0)","rgb(229, 149, 0)","rgb(160, 106, 66)","rgb(229, 217, 0)","rgb(148, 224, 68)","rgb(2, 190, 1)","rgb(0, 211, 221)","rgb(0, 131, 199)","rgb(0, 0, 234)","rgb(207, 110, 228)","rgb(130, 0, 128)"];
  5. var map = new Array(1000);
  6. for (var i = 0; i < map.length; i++) {
  7. map[i] = new Array(1000);
  8. }
  9.  
  10. function colorPixel(x, y, color){
  11. //console.log("x: "+x+", y: "+y+", color: "+color);
  12. map[y][x] = color;
  13. }
  14.  
  15. var myLastChange = [-1, -1];
  16. function tryColorPixel(x, y, color){
  17. x = Math.floor(x);
  18. y = Math.floor(y);
  19. colorPixel(x, y, color);
  20. lastPlaceTime = new Date().getTime();
  21. notified = false;
  22.  
  23. var array = new ArrayBuffer(5);
  24. var dv = new DataView(array);
  25. dv.setUint16(0, x);
  26. dv.setUint16(2, y);
  27. myLastChange = [x, y];
  28. dv.setUint8(4, color);
  29. connection.send(array);
  30. }
  31.  
  32. var connection;
  33.  
  34. function connectToServer(){
  35. if (connection != null) {
  36. connection.onopen = null;
  37. connection.onmessage = null;
  38. connection.onclose = null;
  39. connection.close();
  40. connection = null;
  41. }
  42. document.getElementById("console").innerHTML += "\nConnecting to colorthis.space:32432";
  43. connection = new WebSocket("ws://colorthis.space:32432");
  44. connection.binaryType = 'arraybuffer';
  45. connection.onopen = onopen;
  46. connection.onmessage = onmessage;
  47. connection.onclose = onclose;
  48. connection.onerror = function(evt) {
  49. document.getElementById("console").innerHTML += "\nThe following error occurred: " + evt.data;
  50. }
  51. }
  52.  
  53. connectToServer();
  54.  
  55. function onclose(e) {
  56. console.log('On close! ' + new Date().getTime());
  57. console.log(e);
  58. setTimeout(function() {
  59. connectToServer();
  60. }, 1000);
  61. }
  62.  
  63. function onopen() {
  64. document.getElementById("console").innerHTML += "\nonopen " + new Date().getTime();
  65. recievedMap = false;
  66. }
  67.  
  68. var editPlaces = [];
  69.  
  70. function onmessage(a) {
  71. var dv = new DataView(a.data);
  72. var index = 0;
  73. if (recievedMap){
  74. var x = dv.getUint16(index); index += 2; // x doubles as a category packet
  75. if (x <= 1000) {
  76. var y = dv.getUint16(index); index += 2;
  77. var type = dv.getUint8(index); index += 1;
  78. //console.log(x + " " + y + " " + type);
  79. colorPixel(x, y, type);
  80. if (myLastChange[0] != x || myLastChange[1] != y)
  81. editPlaces.push([x, y, type, new Date().getTime()]);
  82.  
  83. } else if (x == 1001){
  84. onlineCount = "Online: " + dv.getUint16(index); index += 2;
  85. }
  86. }else{
  87. document.getElementById("console").innerHTML += "\nrecievedMap " + new Date().getTime();
  88.  
  89. var done = 0;
  90. var last = -1;
  91. while (done < 1000*1000){
  92. var next = dv.getUint8(index++);
  93. if (next == 255){
  94. var count = dv.getUint8(index++);
  95. for (var i = 0; i < count; i++){
  96. colorPixel(Math.floor(done / 1000), done % 1000, last);
  97. done++;
  98. }
  99. } else {
  100. colorPixel(Math.floor(done / 1000), done % 1000, next);
  101. done++;
  102. last = next;
  103. }
  104. }
  105.  
  106. document.getElementById("console").innerHTML += "\nloaded map " + new Date().getTime();
  107. recievedMap = true;
  108. loop();
  109. }
  110. }
  111. var colorvals = [[255, 255, 255],[228, 228, 228],[136, 136, 136],[34, 34, 34],[255, 167, 209],[229, 0, 0],[229, 149, 0],[160, 106, 66],[229, 217, 0],[148, 224, 68],[2, 190, 1],[0, 211, 221],[0, 131, 199],[0, 0, 234],[207, 110, 228],[130, 0, 128]];
  112. var imageData=[[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3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5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]];
  113. var count = 0;
  114. var offsetX = 537;
  115. var offsetY = 160;
  116. function loop(){
  117. var x = count%imageData[0].length;
  118. var y = Math.floor((count/imageData.length))%24;
  119. count++;
  120. var curColor = map[offsetY + y][offsetX + x];
  121. var newColor = imageData[y%imageData.length][x%imageData[0].length];
  122. if (Math.random() < 0.8 || (curColor == newColor)){
  123. if (Math.random() < 0.05)
  124. setTimeout(loop, 0);
  125. else
  126. loop();
  127. return;
  128. }
  129. document.getElementById("console").innerHTML += "\nfilling " +(offsetX + x) + ", " + (y + offsetY) + " with color: " + newColor;
  130. tryColorPixel(offsetX + x, offsetY + y, newColor);
  131. if (Math.random() < 0.1) count = 0;
  132. setTimeout(loop, 5050);
  133. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement