-
Notifications
You must be signed in to change notification settings - Fork 809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color manipulation methods #2136
Conversation
Add color manipulation functions with HSV, HSL, HSB, HWB. Add HWB support.
Do you think it's also worth porting Also there are conflicts that must be resolved. |
is this legit? lua implementation 100500% faster |
fix style, rm :SetValue alias, add HSLToColor & HSVToColor lua implementation (100500x faster than C)
Moved stuff around to be more logically placed, made changes to HSVToColor and HSLToColor to more closely match the C++ version's returns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HSVToColor
and HSLToColor
replacements are not 1 to 1 with the C++ versions, sometimes generating an off by 1 difference (I think this is just floating point math discrepancies), and severely different when given invalid inputs.
The c++ code generates the same negative values with invalid inputs, but get changed to correct range via either float to int cast, or int to unsigned char cast.
I have applied some changes that gets it close, but not exactly the same. (off by 2)
255 % 255 == 0 we cant use mod here
mod leads to unexpected results. it looks like c++ also uses mod, which is incorrect if saturation == 0 then -- grayscale, depends only on value
rgb = math.floor(value * 255) -- 280.5 (255 floor)
end c++ c++ |
Features:
HWB support.
Color manipulation methods with HSV, HSL, HSB, HWB.
The main way to use this methods is to create colors for the UI.
For example, the Discord color scheme consists of the same hue and saturation, they just change lightness to create a beautiful color palette.
All you need to make pallete is background color, text color & accent color.
So addons theme config can be just 3-5 colors, instead of:
Demo:
hl2_ga8aLyIIvR.mp4
demo src: https://gist.github.com/Be1zebub/a015958b71eb8806f0ce5db3e55ed4c0