Advertisement
Guest User

Javascript image bot for ourworldofpixels.com

a guest
Jan 20th, 2018
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var i,j,_i,_j,i_max,j_max,canDraw,draw;
  2. function drawImg(context, width, height){
  3.     i = (parseInt(document.getElementById("inputX").value)||0)-width / 2; //starting x-value
  4.     j = (parseInt( document.getElementById("inputY").value)||0)-height / 2; //starting y-value
  5.     _i = i;
  6.     _j = j;
  7.     i_max = i + width;
  8.     j_max = j + height;
  9.     canDraw=OWOP.net.protocol.placeBucket.canSpend(1);
  10.  
  11.     draw = setInterval(updateDraw, 20,context);
  12. }
  13.  
  14. function updateDraw(context){
  15.     canDraw=OWOP.net.protocol.placeBucket.allowance>=1;
  16.     OWOP.net.protocol.placeBucket.allowance+=(Date.now() -
  17.     OWOP.net.protocol.placeBucket.lastCheck) / 1000 * (OWOP.net.protocol.placeBucket.rate /
  18.     OWOP.net.protocol.placeBucket.time);
  19.     OWOP.net.protocol.placeBucket.lastCheck=Date.now();
  20.     if (OWOP.net.protocol.placeBucket.allowance > OWOP.net.protocol.placeBucket.rate) {
  21.         OWOP.net.protocol.placeBucket.allowance = OWOP.net.protocol.placeBucket.rate;
  22.     }
  23.     if(canDraw){
  24.         var pixelArray = context.getImageData(i - _i, j - _j, 1, 1).data;
  25.         if (pixelArray[3] > 25){
  26.             OWOP.net.protocol.updatePixel(i, j,pixelArray);
  27.         }
  28.         i++;
  29.         if (i > i_max){
  30.             j++;
  31.             i = _i;
  32.         }
  33.         if (j > j_max){
  34.             clearInterval(draw);
  35.         }
  36.     }
  37. }
  38. copier = {};
  39. copier.maxHeight = 50;
  40. copier.maxWidth = 50;
  41. copier.img = new Image();
  42. copier.img.onload = function() {
  43.     copier.canvas = document.createElement('canvas');
  44.     copier.canvas.width = this.width;
  45.     copier.canvas.height=this.height;
  46.     /*if (this.width > copier.maxWidth && this.height > copier.maxHeight){
  47.         if (this.width > this.height){
  48.             copier.canvas.width = Math.floor(copier.maxWidth);
  49.             copier.canvas.height = Math.floor((copier.maxWidth / this.width) * this.height);
  50.         }else{
  51.             copier.canvas.width = Math.floor((copier.maxHeight / this.height) * this.width);
  52.             copier.canvas.height = Math.floor(copier.maxHeight);
  53.         }
  54.     }else if (this.width > copier.maxWidth){
  55.         copier.canvas.width = Math.floor(copier.maxWidth);
  56.         copier.canvas.height = Math.floor((copier.maxWidth / this.width) * this.height);
  57.     }else if (this.height > copier.maxHeight){
  58.         copier.canvas.width = Math.floor((copier.maxHeight / this.height) * this.width);
  59.         copier.canvas.height = Math.floor(copier.maxHeight);
  60.     }else{
  61.         copier.canvas.width = Math.floor(copier.maxWidth);
  62.         copier.canvas.height = Math.floor(copier.maxHeight);
  63.     }*/
  64.     copier.ctx = copier.canvas.getContext('2d');
  65.     copier.ctx.drawImage(copier.img, 0, 0, copier.canvas.width, copier.canvas.height);
  66.     drawImg(copier.canvas.getContext('2d'), copier.canvas.width, copier.canvas.height);
  67. };
  68. function encodeImageFile(){
  69.     var filesSelected = document.getElementById("inputFileToLoad").files;
  70.     if (filesSelected.length > 0){
  71.         var fileToLoad = filesSelected[0];
  72.         var fileReader = new FileReader();
  73.         fileReader.onload = function(fileLoadedEvent) {
  74.             let src = fileLoadedEvent.target.result;
  75.             copier.img.src = src;
  76.             console.log(src);
  77.         };
  78.     }
  79.     fileReader.readAsDataURL(fileToLoad);
  80. }
  81. (function styleInit() {
  82.     var head=document.getElementsByTagName('head')[0];
  83.         if (!head) {
  84.             return;
  85.         }
  86.     addGlobalStyle(`#styleSetting{padding: 0.2em; margin:0.2em;
  87.     position: absolute;bottom: 0;right:20px;width: 20%;
  88.     background-color: rgba(0,200,200,0.1);display:block;}
  89.     table{text-align: center; width: 100%; height: 80%;}
  90.     td{padding: 0px 0.3em;border: 1px solid black;}`);
  91.     function addGlobalStyle(css) {
  92.         style = document.createElement('style');
  93.         style.type = 'text/css';
  94.         style.innerHTML = css;
  95.         head.appendChild(style);
  96.     }
  97. })();
  98. var temp = `<div id="styleSetting"><table>
  99. <tr><td><input id="inputFileToLoad" type="file" onchange="encodeImageFile();" />
  100. </td></tr><tr><td rowspan=2><input id="inputX" type="number" placeholder="X">
  101. <input id="inputY" type="number" placeholder="Y"></td></tr>
  102. <tr><td></td></tr></table></div>`;
  103. document.querySelector('body').insertAdjacentHTML('beforeend', temp);
  104. document.getElementById("inputFileToLoad").onchange=encodeImageFile;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement