https://github.com/exhuma/colorutils
Java Library containing a couple color helpers
https://github.com/exhuma/colorutils
Last synced: about 1 year ago
JSON representation
Java Library containing a couple color helpers
- Host: GitHub
- URL: https://github.com/exhuma/colorutils
- Owner: exhuma
- License: bsd-3-clause
- Created: 2011-09-07T08:11:13.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2011-09-07T08:53:33.000Z (over 14 years ago)
- Last Synced: 2025-01-30T12:32:53.177Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 98.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
ColorUtils
==========
Small java library containing some helper methods to work with color and
accessibility (A11Y). The primary goal for this library was to provide a
method to return a color which is well readable on a given background color.
Or, given a text-color, find a "good" background-color.
Implementation
--------------
The first algorithm implemented is based on a W3C recommendation. As this
recommendation was based on the websafe color palette, the results are not
always satisfactory.
After a bit of research, I found two alternative algorithms based on
Luminosity and Luminosity contrast. LuminosityContrast seemed to yield the
most acceptable results, so this one is implemented by default.
There is also a method to determine whether a color combination is readable or
not. Using this method you can specify the difference algorithm and adapt the
colors appropriately.
Disclaimer
----------
Many parameters are still hardcoded and could be made accessible externally.
But so far I did not yet have the need to change these values dynamically, so
I did not implement them as such.
Example Usage
-------------
::
import lu.albert.colorutils.ColorA11Y;
Color textColor = ColorA11Y.getReadableComplement(
myTextComponent.getBackground());
myTextComponent.setForeground(textColor);