(Note: this solution assumes that you wanted Lerping and comparisons with RGB isn’t very easy, however if we convert the color to HSV then comparisons become easy. HSV is Hue, Saturation, and Value. Hue controls the color, Saturation controls how much of that color is present (minimum is grayscale, while maximum is full color), and Value is the brightness. Here are your colors converted to HSV:
<0, 0, 0> → <0, 0, 0>
<200, 200, 200> → <0, 0, 78>
<100, 100, 100> → <0, 0, 39> (note, 78 / 2)
<47, 47, 47> → <0, 0, 18> (since a byte is used for each value, 47.3 is not possible but 47 is)
Now comparing if they are the same color (same hue and optionally the same saturation) with a value in the range of 0 to 200 is easy. We can even see if it is close to the same hue in case of some rounding errors. For the other two colors you gave:
<45, 47, 49> → <210, 8, 19>
<202, 202, 202> → <0, 0, 79>
Since the first isn’t the same color and the second isn’t in the given value range then neither of these are a lerp between <0, 0, 0> and <0, 0, 78>.
This would also work if you had two colors with different hues or saturation. You’d simply make sure that the lerped color’s hue and saturation are between the original colors’ hues and saturations.
Here are what the RGB and HSV color spaces look like:
If you pay attention, you’ll note that this method forms a rectangular prism in the HSV space rather than a line in the RGB space. As a result, you have more control over what types of colors you accept as a lerp. You can disregard the brightness, only care about the hue, or require a saturation in a range.
Now, to convert from RGB to HSV we need this function which I got from here: https://github.com/EmmanuelOga/columns/blob/master/utils/color.lua
--[[
* Converts an RGB color value to HSV. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSV_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and v in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSV representation
]]
function rgbToHsv(r, g, b, a)
r, g, b, a = r / 255, g / 255, b / 255, a / 255
local max, min = math.max(r, g, b), math.min(r, g, b)
local h, s, v
v = max
local d = max - min
if max == 0 then s = 0 else s = d / max end
if max == min then
h = 0 -- achromatic
else
if max == r then
h = (g - b) / d
if g < b then h = h + 6 end
elseif max == g then h = (b - r) / d + 2
elseif max == b then h = (r - g) / d + 4
end
h = h / 6
end
return h, s, v, a
end