RGB or Hex for Applying Colors?

Although this may just be personal preference, Ill still ask, so I was wondering if I should be using Hex, or RGB, while I understand how to usr RGB, I am getting interested with Hex, and how it works, but im not sure about its usage because with some code, like this:

Color3.new(1,1,1)        -- Color3 Combination for White
Color3.fromHex("ffffff") -- Hex code for White

-- as far as I remember for Hex so I could be wrong:
red   = "ff0000"
green = "00ff00"
blue  = "0000ff"
-- RGB
C3red   = Color3.new(1,0,0)
C3green = Color3.new(0,1,0)
C3blue  = Color3.new(0,0,1)

RGB might be faster to use, but I was wondering on what I should use.

What would be overall best to use?

Edit: I intended to create this early in the morning (my time), but i didnt have time to finish it, so i did it in the afternoon.

1 Like

A “best” way can’t really exist, since it’s down to personal preference obviously. Hex itself is already based off of RGB so there’s no accuracy benefit since its also on a scale of 0-255 (and any color accuracy would be limited by your monitor’s color depth anyways), but it can be compacted down alot easier into string form since it uses just 2 characters per color (0-FF).

Personally, I just stick with RGB because I’m used to it, but if you are screen space limited or just want to be quirky or something then hex works just as well.

I mean, Its technically 0 - 1, not 0 - 255

Which you can obviously multiply by 255 to get the Actual Color code.

00 == 0
0A == 10
FF == 255

I was just saying that uses the same scale as RGB. Roblox just sets it to a ratio of 255:1.

1 Like

I know.

Also, Im aware that they are the same thing, Im just wondering what would overall be better to use.

Color3.fromRGB() is the best option. Color3.new(0.9960784314) (my bad, fixed) is equal to Color3.fromRGB(254) which makes Color3.fromRGB() faster because of the difference of Bytes each argument takes, and if you look at Color3.fromHex() you can see that it requires 6 Bytes whilst Color3.fromRGB() is simply 1 Byte per value (R, G, and B).

1 Like

I got 0.99607843137 when dividng 254 by 255, but idk could be wrong.

And yeah, As far as I know, every character that has a unicode point below 128 is one byte.

Ill need to check the speed part tho, just to be sure.

Personally, I’m of the opinion that small-scale optimization really isn’t a great concern considering the amount of processing power that we have at our disposal today, and rather that readability and ease of use should be a bigger concern than raw speed.

That’s not to say that optimization is a bad thing, but these pre-optimizations (optimizing before there are any performance issues to begin with), are not great and will probably hurt your workflow eventually. Obviously that is not the case with something as simple as changing a color, but it’s something that should be noted down the line.

tl;dr 6 bytes → 1 byte won’t do a whole lot, and I think its just better to use what you are more comfortable with.

Speed Differences may not be a lot, but it would make your stuff more efficient, and faster, which would very much be helpful.

rgb. hex is a string and it’s complicated to modify, instead rgb uses numbers which you can modify easier than hex. hex might look cooler but truly you shouldn’t use hex for scripting.

Well you cannot store a regular color3 into a datastore, so hexademical is best for datastores and that it can easily be converted and to a color and a string, do I would say hexadecimal because it is used more often, I used color.new very few times for a bar like 3 movable bars which would come out to be a color, but then because the value is stored in memory as hexadecimal because the color on the screen is displayed from 0-255 or 0-ff.
I do not know which is faster but hexadecimal is easier to convert and store. also saving a Color3.new JSON data would be longer [1,0.4,1] compared to “ff00d8”.

Edit:So I would use Color3.new for scripting, but retrieving a Color3 from datastores and remoteEvents I would use Color3.fromHex.

Thats not the reason people use Hex, lol

I see.

1 Like

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