i have been using getColor() for a bit and would actually like to do getColor of an entire region to find a specific pixel to click it. is there an available function for this?
I believe this is what your looking for.
--- isTable
function isTable(t)
return type_Of(t) == "table"
end
function colorExists(obj, time)
time = time or 1
local timer = Timer()
local r, g, b
obj.diff = obj.diff or { 0, 0, 0 }
-- error
if not obj.color or not obj.location or not isTable(obj.color) or not isTable(obj.diff) then
print(obj)
scriptExit("colorExists: Obj bad format")
end
-- while in time
while true do
-- get location color
r, g, b = getColor(obj.location)
--compares diff by above or below the number, so {5,5,5} on diff would make it return true if the pixel color is within variance of 5 above or below rgb color
if math.abs(obj.color[1] - r) <= obj.diff[1] then
if math.abs(obj.color[2] - g) <= obj.diff[2] then
if math.abs(obj.color[3] - b) <= obj.diff[3] then
return true
end
end
end
--
r, g, b = nil, nil, nil
if timer:check() >= time then
break
end
end
return false
end
function getTargetType(range_x, range_y)
------- THESE ARE EXAMPLE COLORS -------
local white = {
location = Location(0, 0), --no need to know the locations, we set then according to our region search within the FOR loop
color = { 190, 190, 190 },
diff = { 20, 20, 20 },
}
--yellow
local yellow = {
location = Location(0, 0),
color = { 158, 148, 95 },
diff = { 18, 14, 7 },
}
--orange
local orange = {
location = Location(0, 0),
color = { 152, 75, 43 },
diff = { 14, 11, 9 },
}
--blue
local blue = {
location = Location(0, 0),
color = { 125, 130, 208 },
diff = { 19, 19, 9 },
}
--red
local red = {
location = Location(0, 0),
color = { 170, 20, 50 },
diff = { 15, 15, 15 },
}
local found = {}
local locs = {}
--Set your region to search in
--keep in mind, the bigger the region, more pixels to scan, slower speed
--so use the ranges to achieve speed but still have functionality
--if you used getTargetType(3,2) this would skip every 3 pixels on each x row, and skip every 2 pixels on each y column
--most accurate: getTargetType(1,1) but may be to slow if your region is huge
--faster: getTargetType(4,3) way faster but may miss the pixel color if its not common enough in the region
--gotta mess around with it, adapt to your needs.
local reg = Region(x,y,h,w) --set our region for searching
local range_x = range_x or 1
local range_y = range_y or 1
snapshotColor() --use snapshot for speed, so we take one single shot, then do all of our pixel searches on that same image
for x = reg.x, reg.x + reg.w, range_x do
for y = reg.y, reg.y + reg.h, range_y do
--set each colors new location for the current search loop
white.location = Location(x, y)
orange.location = Location(x, y)
yellow.location = Location(x, y)
blue.location = Location(x,y)
--if it finds the color within region will return true, or i use string ti return specific color name
if colorExists(orange, 0) then
usePreviousSnap(false)
--Console("ORANGE BOSS")
return "orange"
end
if colorExists(yellow, 0) then
usePreviousSnap(false)
--Console("YELLOW")
return "yellow"
end
if colorExists(blue, 0) then
usePreviousSnap(false)
--Console("YELLOW")
return "blue"
end
if colorExists(white, 0) then
usePreviousSnap(false)
--Console("WHITE")
return "white"
end
end
end
--didnt find any color, so we make sure to set snap to false and return false
usePreviousSnap(false)
return "false"
end