Advertisement
HaydnG

Offline Script

Apr 2nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Bottom left corner X*/
  2.   y: 984,  /*Bottom left corner Y*/
  3.   width: 78,  /*WIDTH OF IMAGE*/
  4.   height: 62  /*HEIGHT OF IMAGE*/
  5. };
  6.  
  7. var perfect_timeout = 60;
  8.  
  9. // hooks
  10. var client;
  11. var canvasse;
  12. var jQuery;
  13.  
  14. var currentDrawPosition = 0;
  15. var currentLoop = 0;
  16.  
  17. r.placeModule("babaevski", function(e){
  18.   client = e("client");
  19.   canvasse = e("canvasse");
  20.   jQuery = e("jQuery");
  21.  
  22.   for(var i=0; i<client.palette.length; i++){
  23.     colorsABGR[i] = client.getPaletteColorABGR(i);
  24.   }
  25.  
  26.   attempt();
  27.  
  28. });
  29.  
  30. function attempt(){
  31.   console.log("tried to draw");
  32.   tryDrawPixel();
  33.  
  34. }
  35.  
  36. function tryDrawPixel()
  37. {
  38.   if(currentLoop < babaevski.width*babaevski.height)
  39.   {
  40.     currentLoop++;
  41.     console.log("checking pixel " + currentDrawPosition);
  42.     var targetPoint = getPoint(currentDrawPosition);
  43.  
  44.       setTimeout(function() {
  45.         //wait an extra half second for reddits servers
  46.  
  47.  
  48.         console.log("x" + targetPoint.x + " y"+ targetPoint.y);
  49.         canvasse.drawTileAt(targetPoint.x, targetPoint.y, colorsABGR[colors[currentDrawPosition]]);
  50.  
  51.           client.setColor(colors[currentDrawPosition]);
  52.           console.log("drew pixel at " + targetPoint.x + "/" + targetPoint.y);
  53.           currentLoop = 0;
  54.        
  55.           var positionIncrease = Math.floor(Math.random() * (Math.min(0.2*currentLoop, 40))) + 1;
  56.           currentDrawPosition += positionIncrease;
  57.           //console.log("" + currentLoop + ", " +positionIncrease);
  58.           if (currentDrawPosition >= babaevski.width*babaevski.height)
  59.             currentDrawPosition = 0;
  60.           tryDrawPixel(currentDrawPosition);
  61.        
  62.       }, 1);
  63.  
  64.   }
  65.   else
  66.   {
  67.     var added_timeout = 0;
  68.     if (currentLoop == babaevski.width*babaevski.height)
  69.     currentLoop = 0;
  70.  
  71.   }
  72.  
  73. }
  74.  
  75. function drawTestRTC(){
  76.   for(var i=0; i < babaevski.width*babaevski.height; i++){
  77.     if(colors[i] === -1){
  78.       continue;
  79.     }
  80.     var targetPoint = getPoint(i);
  81.     canvasse.drawTileAt(targetPoint.x, targetPoint.y, colorsABGR[colors[i]]);
  82.   }
  83. }
  84.  
  85. function getPoint(i){
  86.   var x = i % babaevski.width;
  87.   return {
  88.     x: babaevski.x + x,
  89.     y: babaevski.y + (i - x) / babaevski.width - babaevski.height
  90.   };
  91. }
  92.  
  93. function getPixel(x, y){
  94.   return canvasse.writeBuffer[canvasse.getIndexFromCoords(x, y)];
  95. }
  96.  
  97. //Updated by haydnG (hayhay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement