I need a function where I input something like Color3.fromrgb(0, 230, 20) and get “Green” as my output. Any help.
If you’re okay with Roblox’s brick colour names, then here’s a bit of a goofy one:
BrickColor.new(Color3.fromRGB(0, 230, 20)).Name
Green would be Color3.new(0, 1, 0) or Color3.fromRGB(0, 255, 0), your color has a hint of blue in it.
You could covert the Color3 into its hexadecimal equivalent and then check it against the following list of colors.
If you’d need assistance implementing this let me know.
Tried that. I ended up having to list every single green Color3 without it working
Out of curiosity - why? I’m not too sure I understand what the issue with that code may be aside from the fact that it wouldn’t give you an exact colour and instead pick from the BrickColor palette. Why did you end up having to list any colours? What do you want to achieve exactly?
How would I implement this? And I took a look at this, I don’t want exact outputs like Sea green I want Primary Colors like just green.
I am making a picture to terrain system. I have a server ready but on roblox’s side I need it to convert the pixels color into a very simple color so it knows to make terrain out of the color.
By primary I assume you mean the main 3 color channels?
local color = Color3.new(0, 1, 0)
if color.R > color.G and Color.R > Color.B then
print("Color is red.")
elseif color.G > color.R and color.G > color.B then
print("Color is green.")
elseif color.B > color.R and color.B > color.G then
print("Color is blue.")
end
Obviously this would be fairly inaccurate (but might suffice your usecase).
I mean the 7 colors of the rainbow.
I see your script. It would work except that I need Yellow, Orange, Green, Blue, White as my colors.
Thanks - this wouldn’t work then. There isn’t any real automatic solution here so you will have to, whether by a given list or one that you create, remap different colours to the exact primary colour you want represented. If you use the BrickColor method, that means remapping the full palette and that doesn’t sound great if you want it to scale arbitrarily.
I would say that it might be sound to approximate the colour being represented depending on what colours you want. If it’s just primary colours (Red, Green and Blue) and not any other colour (e.g. secondary), you can take the largest RGB value in a set and get a word based off of that.
local function getPrimaryColorApproximateFromColor3(color3)
local components = {Red = color3.R, Green = color3.G, Blue = color3.B}
local currentName, currentValue = "Black", 0
for colorString, value in pairs(components) do
if value > currentValue then
currentName = colorString
currentValue = value
end
end
return currentName
end
-- Test
local outputs = {}
for i = 1, 25 do
local randomColor = BrickColor.Random().Color
local colorApproximate = getPrimaryColorApproximateFromColor3(randomColor)
print(randomColor, colorApproximate)
end
I saw that you replied you needed secondary colours while I was typing this though, so this wouldn’t work. Worth a try but thought you just needed primaries. Sorry about that.
Sorry, And thank you also. I would manage to get this work