Introduction:
Hello developers ! I am working on a plugin that is related to CSS and Roblox development.
Therefore, I have created a list of every CSS string color in Color3.
The module basically looks like this:
So I made a module for that instead of copying the whole list every time.
How is this useful?
This is useful for people who are familiar with some CSS color names (e.g. ForestGreen or Fuchsia), and feel more comfortable writing the Color name rather than Color3.fromRGB(255,0,255).
Or for people who make CSS-related things such as plugins, and want to easily get the colors.
For instance:
local colors = require(6454054091) --Require the CSS colors module.
script.Parent.BackgroundColor3 = colors["forestgreen"] --Get the Color3 of the ForestGreen Color
How to use?
This module is basically a list of CSS colors ordered by alphabetical order.
There are 2 ways to use it:
- Require the module and type the color name with lower-case letters
local colors = require(6454054091) --Require the CSS colors module.
local forestGreen = colors["forestgreen"] --Get the Color3 of the ForestGreen Color
- Require the module and use the Module:GetColor(colorName) function.
local colors = require(6454054091) --Require the CSS colors module.
local forestGreen = colors:GetColor("fORestGreeN")--Get the Color3 of the ForestGreen Color
In this option, you don’t have to worry about the letter’s case (Capital or Lower), since the function lowers it for you, so for long names such as LightGoldenRodYellow it is much easier.
What else does it include?
As of now, it includes 8 more functions:
module:GetBrickColor(colorName) - it gives you the BrickColor from the CSS color name.
colors:GetBrickColor("Fuchsia") -- "Hot pink" brick color is returned.
module:GetHEXColor(colorName) - it gives you the HEX string from the CSS color name.
colors:GetHEXColor("red") -- "#FF0000" color is returned.
module:GetCSSColorNameFromRGB(red, green, blue) - it gives the CSS color name from RGB values.
colors:GetCSSColorNameFromRGB(138,43,226) -- "blueviolet" is returned.
module:GetCSSColorNameFromHSV(hue, saturation, value) - it gives the CSS color name from HSV values.
module:GetCSSColorNameFromColor3(color) - it gives the CSS color name from Color3 entered.
colors:GetCSSColorNameFromColor3(Color3.new(255,255,255)) -- "white" is returned.
module:GetCSSColorNameFromBrickColor(color) - it gives the CSS color name from BrickColor entered.
colors:GetCSSColorNameFromBrickColor(BrickColor.new("Really blue")) -- "blue" is returned.
module:GetCSSColorNameFromHEX(hex) - it gives the CSS color name from the HEX string.
colors:GetCSSColorNameFromHEX("#0000FF") -- "blue" is returned.
module:Random() - it gives a Random CSS Color3 Value.
colors:Random() -- a Random CSS Color is returned.
Error Handling
There are a few error messages:
1.Color3 or BrickColor wasn’t found.
2.No CSS Color was found from RGB
3.No CSS Color was found from HSV
4.No CSS Color was found from Color3
5.No CSS Color was found from BrickColor
6. Expected type got wrong type messages
If you get nil from colors:GetColor(), it means that no color was found
Want to get rid of the warnings? Use the module:ToggleWarnings(false) function
The only warnings that won’t be disabled are the type errors.
local colors = require(6454054091) --The CSS color module
colors:ToggleWarnings(false) --Disable warnings
local color = colors:GetCSSColorNameFromRGB(1,4,3) --A color that doesn't exist
--The color is nil, but you won't receive a warning that it doesn't exist ^
Links:
https://www.roblox.com/library/6454054091/CSS-Colors-to-Lua
To require:
local colors = require(6454054091) --The CSS color module
The plugin:
That’s right, I finished the plugin that utilizes this module :
Thank you for reading , I hope it helps!
Have a wonderful day/night!
Yes, I did actually spend 3 hours listing every color from the website in the dictionary, and making the functions