Advertisement
HaydnG

Offline r/place script

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