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,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. var babaevski = {
  57.   x: 240,
  58.   y: 775,
  59.   width: 40,
  60.   height: 50
  61. };
  62.  
  63. var perfect_timeout = 60;
  64.  
  65. // hooks
  66. var client;
  67. var canvasse;
  68. var jQuery;
  69.  
  70. var currentDrawPosition = babaevski.width*babaevski.height / 2;
  71. var currentLoop = 0;
  72.  
  73. r.placeModule("babaevski", function(e){
  74.   client = e("client");
  75.   canvasse = e("canvasse");
  76.   jQuery = e("jQuery");
  77.  
  78.   for(var i=0; i<client.palette.length; i++){
  79.     colorsABGR[i] = client.getPaletteColorABGR(i);
  80.   }
  81.  
  82.   attempt();
  83.  
  84. });
  85.  
  86. function attempt(){
  87.   console.log("tried to draw");  
  88.   var toWait = client.getCooldownTimeRemaining();
  89.   if(toWait === 0)
  90.   {
  91.     tryDrawPixel();
  92.   }
  93.   else
  94.   {
  95.     setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  96.     console.log("set a timeout");
  97.   }
  98. }
  99.  
  100. function tryDrawPixel()
  101. {
  102.   var toWait = client.getCooldownTimeRemaining();
  103.   if(toWait === 0 && currentLoop < babaevski.width*babaevski.height)
  104.   {
  105.     currentLoop++;
  106.     console.log("checking pixel " + currentDrawPosition);
  107.     var targetPoint = getPoint(currentDrawPosition);
  108.    
  109.     $.get( "/api/place/pixel.json", { x:targetPoint.x, y:targetPoint.y }, function( data )
  110.     {
  111.       setTimeout(function() {
  112.         //wait an extra half second for reddits servers
  113.        
  114.      
  115.         console.log("x" + targetPoint.x + " y"+ targetPoint.y);
  116.         if (data.color == undefined)
  117.           data.color = 0;
  118.         canvasse.drawTileAt(data.x, data.y, colorsABGR[data.color]);
  119.         if (colors[currentDrawPosition] != data.color && colors[currentDrawPosition] !== -1)
  120.         {
  121.           client.setColor(colors[currentDrawPosition]);
  122.           client.drawTile(targetPoint.x, targetPoint.y);
  123.           console.log("drew pixel at " + targetPoint.x + "/" + targetPoint.y);
  124.           var toWait = client.getCooldownTimeRemaining();
  125.           setTimeout(attempt, toWait + Math.round(Math.random() * 1500));
  126.           currentLoop = 0;
  127.           console.log("set a timeout");
  128.         }
  129.         else
  130.         {
  131.           var positionIncrease = Math.floor(Math.random() * (Math.min(0.2*currentLoop, 40))) + 1;
  132.           currentDrawPosition += positionIncrease;
  133.           //console.log("" + currentLoop + ", " +positionIncrease);
  134.           if (currentDrawPosition >= babaevski.width*babaevski.height)
  135.             currentDrawPosition = 0;
  136.           tryDrawPixel(currentDrawPosition);
  137.         }
  138.       }, 300);
  139.     });
  140.   }
  141.   else
  142.   {
  143.     var added_timeout = 0;
  144.     if (currentLoop == babaevski.width*babaevski.height)
  145.       added_timeout = perfect_timeout*1000;
  146.     setTimeout(attempt, toWait + Math.round(Math.random() * 1500) + added_timeout);
  147.     currentLoop = 0;
  148.     console.log("set a timeout");
  149.   }
  150.  
  151. }
  152.  
  153. function drawTestRTC(){
  154.   for(var i=0; i < babaevski.width*babaevski.height; i++){
  155.     if(colors[i] === -1){
  156.       continue;
  157.     }
  158.     var targetPoint = getPoint(i);
  159.     canvasse.drawTileAt(targetPoint.x, targetPoint.y, colorsABGR[colors[i]]);
  160.   }
  161. }
  162.  
  163. function getPoint(i){
  164.   var x = i % babaevski.width;
  165.   return {
  166.     x: babaevski.x + x,
  167.     y: babaevski.y + (i - x) / babaevski.width - babaevski.height
  168.   };
  169. }
  170.  
  171. function getPixel(x, y){
  172.   return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)];
  173. }
Advertisement
Add Comment
Please, Sign In to add comment