Colormath is a Kotlin Multiplatform library for color manipulation and conversion.
Colormath can:
- Convert between color models and spaces
- Manipulate colors with transformations such as mixing and chromatic adaptation
- Calculate attributes such as WCAG contrast and perceptual color difference
- Generate gradients with custom interpolation methods and easing functions
- Parse and render colors as strings, including all representations from the CSS spec
val color = RGB("#ff23cc")
mixed = color.interpolate(RGB(, , ), )
lab = mixed.toLAB()
labA = lab.copy(alpha = )
lab50 = labA.convertTo(LAB50)
println(lab50.formatCssString())
Documentation
The full documentation can be found on the website.
You can also try it online
Installation
Colormath is distributed through Maven Central.
dependencies {
implementation("com.github.ajalt.colormath:colormath:3.6.1")
// optional extensions for interop with other platforms
//
// android.graphics.Color
implementation("com.github.ajalt.colormath:colormath-ext-android-color:3.6.1")
// androidx.annotation.ColorInt
implementation("com.github.ajalt.colormath:colormath-ext-android-colorint:3.6.1")
// androidx.compose.ui.graphics.Color
implementation("com.github.ajalt.colormath:colormath-ext-jetpack-compose:3.6.1")
}
If you're using Maven instead of Gradle, use <artifactId>colormath-jvm</artifactId>
Multiplatform
Colormath publishes artifacts for all
Tier 1 and Tier 2
targets, as well as mingwX64 and wasmJs.
Snapshots
Snapshot builds are also available

You'll need to add the Sonatype snapshots repository:
repositories {
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}