Code Monkey home page Code Monkey logo

Comments (5)

Ellypse avatar Ellypse commented on September 15, 2024

I completely agree with you. The fact that it is not possible at all to create a color with RGB values of (1, 1, 1) on a 0-255 scale is a huge oversight.

I will add explicit constructors to use when you are sure of the format of the numbers.

from ellyb.

Meorawr avatar Meorawr commented on September 15, 2024

Pretty sure Github still doesn't let people PR against wiki pages, but here's a slightly messy diff with the newly added constructors for the docs if you get a chance.

diff --git a/Color.md b/Color.md
index 43929b2..7cdab0d 100644
--- a/Color.md
+++ b/Color.md
@@ -1,6 +1,8 @@
 The Color model provides methods to handle colors and colored text.
 
-## Color(red, green, blue, [alpha]) or Color(colorCode) or Color(colorTable)
+# Constructor
+
+## Color(red, green, blue[, alpha]) or Color(colorCode) or Color(colorTable)
 
 Constructor. Used to create a new Color.
 
@@ -10,7 +12,41 @@ local yellow = Ellyb.Color(255, 255, 0);
 local grey = Ellyb.Color("#CCC");
 local purple = Ellyb.Color({ r = 1, g = 0, b = 1});
 ```
- 
+
+**Note:** The `Color(red, green, blue[, alpha])` signature accepts values in either a floating point range and a byte value range. The byte value range is deprecated; see `Color:CreateFromRGBAsBytes()`.
+
+# Static Methods
+
+## CreateFromRGBA(red, green, blue[, alpha])
+
+Constructs a new `Color` instance with the given RGBA values treated as floating point values in the range 0-1.
+
+```lua
+local mahogany = Ellyb.Color:CreateFromRGBA(0.75, 0.25, 0);
+```
+
+## CreateFromRGBAAsBytes(red, green, blue[, alpha])
+
+Constructs a new `Color` instance with the given RGBA values treated as byte values in the range 0-255.
+
+Unlike the class constructor, this static method is capable of constructing a `Color` correctly when the input values are all equal to 1.
+
+```lua
+local malachite = Ellyb.Color:CreateFromRGBAAsBytes(11, 218, 81);
+```
+
+## CreateFromHexa(colorCode)
+
+Constructs a new `Color` instance with the given RGBA hexadecimal color code in the form `#RGB`, `#RRGGBB`, or `#RRGGBBAA`.
+
+Any prefixing `#` or present `|c` UI escape sequence will be stripped automatically (see `ColorManager.hexaToNumber`).
+
+```lua
+local azure = Ellyb.Color:CreateFromHexa("#0080ff");
+```
+
+# Instance Methods
+
 ## __tostring()
 
 Get a text representation of the Color: the hexadecimal code of the Color, colored using [UI escape sequences].

from ellyb.

Ellypse avatar Ellypse commented on September 15, 2024

Thanks :D It is updated, I just fixed the usage of : instead of .. Since they are static methods they do not use the : notation that passes self :)

from ellyb.

Meorawr avatar Meorawr commented on September 15, 2024

I should have proofread it some more, but the deprecation notice should point to Color.CreateFromRGBAAsBytes (had the colon and was missing the A in RGBA).

from ellyb.

Ellypse avatar Ellypse commented on September 15, 2024

Fixed :)

from ellyb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.