How to Mix Colors

How can I mix 2 colors? Is this even possible?
Any ideas or help would be greatly appreciated. :smiley:

Example:

local color_1 = Color3.fromRGB(86, 75, 60)
local color_2 = Color3.fromRGB(255, 255, 255)

local mixed_color = Color3.fromRGB(?, ?, ?)
3 Likes

Maybe one of these might help

https://www.google.com/url?sa=t&source=web&rct=j&url=https://devforum.roblox.com/t/how-do-i-mix-colors-in-studio/1137470&ved=2ahUKEwjLhovxkMf3AhWH-qQKHYTqC-IQFnoECAQQAQ&usg=AOvVaw1MH-g-cbH2axud4t3LFgRL

https://www.google.com/url?sa=t&source=web&rct=j&url=https://devforum.roblox.com/t/mix-together-two-color3-values/340546&ved=2ahUKEwjLhovxkMf3AhWH-qQKHYTqC-IQFnoECAMQAQ&usg=AOvVaw0bftTPkd6Ibg1JqRh9n6If

https://www.google.com/url?sa=t&source=web&rct=j&url=https://devforum.roblox.com/t/can-you-mix-3-colours-together/1154167&ved=2ahUKEwjLhovxkMf3AhWH-qQKHYTqC-IQFnoECAsQAQ&usg=AOvVaw1feNCZlVnpKg-CKWMo2tiV

Color3 has a lerp function, which essentially blends the two:

local color_1 = Color3.fromRGB(86, 75, 60)
local color_2 = Color3.fromRGB(255, 255, 255)

local mixed_color = color_1:Lerp(color_2, 0.5)

Alternatively, you could get the mean of the colors:

local function CombineColors(...: Color3)
    local length = select("#", ...)
    local rV = 0
    local gV = 0
    local bV = 0

    for index = 1, length do
        local Color = select(index, ...)

        rV += Color.R
        gV += Color.G
        bV += Color.B
    end

    return Color3.fromRGB(
        rV / length,
        gV / length,
        bV / length
    )
end
2 Likes

Thank you so much for providing 2 amazing answers.

However, I have a question.
What is “alpha” in the lerp function? Although I looked it up, I have difficult time understand it.

It’s the percent between the first and second colours provided. If you had white and black, an alpha of 0.5 (or 50%) would make exactly grey.

1 Like

It’s essentially a multiplier to the color values. Let’s say there are two color values: Color A, and Color B. An alpha of zero would be the base color (Color A). An alpha of one would be the target color (Color B). At the same time, an alpha of 0.5 would be the halfway point between Color A and Color B.

In certain terms, it’s the percent of how the base matches the target.

Ah, that makes perfect sense!
Thank you so much.

1 Like