utility function `pixelSearch()`
bryanlundberg opened this issue · 0 comments
bryanlundberg commented
Short overview
If we could input 2 absolute points directly and the color and let the function calculate the rest.
It only needs a formula like this creating the new Region: (x1, y1, x2 - x1, y2 - y1).
Use case
Simplicity, pixelWithColor comes with boilerplate, creating the color, creating the areas...
sample - idea
type Color = [number, number, number];
type Region = [number, number, number, number];
type PixelSearchParams = {
color: Color;
region: Region;
};
async function pixelSearch({ color, region }: PixelSearchParams): Promise<Point> {
try {
const customRegion= new Region(region[0], region[1], region[2] - region[0], region[3] - region[1]);
const customColor= new RGBA(color[0], color[1], color[2], 255);
const pixel = await screen.find(pixelWithColor(customColor), {
searchRegion: customRegion,
});
if (pixel) return pixel;
} catch (error) {
// handle error if needed
}
return { x: -1, y: -1 };
}
