I was wondering whether I could make some code that essentially reverses the value of each color segment (R,G,B).
I am wanting to reverse it completely whilst keeping the range from 0.5 equal between both new and original values.
Examples:
(0,0,0) = (1,1,1)
(0.25,0.7,0) = (0.75,0.3,1)
Here is what I have figured out - but it is not very good in terms of writing efficiency.
function invertColor(color)
local am = 0.5
local equation = {r = am-color.r,g = am-color.g,b = am-color.b}
local r,g,b
if color.r > 0.5 then
r = am-equation.r
else
r = am+equation.r
end
if color.g > 0.5 then
g = am-equation.g
else
g = am+equation.g
end
if color.b > 0.5 then
b = am-equation.b
else
b = am+equation.b
end
return Color3.new(r,g,b)
end
Is there a way I can lower the amount of code I have to write?
Thank you!
~TDP

1 comment
You will need to check the range though, (x - 1) * -1