eatdrywallbot/main.js
2025-04-08 20:35:26 -04:00

46 lines
982 B
JavaScript

const jimp = require("jimp");
const fs = require("fs");
let config = JSON.parse(fs.readFileSync("./config.jsonc"));
const photoInterval = config.photoInterval;
const targetColor = config.targetColor;
const tolerance = config.tolerance;
function rasterize(x, y, width){ //scale to image
return (x + y * width);
}
function deRasterize(i, width){
return ({
y: Math.floor(i/width),
x: i % width
});
}
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;
if (Math.abs(sum1-sum2) < (tolerance*4)) {
return true;
} else return false;
}
//gets color of a pixel at given coordinate
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]
};
return p;
}