How to brighten a color

I have a function that takes a base color and a number, and returns a color that is brighter/darker than the one that was provided.

I don’t know Color3-s well, so excuse my creative horrible solution lol.

    local baseColor = Color3.fromRGB(200, 10, 50)
	local amount = 30
	
	local r = baseColor.R + amount  
	local g = baseColor.G + amount  
	local b = baseColor.B + amount  
	
	print(r, g, b)

note that this isn’t what the function looks like, I just made it more straightforward to be able to run in the command bar.

Any help appreciated!

You could simply just add/multiply a value to each component!, like you’re already doing.

not sure if this only applies to cframes/vector3s
but you can try this:

local function shadeColour(rgb, ...)
    if not ... or not rgb then return end
    if #... > 3 then return end
    local shade1, shade2, shade3 = ...[1], ...[2] or ...[1], ...[3] or ...[1]
    return rgb + Color3.fromRGB(shade1, shade2, shade3)
end

--local colour = Color3.fromRGB(200, 150, 70)
--local brighter = shadeColour(colour, 30, 20)
--local darker = shadeColour(colour, -30, -20, -10)

i haven’t coded in lua in a while so i forget some things cuz im learning html, css, python, and javascript right now

Here’s 2 ways. Idk if by brightness u meant how white or the contrasted it is, but it’s an easy change if u meant constrast.

local amount = 30

local baseColor = Color3.fromRGB(200, 10, 50) do
	baseColor = (baseColor:Lerp(Color3.fromHSV(0, 0, amount/255), .5))
end

local baseColor = Color3.fromRGB(200, 10, 50) do
	baseColor = (baseColor:Lerp(Color3.fromHSV(0, 0, 1), amount/255))
end

It seems to simply just erase the already existing color value.

(the amount is 30.)

image

Greetings, I’m here to say that I’ve resolved my issue.

It turns out that the outputs of the R, G and B components of the Color3 are not whole numbers, meaning that they are meant to be put into a Color3.new() function and not a Color3.fromRGB() function.

Thanks to everyone for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.