diff --git a/main.js b/main.js index 6193aba..b9c707b 100644 --- a/main.js +++ b/main.js @@ -10,6 +10,37 @@ const targetColor = config.targetColor; const tolerance = config.tolerance; +setInterval(eatDrywall, photoInterval*1000); + +async function eatDrywall() { + let monitors = ss.Monitor.all(); + + monitors.forEach((i) => { + var im = i; + if (im.isPrimary){ + let image = im.captureImageSync(); + let img = image.toRawSync(); + clickRandomPixelOfColor(im.width, im.height, img); + } + }); +} + +function clickRandomPixelOfColor(width, height, image) { + + var hits = []; + for (let i = 0; i < width*height; i++) { + if (compareColors(targetColor,getPixel(i, image))) { + hits.push(i); + } + + } + 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); + proc.execSync("python click.py " + target.x + " " + target.y); +} + function rasterize(x, y, width){ //scale to image return (x + y * width); }