Skip to content
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

Added functions that helps in finding more contrasting colors #1386

Closed
wants to merge 1 commit into from

Conversation

lisandropuzzolo
Copy link

I added 3 color functions:

*invertluma(color)
This function inverts the luma component of a color. If its luma was 27%, it will be 73%

*contrastmore( color1, color2, minLumaDIfference = 30% )
This function is very usefull when you need color2 to be legible against color1 (based on luma).
If color2 and color1 have a luma less than minLumaDIfference (30% default), color2 will be moved far away in luminance from color1.
If the resulting color2 luma is more than 1 or less than 0, its pivoted around color1, so the resulting color will be "near" than color1.

*autocontrast( color1, color2, minLumaDIfference = 30% )
This function is similar than contrastmore and is very usefull when you need color2 to be legible against color1 (based on luma).
If color2 and color1 have a luma less than minLumaDIfference (30% default), color2 will be moved far away in luminance from color1.
If the resulting color2 luma is more than 1 or less than 0, its luma gets INVERTED, so the resulting color2 luma will be far away from color1 luma.
It works better than contrastmore for buttons colors (background color and text color)

I added 3 color functions:

invertluma(color)
This function inverts the luma component of a color. If its luma was 27%, it will be 73%

contrastmore( color1, color2, minLumaDIfference = 30% )
This function is very usefull when you need color2 to be legible against color1 (based on luma).
If color2 and color1 have a luma less than minLumaDIfference (30% default), color2 will be moved far away in luminance from color1.
If the resulting color2 luma is more than 1 or less than 0, its pivoted around color1, so the resulting color will be "near" than color1.

autocontrast( color1, color2, minLumaDIfference = 30% )
This function is similar than contrastmore and is very usefull when you need color2 to be legible against color1 (based on luma).
If color2 and color1 have a luma less than minLumaDIfference (30% default), color2 will be moved far away in luminance from color1.
If the resulting color2 luma is more than 1 or less than 0, its luma gets INVERTED, so the resulting color2 luma will be far away from color1 luma.
It works better than contrastmore for buttons colors (background color and text color)
@Synchro
Copy link
Member

Synchro commented Jun 26, 2013

I assume you've already seen the existing contrast and luma functions?

@Synchro
Copy link
Member

Synchro commented Jun 26, 2013

Your luma calculations are inconsistent: hsl.l isn't the same thing as .luma; they are calculated quite differently. You'll probably get good enough results from them though.

@lisandropuzzolo
Copy link
Author

Hi Synchro, yes, i saw the contrast and luma functions, but they don't do what my proposal functions do, that is automatically calculate colors that are legibles for the eye.

@lukeapage
Copy link
Member

I would accept this, but I also think this and other color functions should
live in a pluggable module.

@lukeapage lukeapage added this to the 2.0.0 milestone Oct 20, 2014
lukeapage added a commit to less/less-plugin-advanced-color-functions that referenced this pull request Jan 3, 2015
@lukeapage
Copy link
Member

I created a plugin (mainly as an example) of this

https://github.com/less/less-plugin-advanced-color-functions

so you can use your functions through that.

@lukeapage lukeapage closed this Jan 3, 2015
@bassjobsen
Copy link
Contributor

@lukeapage, @lisandropuzzolo great! i think indeed using plugin to distribute custom function is a good idea. I did the same today, see: https://github.com/bassjobsen/less-plugin-cubehelix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants