Color parsing, conversion, and manipulation across RGB, HSL, HSV, and HEX
implementation com.philiprehberger:color-kitColor parsing, conversion, and manipulation across RGB, HSL, and HEX.
implementation("com.philiprehberger:color-kit:0.2.0")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>color-kit</artifactId>
<version>0.2.0</version>
</dependency>
import com.philiprehberger.colorkit.*
val red = Color.hex("#ff0000")
val blue = Color.rgb(0, 0, 255)
red.toHex() // "#ff0000"
red.lighten(0.2) // lighter red
red.mix(blue) // purple
red.luminance() // 0.2126
red.isDark() // true
red.complementary() // cyan (#00ffff)
val (t1, t2) = red.triadic() // green-ish, blue-ish
| Function / Class | Description |
|---|---|
Color.hex(hex) | Parse hex color (#RGB or #RRGGBB) |
Color.rgb(r, g, b, a) | Create from RGB values |
Color.hsl(h, s, l) | Create from HSL values |
Color.named(name) | Look up CSS named color |
Color.toHex() | Convert to hex string |
Color.toHsl() | Convert to HSL triple |
Color.lighten(amount) / darken(amount) | Adjust lightness |
Color.invert() / grayscale() | Color transformations |
Color.mix(other, weight) | Blend two colors |
Color.complementary() | Complementary color (180° hue rotation) |
Color.triadic() | Pair of triadic colors (120° and 240° rotations) |
Color.luminance() / isLight() / isDark() | Color analysis |
./gradlew test
./gradlew build
If you find this project useful: