Hashtagphag

Hammer & Sickle

Apr 2nd, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var colors = [
  2. 5,5,5,5,5,5,5,5,5,5,5,5,5,3,3,5,5,5,5,5,5,5,5,5,5,5,//413
  3. 5,5,5,5,5,5,5,5,5,5,5,5,3,8,8,3,3,5,5,5,5,5,5,5,5,5,//414
  4. 5,5,5,5,5,5,5,5,5,5,5,5,5,3,3,8,8,3,3,5,5,5,5,5,5,5,//415
  5. 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,8,8,8,3,5,5,5,5,5,5,//416
  6. 5,5,5,5,5,5,5,5,5,3,5,5,5,5,5,5,3,8,8,8,3,3,5,5,5,5,//417
  7. 5,5,5,5,5,5,5,5,3,8,3,3,3,5,5,5,5,3,8,8,8,8,3,5,5,5,//418
  8. 5,5,5,5,5,5,5,3,8,8,8,8,8,3,5,5,5,5,3,8,8,8,8,3,5,5,//419
  9. 5,5,5,5,5,5,3,8,8,8,8,8,3,5,5,5,5,5,5,3,8,8,8,3,5,5,//420
  10. 5,5,5,5,5,3,8,8,8,8,8,3,5,5,5,5,5,5,5,5,3,8,8,8,3,5,//421
  11. 5,5,5,5,3,8,8,8,8,8,8,3,5,5,5,5,5,5,5,5,3,8,8,8,3,5,//422
  12. 5,5,5,3,8,8,8,8,8,8,8,8,3,5,5,5,5,5,5,5,5,3,8,8,8,3,//423
  13. 5,5,5,5,3,8,8,8,3,3,8,8,8,3,5,5,5,5,5,5,5,3,8,8,8,3,//424
  14. 5,5,5,5,5,3,8,3,5,5,3,8,8,8,3,5,5,5,5,5,5,3,8,8,8,3,//425
  15. 5,5,5,5,5,5,3,5,5,5,5,3,8,8,8,3,5,5,5,5,5,3,8,8,8,3,//426
  16. 5,5,5,5,5,5,5,5,5,5,5,5,3,8,8,8,3,5,5,5,5,3,8,8,8,3,//427
  17. 5,5,5,5,5,5,5,5,5,5,5,5,5,3,8,8,8,3,5,5,5,3,8,8,8,3,//428
  18. 5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,8,8,8,3,5,3,8,8,8,8,3,//429
  19. 5,5,5,5,5,5,3,3,3,5,5,5,5,5,5,3,8,8,8,3,8,8,8,8,8,3,//430
  20. 5,5,5,5,3,3,8,8,8,3,3,5,5,5,5,5,3,8,8,8,8,8,8,8,3,5,//431
  21. 5,5,5,3,8,8,8,8,8,8,8,3,3,3,3,3,3,3,8,8,8,8,8,8,3,5,//432
  22. 5,5,5,3,8,8,8,3,3,8,8,8,8,8,8,8,8,8,8,8,8,8,8,3,5,5,//433
  23. 5,5,3,8,8,8,8,3,5,3,8,8,8,8,8,8,8,8,8,8,8,8,8,8,3,5,//434
  24. 5,3,8,8,8,3,3,5,5,5,3,3,8,8,8,8,8,8,8,8,8,8,8,8,8,3,//435
  25. 3,8,8,8,3,5,5,5,5,5,5,5,3,3,3,3,3,3,3,3,3,8,8,8,8,3,//436
  26. 3,8,8,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,8,8,8,3,//437
  27. 5,3,3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,3,3,3,5,//438
  28. ];
  29. var colorsABGR = [];
  30.  
  31. var FULLY = {
  32.   x: 3,
  33.   y: 438,
  34.   width: 26,
  35.   height: 26
  36. };
  37.  
  38. var perfect_timeout = 60;
  39.  
  40. // hooks
  41. var client;
  42. var canvasse;
  43. var jQuery;
  44.  
  45. var currentDrawPosition = Math.floor(Math.random() * FULLY.width*FULLY.height);
  46. var currentLoop = 0;
  47.  
  48. r.placeModule("FULLY", function(e){
  49.   client = e("client");
  50.   canvasse = e("canvasse");
  51.   jQuery = e("jQuery");
  52.  
  53.   for(var i=0; i<client.palette.length; i++){
  54.     colorsABGR[i] = client.getPaletteColorABGR(i);
  55.   }
  56.  
  57.   attempt();
  58.  
  59. });
  60.  
  61. function attempt(){
  62.   console.log("tried to draw");
  63.   var toWait = client.getCooldownTimeRemaining();
  64.   if(toWait === 0)
  65.   {
  66.     tryDrawPixel();
  67.   }
  68.   else
  69.   {
  70.     setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  71.     console.log("set a timeout");
  72.   }
  73. }
  74.  
  75. function tryDrawPixel()
  76. {
  77.   var toWait = client.getCooldownTimeRemaining();
  78.   if(toWait === 0 && currentLoop < FULLY.width*FULLY.height)
  79.   {
  80.     currentLoop++;
  81.     console.log("checking pixel " + currentDrawPosition);
  82.     var targetPoint = getPoint(currentDrawPosition);
  83.     try{
  84.     $.get( "/api/place/pixel.json", { x:targetPoint.x, y:targetPoint.y }, function( data )
  85.     {
  86.       setTimeout(function() {
  87.         //wait an extra half second for reddits servers
  88.  
  89.  
  90.         console.log("x" + targetPoint.x + " y"+ targetPoint.y);
  91.         if (data.color == undefined)
  92.           data.color = 0;
  93.         canvasse.drawTileAt(data.x, data.y, colorsABGR[data.color]);
  94.         if (colors[currentDrawPosition] != data.color && colors[currentDrawPosition] !== -1)
  95.         {
  96.           client.setColor(colors[currentDrawPosition]);
  97.           client.drawTile(targetPoint.x, targetPoint.y);
  98.           console.log("drew pixel at " + targetPoint.x + "/" + targetPoint.y);
  99.           var toWait = client.getCooldownTimeRemaining();
  100.           setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  101.           currentLoop = 0;
  102.           console.log("set a timeout");
  103.         }
  104.         else
  105.         {
  106.           var positionIncrease = Math.floor(Math.random() * (Math.min(0.2*currentLoop, 40))) + 1;
  107.           currentDrawPosition += positionIncrease;
  108.           //console.log("" + currentLoop + ", " +positionIncrease);
  109.           if (currentDrawPosition >= FULLY.width*FULLY.height)
  110.             currentDrawPosition = Math.floor(Math.random() * FULLY.width*FULLY.height);
  111.           tryDrawPixel(currentDrawPosition);
  112.         }
  113.       }, 300);
  114.     });
  115.     }
  116.     catch(e){
  117.     alert("test");
  118.     }
  119.   }
  120.   else
  121.   {
  122.     var added_timeout = 0;
  123.     if (currentLoop == FULLY.width*FULLY.height)
  124.       added_timeout = perfect_timeout*1000;
  125.     setTimeout(attempt, toWait + Math.round(Math.random() * 1500) + added_timeout);
  126.     currentLoop = 0;
  127.     console.log("set a timeout");
  128.   }
  129.  
  130. }
  131.  
  132. function drawTest(){
  133.   for(var i=0; i < FULLY.width*FULLY.height; i++){
  134.     if(colors[i] === -1){
  135.       continue;
  136.     }
  137.     var targetPoint = getPoint(i);
  138.     canvasse.drawTileAt(targetPoint.x, targetPoint.y, colorsABGR[colors[i]]);
  139.   }
  140. }
  141.  
  142. function getPoint(i){
  143.   var x = i % FULLY.width;
  144.   return {
  145.     x: FULLY.x + x,
  146.     y: FULLY.y + (i - x) / FULLY.width - FULLY.height
  147.   };
  148. }
  149.  
  150. function getPixel(x, y){
  151.   return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)];
  152. }
Add Comment
Please, Sign In to add comment