current interaction and scanning logic
This commit is contained in:
parent
fd4e2b2905
commit
d3e9b24631
31
main.js
31
main.js
@ -10,6 +10,37 @@ const targetColor = config.targetColor;
|
|||||||
const tolerance = config.tolerance;
|
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
|
function rasterize(x, y, width){ //scale to image
|
||||||
return (x + y * width);
|
return (x + y * width);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user