diff --git a/main.js b/main.js index 8740ac6..03bff76 100644 --- a/main.js +++ b/main.js @@ -12,14 +12,14 @@ const targetColor = config.targetColor; const tolerance = config.tolerance; -setInterval(eatDrywall, photoInterval*1000); +setInterval(eatDrywall, photoInterval * 1000); async function eatDrywall() { let monitors = ss.Monitor.all(); - monitors.forEach((i) => { + monitors.forEach((i) => { var im = i; - if (im.isPrimary){ + if (im.isPrimary) { let image = im.captureImageSync(); let img = image.toRawSync(); clickRandomPixelOfColor(im.width, im.height, img); @@ -30,8 +30,8 @@ async function eatDrywall() { function clickRandomPixelOfColor(width, height, image) { var hits = []; - for (let i = 0; i < width*height; i++) { - if (compareColors(targetColor,getPixel(i, image))) { + for (let i = 0; i < width * height; i++) { + if (compareColors(targetColor, getPixel(i, image))) { hits.push(i); } @@ -39,40 +39,40 @@ function clickRandomPixelOfColor(width, height, image) { let click = Math.floor(Math.random() * hits.length); //get index of random viable pixel let target = deRasterize(hits[click], width);//get coordinates of random pixel - console.log("Clicking: " + target); + console.log("Clicking: " + target); proc.execSync("python click.py " + target.x + " " + target.y); } -function rasterize(x, y, width){ //scale to image +function rasterize(x, y, width) { //scale to image return (x + y * width); } -function deRasterize(i, width){ +function deRasterize(i, width) { return ({ - y: Math.floor(i/width), + y: Math.floor(i / width), x: i % width }); } -function compareColors(c1,c2){ //compare two rgba color structs - //general basic distance nothing too special +function compareColors(c1, c2) { //compare two rgba color structs + //general basic distance nothing too special - let sum1 = c1.r + c1.g + c1.b + c1.a; - let sum2 = c2.r + c2.g + c2.b + c2.a; + let sum1 = c1.r + c1.g + c1.b + c1.a; + let sum2 = c2.r + c2.g + c2.b + c2.a; - if (Math.abs(sum1-sum2) < (tolerance*4)) { - return true; - } else return false; + if (Math.abs(sum1 - sum2) < (tolerance * 4)) { + return true; + } else return false; } //gets color of a pixel at given coordinate -function getPixel(pos,img) { +function getPixel(pos, img) { //pixel origin let o = pos * 4; let p = { r: img[o], - g: img[o+1], - b: img[o+2], - a: img[o+3] + g: img[o + 1], + b: img[o + 2], + a: img[o + 3] }; return p;