
Library for color manipulation and conversion, supporting various color models and spaces. Includes features like color mixing, chromatic adaptation, WCAG contrast, perceptual difference calculations, gradient generation, and CSS-compatible color string rendering.
Colormath is a Kotlin Multiplatform library for color manipulation and conversion.
Colormath can:
// Create an sRGB color
val color = RGB("#ff23cc")
// Interpolate with another color
val mixed = color.interpolate(RGB(0.1, 0.4, 1), 0.5f)
// RGB("#8c45e6")
// Convert to a different color space
val lab = mixed.toLAB()
// LAB(46.3, 60.9, -70)
// Change the transparency
val labA = lab.copy(alpha = 0.25f)
// LAB(46.3, 60.9, -70, 0.25)
// Adapt white point
val lab50 = labA.convertTo(LAB50)
// LAB50(45, 55.1812, 72.5911, 0.25)
// Render as a css color string
println(lab50.formatCssString())
// "lab(45% 55.1812 -72.5911 / 0.25)"The full documentation can be found on the website.
You can also try it online
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")
}Colormath publishes artifacts for all
Tier 1 and Tier 2
targets, as well as mingwX64 and wasmJs.
Colormath is a Kotlin Multiplatform library for color manipulation and conversion.
Colormath can:
// Create an sRGB color
val color = RGB("#ff23cc")
// Interpolate with another color
val mixed = color.interpolate(RGB(0.1, 0.4, 1), 0.5f)
// RGB("#8c45e6")
// Convert to a different color space
val lab = mixed.toLAB()
// LAB(46.3, 60.9, -70)
// Change the transparency
val labA = lab.copy(alpha = 0.25f)
// LAB(46.3, 60.9, -70, 0.25)
// Adapt white point
val lab50 = labA.convertTo(LAB50)
// LAB50(45, 55.1812, 72.5911, 0.25)
// Render as a css color string
println(lab50.formatCssString())
// "lab(45% 55.1812 -72.5911 / 0.25)"The full documentation can be found on the website.
You can also try it online
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")
}Colormath publishes artifacts for all
Tier 1 and Tier 2
targets, as well as mingwX64 and wasmJs.