How do I mix colors in studio

how do I mix colors in ROBLOX studio?

3 Likes

It’s hard to mix colors, but you could combine the color 3 values of the two colors by taking the average of the red, blue and green. For example if color 1 had 100 for red and color 2 had 20 for the red, the new color could have 60 for the red.

3 Likes

If you mean in gui you can use a UIGradient

no that’s not what I mean I mean like how do i mix colors like red and blue how do i tell studio that these colors if mixed will make purple? using RGB

This function takes two Gui objects and returns a mixture of the two colors.

local function MixColors(Frame1, Frame2)
     local r = (Frame1.BackgroundColor3.R + Frame2.BackgroundColor3.R)/2
     local g = (Frame1.BackgroundColor3.G + Frame2.BackgroundColor3.G)/2
     local b = (Frame1.BackgroundColor3.B + Frame2.BackgroundColor3.B)/2
     return Color3.FromRGB(r,g,b)
end

--How to use, parameters are two GUIS

script.Parent.BackgroundColor3 = MixColors(script.Parent.Parent.Frame1, script.Parent.Parent.Frame2)
3 Likes

just curios why do i have to divide by two

im not talking about guis im talking about colors genarly

Because you are taking the average of each color. For example the average of 10 and 18 is 14. To calculate this, we add them to get 28, and divide them to get 14.

1 Like

If you just want to deal with colors then do this:

local function MixColors(Color1, Color2)
     local r = (Color1.R + Color2.R)/2
     local g = (Color1.G + Color2.G)/2
     local b = (Color1.B + Color2.B)/2
     return Color3.FromRGB(r,g,b)
end

print(MixColors(Color3.fromRGB(255, 0, 0), Color3.fromRGB(0, 0, 255))

The example I gave takes in red and blue, and returns purple aka Color3.fromRGB(127,0,127).

what if i want to mix more then one color?

Use Color:lerp() :

local Color1 = Color3.fromRGB()
local Color2 = Color3.fromRGB()
local NewColor = Color1:lerp(Color2,0.5)
3 Likes

@SOTR654 Oh that’s smart, that would work perfectly for mixing two colors.

@ZINTICK im writing a function for mixing multiple colors, ill get back to you in a couple minutes.

2 Likes

i thought you can only use :lerp for CFrames

:lerp it is used as a quick tween if you want to mix something up, it can be with Vector2 and Vecto3, Udim2, CFrame and Color3.

This function works with infinitely many parameters, just call the function with Color3 values.

local function mix(...)
	local args = {...} -- ... represents all the parameters, so put them in a table
	local r, g, b = 0,0,0 --define our three numbers
	for i, v in pairs(args) do --loop through table
		r += v.R --add to red
		g += v.G --add to green
		b += v.B --add to blue
	end
	r, g, b = r/#args, g/#args, b/#args --divide each value by the number of parameters
	return Color3.fromRGB(r,g,b) --return colors
end
1 Like

Modified version of @XdJackyboiiXd21

local function MixColours(ColourTbl)
    local red = Color3.fromRGB(0,0,0)
    local green = Color3.fromRGB(0,0,0)
    local blue = Color3.fromRGB(0,0,0)
    for i, v in ipairs(ColourTbl) do
        red = red + v.R
        blue = blue + v.B
        green = green + v.G
    end
    return Color3.fromRGB(red/2,green/2,blue/2)
end

Another function:

local Colors = {}
local CurrentColor
for i,Color in pairs(Colors) do
    if not CurrentColor then            CurrentColor = Color            end
    CurrentColor = CurrentColor:lerp(Color,0.5)
end
print(CurrentColor)

Place within Colors all the colors you want to mix

The problem with this is that the later colors will have more of an effect than the beginning colors. For example if there were 4 colors, here is how it would go:

New Color is Made up Of:

1/16 of the 1st color
1/8 of the  2nd color
1/4 of the 3rd color
1/2 of the 4th color

I have been thinking why do I need the average when I can have the exact?

Well to mix colors you want to take the average. For example mixing black and white, you want grey. So you want to have some white and some black, and to do that you just average them. White is (255, 255, 255) and Black is (0,0,0) so grey is (127.5,127.5,127.5)

2 Likes