Find Color - Color Offset Mode (screen.find_color)
Declaration
x, y = screen.find_color({
[find_all = boolean,]
[max_results = integer_value,]
[max_miss = integer_value,]
{x0, y0, {color0[, offset0]}},
{dx*, dy*, {color*[, offset*]}},
{dx*, dy*, {color*[, offset*]}},
...
}[, left, top, right, bottom ])
Parameters
- find_all
Boolean, optional. When true, returns a table of all match positions within the region, format{{x1, y1}, {x2, y2}, ...}
. Default false. - max_results
Integer, optional. The maximum number of results whenfind_all
is true. Up to 1000, default 100. - max_miss
Integer, optional. Maximum number of non-matching points allowed. Default 0 (all points must match). - x0, y0
Integer. Starting anchor coordinate. It does not limit search to that fixed point; it serves as the base for offset positions. If unsure, use 0, 0. - color0
Integer. Color to match at the starting point. - offset0
Integer. Max color offset (or bias). A value greater than0xff000000
means inverse matching. - dx*, dy*
Integer. Offset coordinate relative to the starting point. - color*
Integer. Expected color at the offset point. - offset*
Integer. Max color offset (or bias) at the offset point. A value greater than0xff000000
means inverse matching. - left, top, right, bottom
Integer, optional. Search region. Default is full screen.
Returns
- x, y
Integer. The coordinate of the first matched multi-point structure. Returns -1, -1 on failure.
Description
Find the position of the first fully matched multi-point color structure using color-offset mode.
Color offset (bias) represents a range of acceptable colors. For color
0x456789
with offset0x123456
, the ranges are:
Red:0x45 ± 0x12
, Green:0x67 ± 0x34
, Blue:0x89 ± 0x56
.Use
0x
prefix for hex numbers.
Example
x, y = screen.find_color({
{ 0, 0, {0xec1c23, 0x000000}},
{ 12, -3, {0xffffff, 0x101010}},
{ 5, -18, {0x00adee, 0x123456}},
{ -1, -10, {0xffc823, 0x101001}},
{ 2, -34, {0xa78217, 0x101001}},
{ 12, -55, {0xd0d2d2, 0x101001}},
}, 0, 0, 100, 100)
--
-- Equivalent form with absolute coords:
--
x, y = screen.find_color({
{ 509, 488, {0xec1c23, 0x000000}},
{ 521, 485, {0xffffff, 0x101010}},
{ 514, 470, {0x00adee, 0x123456}},
{ 508, 478, {0xffc823, 0x101001}},
{ 511, 454, {0xa78217, 0x101001}},
{ 521, 433, {0xd0d2d2, 0x101001}},
}, 0, 0, 100, 100)
--
-- One-line compact form:
--
x, y = screen.find_color({ {0,0,{0xec1c23,0x000000} },{12,-3, {0xffffff,0x101010} },{5,-18, {0x00adee,0x123456} },{-1,-10,{0xffc823,0x101001} },{2,-34,{0xa78217,0x101001} },{12,-55,{0xd0d2d2,0x101001} }, },0,0,100,100)
--
-- Inverse matching demo (run on iPhone 5C home screen for results):
x, y = screen.find_color({
{ 516, 288, {0xffffff, 0x101010} },
{ 519, 286, {0xffffff, 0x101010} },
{ 521, 289, {0xffffff, 0x101010} },
{ 516, 296, {0xffffff, 0x101010} },
{ 522, 297, {0xffffff, 0x101010} },
{ 520, 295, {0xffffff, 0xff101010} },
{ 515, 291, {0xffffff, 0xff101010} },
{ 518, 284, {0xffffff, 0xff101010} },
{ 523, 298, {0xffffff, 0xff101010} },
{ 514, 298, {0xffffff, 0xff101010} },
{ 514, 296, {0xffffff, 0xff101010} },
})
--
-- Find-all demo (returns all positions):
results = screen.find_color({
{ 527, 278, {0xde1d26, 0x101010} },
{ 524, 285, {0x007aff, 0x101010} },
{ 555, 292, {0xe4ddc9, 0x101010} },
{ 536, 314, {0xffde02, 0x101010} },
{ 502, 291, {0xffde02, 0x101010} },
{ 502, 283, {0xe4ddc9, 0x101010} },
find_all = true,
})