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,3,3,3,3,3,7,7,7,7,7,7,7,7,7,3,3,3,7,7,7,7,7,3,3,3,3,3,3,3,3,
  50. 3,3,3,3,3,3,3,3,3,3,7,7,7,3,3,3,3,3,7,7,7,3,3,3,3,3,7,7,7,7,7,3,3,3,3,3,3,3,3,3,
  51. 3,3,3,3,3,3,3,3,3,3,6,7,7,7,3,3,3,3,3,3,3,3,3,3,3,7,7,7,7,7,7,3,3,3,3,3,3,3,3,3,
  52.  
  53. ];
  54. var colorsABGR = [];
  55.  
  56. //x/y is the lower left (or maybe 1 pixel below? fuck knows, check with drawTestImage() if you got it right)
  57. var image = {
  58.   x: 240,
  59.   y: 775,
  60.   width: 40,
  61.   height: 50
  62. };
  63.  
  64. var perfect_timeout = 60;
  65.  
  66. //update timeout for poor reddit servers (ms)
  67. var get_delay = 500;
  68.  
  69. //always check the next pixel or increasingly skip more each loop?
  70. //might help performance if many people run it
  71. var use_skipping = false;
  72. var skipping_max = 20;
  73.  
  74.  
  75. // hooks
  76. var client;
  77. var canvasse;
  78. var jQuery;
  79.  
  80. //will start here the first time
  81. var currentDrawPosition = 2;
  82.  
  83. var currentLoop = 0;
  84.  
  85. r.placeModule("image", function(e){
  86.   client = e("client");
  87.   canvasse = e("canvasse");
  88.   jQuery = e("jQuery");
  89.  
  90.   for(var i=0; i<client.palette.length; i++){
  91.     colorsABGR[i] = client.getPaletteColorABGR(i);
  92.   }
  93.  
  94.   startup();
  95.  
  96. });
  97.  
  98.  
  99. function startup()
  100. {
  101.   console.log("skipping to first wrong pixel");
  102.   var toWait = client.getCooldownTimeRemaining();
  103.   for(var i = currentDrawPosition; i < image.width*image.height; i++){
  104.     if(colors[i] === -1){
  105.       continue;
  106.     }
  107.     var targetPoint = getPoint(i);
  108.     var pixelColor = getPixel(targetPoint.x, targetPoint.y);
  109.     if(pixelColor !== colorsABGR[colors[i]]){
  110.         currentDrawPosition = i;
  111.         console.log("starting at " + currentDrawPosition);
  112.         break;
  113.     }
  114.   }
  115.   setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  116.  
  117. }
  118.  
  119.  
  120.  
  121. function attempt(){
  122.   console.log("tried to draw");  
  123.   var toWait = client.getCooldownTimeRemaining();
  124.   if(toWait === 0)
  125.   {
  126.     tryDrawPixel();
  127.   }
  128.   else
  129.   {
  130.     setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  131.     console.log("set a timeout");
  132.   }
  133. }
  134.  
  135. function tryDrawPixel()
  136. {
  137.   var toWait = client.getCooldownTimeRemaining();
  138.   if(toWait === 0 && currentLoop < image.width*image.height)
  139.   {
  140.     currentLoop++;
  141.     console.log("checking pixel " + currentDrawPosition);
  142.     var targetPoint = getPoint(currentDrawPosition);
  143.    
  144.     $.get( "/api/place/pixel.json", { x:targetPoint.x, y:targetPoint.y }, function( data )
  145.     {
  146.       setTimeout(function() {
  147.         //wait an extra half second for reddits servers
  148.        
  149.      
  150.         console.log("x" + targetPoint.x + " y"+ targetPoint.y);
  151.         if (data.color == undefined)
  152.           data.color = 0;
  153.         canvasse.drawTileAt(data.x, data.y, colorsABGR[data.color]);
  154.         if (colors[currentDrawPosition] != data.color && colors[currentDrawPosition] !== -1)
  155.         {
  156.           client.setColor(colors[currentDrawPosition]);
  157.           client.drawTile(targetPoint.x, targetPoint.y);
  158.           console.log("drew pixel at " + targetPoint.x + "/" + targetPoint.y);
  159.           var toWait = client.getCooldownTimeRemaining();
  160.           setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  161.           currentLoop = 0;
  162.           console.log("set a timeout");
  163.         }
  164.         else
  165.         {
  166.           var positionIncrease = 1;
  167.           if (use_skipping == true)
  168.           {
  169.             positionIncrease = Math.floor(Math.random() * (Math.min(0.2*currentLoop, skipping_max))) + 1;
  170.           }
  171.           currentDrawPosition += positionIncrease;
  172.           if (currentDrawPosition >= image.width*image.height)
  173.             currentDrawPosition = 0;
  174.           tryDrawPixel(currentDrawPosition);
  175.         }
  176.       }, get_delay);
  177.     });
  178.   }
  179.   else
  180.   {
  181.     var added_timeout = 0;
  182.     if (currentLoop == image.width*image.height)
  183.       added_timeout = perfect_timeout*1000;
  184.     setTimeout(attempt, toWait + Math.round(Math.random() * 1500) + added_timeout);
  185.     currentLoop = 0;
  186.     console.log("set a timeout");
  187.   }
  188.  
  189. }
  190.  
  191. function drawTestImage(){
  192.   for(var i=0; i < image.width*image.height; i++){
  193.     if(colors[i] === -1){
  194.       continue;
  195.     }
  196.     var targetPoint = getPoint(i);
  197.     canvasse.drawTileAt(targetPoint.x, targetPoint.y, colorsABGR[colors[i]]);
  198.   }
  199. }
  200.  
  201. function getPoint(i){
  202.   var x = i % image.width;
  203.   return {
  204.     x: image.x + x,
  205.     y: image.y + (i - x) / image.width - image.height
  206.   };
  207. }
  208.  
  209. function getPixel(x, y){
  210.   return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)];
  211. }
Advertisement
Add Comment
Please, Sign In to add comment