{"id":19521821,"url":"https://github.com/smarttoolfactory/compose-extended-colors","last_synced_at":"2025-07-14T05:36:37.974Z","repository":{"id":48493620,"uuid":"486664213","full_name":"SmartToolFactory/Compose-Extended-Colors","owner":"SmartToolFactory","description":"🚀🌈♾  Utility library that expands Compose Colors with Material Design2 colors, color swatches, Material Design 3 Tonal Palettes, color names, and utility functions to convert between HSL, HSV, RGB, HCT models and to HEX or from HEX","archived":false,"fork":false,"pushed_at":"2023-04-25T04:36:45.000Z","size":5233,"stargazers_count":42,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T09:35:09.421Z","etag":null,"topics":["android","color","color-palette","color-pickers","colorpalette","hsl","hsl2rgb","hsv-color-detection","hsv-to-rgb","hsv2rgb","jetpack-compose","jetpack-compose-library","material-design","material-ui"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SmartToolFactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-28T16:10:55.000Z","updated_at":"2025-01-12T20:08:35.000Z","dependencies_parsed_at":"2025-04-26T09:42:11.842Z","dependency_job_id":null,"html_url":"https://github.com/SmartToolFactory/Compose-Extended-Colors","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/SmartToolFactory/Compose-Extended-Colors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FCompose-Extended-Colors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FCompose-Extended-Colors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FCompose-Extended-Colors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FCompose-Extended-Colors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SmartToolFactory","download_url":"https://codeload.github.com/SmartToolFactory/Compose-Extended-Colors/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SmartToolFactory%2FCompose-Extended-Colors/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265246178,"owners_count":23734109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","color","color-palette","color-pickers","colorpalette","hsl","hsl2rgb","hsv-color-detection","hsv-to-rgb","hsv2rgb","jetpack-compose","jetpack-compose-library","material-design","material-ui"],"created_at":"2024-11-11T00:35:10.211Z","updated_at":"2025-07-14T05:36:32.955Z","avatar_url":"https://github.com/SmartToolFactory.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jetpack Compose Extended Colors\n\n[![](https://jitpack.io/v/SmartToolFactory/Compose-Extended-Colors.svg)](https://jitpack.io/#SmartToolFactory/Compose-Extended-Colors)\n\n* Utility library that extends Compose Colors with Material Design2 colors, Color swatches like in\n  [Flutter](https://api.flutter.dev/flutter/material/Colors-class.html).\n\n* Material Design 3 tonal and Core palettes,\n  see [Material Design 3 site](https://m3.material.io/styles/color/the-color-system/key-colors-tones)\n  for more information about the Material 3 color system and tonal palettes.\n\n* Rotatable gradients by 45 degrees with aim to add rotation by any angle in the future\n\n* Functions to convert between `androidx.compose.ui.graphics.Color`, `HSL`, `HSV`, `RGB`, `HCT`, and\n  colors with  **Name** based on distance to pre-defined elements in json in 3D space using `Red`\n  , `Green`, `Blue` values of picked Color.\n\n| M2 Color Swatches                                          | M3 Tone Palettes                                           | Gradient Rotation                                           |\n|------------------------------------------------------------|------------------------------------------------------------|-------------------------------------------------------------|\n| \u003cimg src=\"./screenshots/material_design2.gif\" width=\"300\"\u003e | \u003cimg src=\"./screenshots/material_design3.gif\" width=\"300\"\u003e | \u003cimg src=\"./screenshots/gradient_rotation.gif\" width=\"300\"\u003e |\n\n## Gradle Setup\n\nTo get a Git project into your build:\n\n* Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end\n  of repositories:\n\n```\nallprojects {\n  repositories {\n      ...\n      maven { url 'https://jitpack.io' }\n  }\n}\n```\n\n* Step 2. Add the dependency\n\n```\ndependencies {\n    implementation 'com.github.SmartToolFactory:Compose-Extended-Colors:\u003cversion\u003e'\n}\n```\n\n\n## Material Design 2 Colors \u0026 Swatches\n\n### Material Colors\n\n\u003cimg src=\"./screenshots/m2_palette.png\"\u003e\n\n[Material Colors](https://materialui.co/colors/) can be accessed from Red to BlueGrey. Brown, Grey, and\nBlueGrey swatches only have primary colors.\n\n```kotlin\nval Red50 = Color(0xffFFEBEE)\nval Red100 = Color(0xffFFCDD2)\nval Red200 = Color(0xffEF9A9A)\nval Red300 = Color(0xffE57373)\nval Red400 = Color(0xffEF5350)\nval Red500 = Color(0xffF44336)\nval Red600 = Color(0xffE53935)\nval Red700 = Color(0xffD32F2F)\nval Red800 = Color(0xffC62828)\nval Red900 = Color(0xffB71C1C)\n\n// Accent Colors\nval RedA100 = Color(0xffFF8A80)\nval RedA200 = Color(0xffFF5252)\nval RedA400 = Color(0xffFF1744)\nval RedA700 = Color(0xffD50000)\n```\n\n### Material Swatches\n\nCall any swatch from `ColorSwatch` for instance for Red500 with `ColorSwatch.red` which will return\nprimary color `Map\u003cInt,Color\u003e`\n\n```kotlin\n  val red by lazy {\n    linkedMapOf(\n        50 to Color(0xffFFEBEE),\n        100 to Color(0xffFFCDD2),\n        200 to Color(0xffEF9A9A),\n        300 to Color(0xffE57373),\n        400 to Color(0xffEF5350),\n        500 to Color(0xffF44336),\n        600 to Color(0xffE53935),\n        700 to Color(0xffD32F2F),\n        800 to Color(0xffC62828),\n        900 to Color(0xffB71C1C)\n    )\n}\n```\n\nto access any color from this map\n\n```\nval redSwatch = ColorSwatch.red\nval red300 = redSwatch[300]!!\n```\n\nSwatch that returns header(50 variants)\n\n```kotlin\nval primaryHeaderColors by lazy {\n    listOf(\n        Color(0xffF44336),\n        Color(0xffE91E63),\n        Color(0xff9C27B0),\n        Color(0xff673AB7),\n        Color(0xff3F51B5),\n        Color(0xff2196F3),\n        Color(0xff03A9F4),\n        Color(0xff00BCD4),\n        Color(0xff00ACC1),\n        Color(0xff4CAF50),\n        Color(0xff8BC34A),\n        Color(0xffCDDC39),\n        Color(0xffFFEB3B),\n        Color(0xffFFC107),\n        Color(0xffFF9800),\n        Color(0xffFF5722),\n        Color(0xff795548),\n        Color(0xff9E9E9E),\n        Color(0xff607D8B)\n    )\n}\n```\n\n## Material Design 3 Tonal Palette\n\nA tonal palette consists of thirteen tones, including white and black. A tone value of 100 is\nequivalent to the idea of light at its maximum and results in white. Every tone value between 0 and\n100 expresses the amount of light present in the color.\n\n\u003cimg src=\"./screenshots/m3_tones.png\"\u003e\n\nFrom range 0 to 100\n\n```kotlin\nval material3ToneRange = listOf(\n    0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100\n)\n\n```\n\nCall that returns list of colors\n\n```kotlin\nfun getColorTonesList(color: Color): List\u003cColor\u003e {\n\n    val camColor = Cam16.fromInt(color.toArgb())\n    val palette: TonalPalette =\n        TonalPalette.fromHueAndChroma(camColor.hue, max(48.0, camColor.chroma))\n    val toneList = mutableListOf\u003cColor\u003e()\n\n    material3ToneRange.forEach { shade -\u003e\n        toneList.add(Color(palette.tone(shade)))\n    }\n\n    return toneList\n}\n```\n\n or to get Map with tone keys\n\n```kotlin\nfun getColorTonesMap(color: Color): Map\u003cInt, Color\u003e {\n    val palette: TonalPalette = TonalPalette.fromInt(color.toArgb())\n    val toneMap = linkedMapOf\u003cInt, Color\u003e()\n\n    material3ToneRange.forEach { shade -\u003e\n        toneMap[shade] = Color(palette.tone(shade))\n    }\n\n    return toneMap\n}\n\n```\n\n\n## Gradient Rotation\n\nGradients can be rotate by 45, in the future this can be expanded to any angle, with\n\nCreate a `GradientOffset`with\n\n```kotlin\nvar gradientOffset by remember {\n    mutableStateOf(GradientOffset(GradientAngle.CW0))\n}\n```\n\n```kotlin\nfun GradientOffset(angle: GradientAngle = GradientAngle.CW0): GradientOffset {\n    return when (angle) {\n        GradientAngle.CW45 -\u003e GradientOffset(\n            start = Offset.Zero,\n            end = Offset.Infinite\n        )\n        GradientAngle.CW90 -\u003e GradientOffset(\n            start = Offset.Zero,\n            end = Offset(0f, Float.POSITIVE_INFINITY)\n        )\n        GradientAngle.CW135 -\u003e GradientOffset(\n            start = Offset(Float.POSITIVE_INFINITY, 0f),\n            end = Offset(0f, Float.POSITIVE_INFINITY)\n        )\n        GradientAngle.CW180 -\u003e GradientOffset(\n            start = Offset(Float.POSITIVE_INFINITY, 0f),\n            end = Offset.Zero,\n        )\n        GradientAngle.CW225 -\u003e GradientOffset(\n            start = Offset.Infinite,\n            end = Offset.Zero\n        )\n        GradientAngle.CW270 -\u003e GradientOffset(\n            start = Offset(0f, Float.POSITIVE_INFINITY),\n            end = Offset.Zero\n        )\n        GradientAngle.CW315 -\u003e GradientOffset(\n            start = Offset(0f, Float.POSITIVE_INFINITY),\n            end = Offset(Float.POSITIVE_INFINITY, 0f)\n        )\n        else -\u003e GradientOffset(\n            start = Offset.Zero,\n            end = Offset(Float.POSITIVE_INFINITY, 0f)\n        )\n    }\n}\n```\n\nSet start and end of `Brush` with\n\n```kotlin\nval redGreenGradient = Brush.linearGradient(\n    colors = listOf(Color.Red, Color.Green, Color.Blue),\n    start = gradientOffset.start,\n    end = gradientOffset.end\n)\n```\n\n## Color Names\nCreate an instance of `ColorNameParser` with\n\n```kotlin\n@Composable\nfun rememberColorParser(): ColorNameParser {\n    return remember {\n        ColorNameParser()\n    }\n}\n```\nAnd call `ColorNameParser.parseColor(color)`\n\nCall it in a launchedEffect with snapshotFlow or in a ViewModel or UseCase\n\n```kotlin\nLaunchedEffect(key1 = colorNameParser) {\n\n    snapshotFlow { color }\n        .distinctUntilChanged()\n        .mapLatest { color: Color -\u003e\n            colorNameParser.parseColorName(color)\n        }\n        .flowOn(Dispatchers.Default)\n        .collect { name: String -\u003e\n            colorName = name\n        }\n}\n```\n\n\n## Conversions\n\nYou can use `ColorItem` which has functions that enables user to convert from `Color` to\nother type\n\n```kotlin\n/**\n * Data class that wraps [Color] and contains extend information about this color such\n * as HSL, HSV, RGB, HEX counterparts.\n */\ndata class ColorItem(var color: Color) {\n    val hexARGB\n        get() = colorToHexAlpha(color)\n\n    val hex\n        get() = colorToHex(color)\n\n    val hsvArray\n        get() = colorToHSV(color)\n\n    val hslArray\n        get() = colorToHSL(color)\n\n    val rgb\n        get() = colorToARGBArray(color)\n\n    val alpha:Float\n        get() = color.alpha\n\n    val red: Int\n        get() = color.red.fractionToRGBRange()\n\n    val green: Int\n        get() = color.green.fractionToRGBRange()\n\n    val blue: Int\n        get() = color.blue.fractionToRGBRange()\n\n    var label: String = Unspecified\n\n    companion object {\n        const val Unspecified = \"?????\"\n    }\n}\n```\n\nYou can also convert between `Color`, `HSL`, `HSV`, `RGB`,  and\ncolors with  utility functions. call color model you want to conveert from,  `to` then the\ncolor model you want to convert to\n\n### Color Conversion\n\n```kotlin\n\n/**\n * Convert Jetpack Compose [Color] to HSV (hue-saturation-value) components.\n * ```\n* Hue is [0 .. 360)\n* Saturation is [0...1]\n* Value is [0...1]\n* ```\n* @param hslIn 3 element array which holds the input HSL components.\n  */\n  fun colorToHSV(color: Color, hslIn: FloatArray) {\n  val rgbArray: IntArray = colorIntToRGBArray(color.toArgb())\n  val red = rgbArray[0]\n  val green = rgbArray[1]\n  val blue = rgbArray[2]\n  rgbToHSV(red, green, blue, hslIn)\n  }\n\n/**\n* Convert Jetpack Compose [Color] to HSV (hue-saturation-value) components.\n* ```\n* Hue is [0 .. 360)\n* Saturation is [0...1]\n* Value is [0...1]\n* ```\n*/\nfun colorToHSV(color: Color): FloatArray {\nval rgbArray: IntArray = colorIntToRGBArray(color.toArgb())\nval red = rgbArray[0]\nval green = rgbArray[1]\nval blue = rgbArray[2]\nreturn rgbToHSV(red, green, blue)\n}\n\n/**\n* Convert Jetpack Compose [Color] to HSV (hue-saturation-value) components.\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n* @param hslIn 3 element array which holds the input HSL components.\n  */\n  fun colorToHSL(color: Color, hslIn: FloatArray) {\n  val rgbArray: IntArray = colorIntToRGBArray(color.toArgb())\n  val red = rgbArray[0]\n  val green = rgbArray[1]\n  val blue = rgbArray[2]\n  rgbToHSL(red, green, blue, hslIn)\n  }\n\n/**\n* Convert Jetpack Compose [Color] to HSV (hue-saturation-value) components.\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun colorToHSL(color: Color): FloatArray {\nval rgbArray: IntArray = colorIntToRGBArray(color.toArgb())\nval red = rgbArray[0]\nval green = rgbArray[1]\nval blue = rgbArray[2]\nreturn rgbToHSL(red, green, blue)\n}\n\n/*\nCOLOR-RGB Conversions\n*/\n\n/**\n* Convert Jetpack [Color] into 3 element array of red, green, and blue\n  *```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param color Jetpack Compose [Color]\n* @return 3 element array which holds the input RGB components.\n  */\n  fun colorToARGBArray(color: Color): IntArray {\n  return colorIntToRGBArray(color.toArgb())\n  }\n\n/**\n* Convert Jetpack [Color] into 3 element array of red, green, and blue\n  *```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param color Jetpack Compose [Color]\n* @return 3 element array which holds the input RGB components.\n  */\n  fun colorToRGBArray(color: Color): IntArray {\n  return colorIntToRGBArray(color.toArgb())\n  }\n\n/**\n* Convert Jetpack [Color] into 3 element array of red, green, and blue\n  *```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param color Jetpack Compose [Color]\n* @param rgbIn 3 element array which holds the input RGB components.\n  */\n  fun colorToRGBArray(color: Color, rgbIn: IntArray) {\n  val argbArray = colorIntToRGBArray(color.toArgb())\n  rgbIn[0] = argbArray[0]\n  rgbIn[1] = argbArray[1]\n  rgbIn[2] = argbArray[2]\n  }\n\n\nfun colorToHex(color: Color): String {\nreturn rgbToHex(color.red, color.green, color.blue)\n}\n\nfun colorToHexAlpha(color: Color): String {\nreturn argbToHex(color.alpha, color.red, color.green, color.blue)\n}\n\n/**\n* Convert a RGB color in [Integer] form to HSV (hue-saturation-value) components.\n*  * For instance, red =255, green =0, blue=0 is -65536\n* ```\n* hsv[0] is Hue [0 .. 360)\n* hsv[1] is Saturation [0...1]\n* hsv[2] is Value [0...1]\n* ```\n*/\nfun colorIntToHSV(color: Int): FloatArray {\nval hsvOut = floatArrayOf(0f, 0f, 0f)\nandroid.graphics.Color.colorToHSV(color, hsvOut)\nreturn hsvOut\n}\n\n/**\n* Convert a RGB color in [Integer] form to HSV (hue-saturation-value) components.\n*  * For instance, red =255, green =0, blue=0 is -65536\n*\n* ```\n* hsv[0] is Hue [0 .. 360)\n* hsv[1] is Saturation [0...1]\n* hsv[2] is Value [0...1]\n* ```\n* @param hsvIn 3 element array which holds the input HSV components.\n  */\n  fun colorIntToHSV(color: Int, hsvIn: FloatArray) {\n  android.graphics.Color.colorToHSV(color, hsvIn)\n  }\n\n\n/**\n* Convert RGB color [Integer] to HSL (hue-saturation-lightness) components.\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun colorIntToHSL(color: Int): FloatArray {\nval hslOut = floatArrayOf(0f, 0f, 0f)\nColorUtils.colorToHSL(color, hslOut)\nreturn hslOut\n}\n\n/**\n* Convert RGB color [Integer] to HSL (hue-saturation-lightness) components.\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun colorIntToHSL(color: Int, hslIn: FloatArray) {\nColorUtils.colorToHSL(color, hslIn)\n}\n\n\n/*\nColorInt-RGB Conversions\n*/\n/**\n* Convert Color [Integer] into 3 element array of red, green, and blue\n  *```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @return 3 element array which holds the input RGB components.\n  */\n  fun colorIntToRGBArray(color: Int): IntArray {\n  val red = android.graphics.Color.red(color)\n  val green = android.graphics.Color.green(color)\n  val blue = android.graphics.Color.blue(color)\n  return intArrayOf(red, green, blue)\n  }\n\n/**\n* Convert Color [Integer] into 3 element array of red, green, and blue\n  *```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param rgbIn 3 element array which holds the input RGB components.\n  */\n  fun colorIntToRGBArray(color: Int, rgbIn: IntArray) {\n  val red = android.graphics.Color.red(color)\n  val green = android.graphics.Color.green(color)\n  val blue = android.graphics.Color.blue(color)\n\n  rgbIn[0] = red\n  rgbIn[1] = green\n  rgbIn[2] = blue\n  }\n\n/**\n* Convert Color [Integer] into 4 element array of alpha red, green, and blue\n  *```\n* rgb[0] is Alpha [0 .. 255]\n* rgb[1] is Red [0 .. 255]\n* rgb[2] is Green [0...255]\n* rgb[3] is Blue [0...255]\n* ```\n* @return 4 element array which holds the input ARGB components.\n  */\n  fun colorIntToARGBArray(color: Int): IntArray {\n  val alpha = android.graphics.Color.alpha(color)\n  val red = android.graphics.Color.red(color)\n  val green = android.graphics.Color.green(color)\n  val blue = android.graphics.Color.blue(color)\n  return intArrayOf(alpha, red, green, blue)\n  }\n\n/**\n* Convert Color [Integer] into 4 element array of alpha red, green, and blue\n  *```\n* rgb[0] is Alpha [0 .. 255]\n* rgb[1] is Red [0 .. 255]\n* rgb[2] is Green [0...255]\n* rgb[3] is Blue [0...255]\n* ```\n* @param argbIn 4 element array which holds the input ARGB components.\n  */\n  fun colorIntToARGBArray(color: Int, argbIn: IntArray) {\n  val alpha = android.graphics.Color.alpha(color)\n  val red = android.graphics.Color.red(color)\n  val green = android.graphics.Color.green(color)\n  val blue = android.graphics.Color.blue(color)\n\n  argbIn[0] = alpha\n  argbIn[1] = red\n  argbIn[2] = green\n  argbIn[3] = blue\n  }\n```\n\n\n### HSL Conversion\n```kotlin\n\n\n/**\n * Convert HSL components(hue-saturation-lightness) to HSV\n * (hue-saturation-value) components.\n * @param hue in [0..360f]\n * @param saturation in [0..1f]\n * @param lightness in [0..1f]\n */\nfun hslToHSV(\n    hue: Float,\n    saturation: Float,\n    lightness: Float\n): FloatArray {\n    val value = lightness + saturation * lightness.coerceAtMost(1 - lightness)\n    val saturationHSV = if (value == 0f) 0f else 2 * (1 - lightness / value)\n    return floatArrayOf(hue, saturationHSV.coerceIn(0f, 1f), value.coerceIn(0f, 1f))\n}\n\n/**\n * Convert HSL components(hue-saturation-lightness) to HSV\n * (hue-saturation-value) components.\n *\n * ```\n* hsv[0] is Hue [0 .. 360)\n* hsv[1] is Saturation [0...1]\n* hsv[2] is Value [0...1]\n* ```\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun hslToHSV(hslIn: FloatArray): FloatArray {\nreturn hslToHSV(hslIn[0], hslIn[1], hslIn[2])\n}\n\n/*\nHSL-ColorInt Conversions\n*/\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB color in [Integer] format.\n*\n* For instance, red =255, green =0, blue=0 is -65536\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun hslToColorInt(hslIn: FloatArray): Int {\nreturn hslToColorInt(hslIn[0], hslIn[1], hslIn[2])\n}\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB color in [Integer] format.\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n  */\n  fun hslToColorInt(\n  hue: Float,\n  saturation: Float,\n  lightness: Float\n  ): Int {\n  return ColorUtils.HSLToColor(floatArrayOf(hue, saturation, lightness))\n  }\n\n\n/*\nHSL-RGB Conversions\n*/\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array.\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n* ```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param hslIn 3 element array which holds the input HSL components.\n  */\n  fun hslToRGB(hslIn: FloatArray): IntArray {\n  return colorIntToRGBArray(hslToColorInt(hslIn))\n  }\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array.\n* ```\n* Hue is [0 .. 360)\n* Saturation is [0...1]\n* Lightness is [0...1]\n* ```\n*\n* ```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n*/\nfun hslToRGB(\nhue: Float,\nsaturation: Float,\nlightness: Float\n): IntArray {\nreturn colorIntToRGBArray(\ncolor = hslToColorInt(hue, saturation, lightness)\n)\n}\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array.\n* ```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n* @param rgbIn 3 element array which holds the input RGB components.\n  */\n  fun hslToRGB(\n  hue: Float,\n  saturation: Float,\n  lightness: Float,\n  rgbIn: IntArray\n  ) {\n  colorIntToRGBArray(hslToColorInt(hue, saturation, lightness), rgbIn)\n  }\n\n\n/**\n* Convert HSL (hue-saturation-lightness) to RGB red, green, blue components in [0f..1f] range.\n* ```\n* rgb[0] is Red [0f .. 1f)\n* rgb[1] is Green [0f...1f]\n* rgb[2] is Blue [0f...1f]\n* ```\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n*\n* @return 3 element array which holds the output RGB components.\n  */\n  fun hslToRGBFloat(\n  hue: Float,\n  saturation: Float,\n  lightness: Float\n  ): FloatArray {\n  val color = Color.hsl(hue, saturation, lightness)\n  return floatArrayOf(color.red, color.green, color.blue)\n  }\n\n/**\n* Convert HSL (hue-saturation-lightness) to RGB red, green, blue components in [0f..1f] range.\n* ```\n* rgb[0] is Red [0f .. 1f)\n* rgb[1] is Green [0f...1f]\n* rgb[2] is Blue [0f...1f]\n* ```\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n* @param rgbIn 3 element array which holds the output RGB components.\n  */\n  fun hslToRGBFloat(\n  hue: Float,\n  saturation: Float,\n  lightness: Float,\n  rgbIn: FloatArray\n  ) {\n  val color = Color.hsl(hue, saturation, lightness)\n  rgbIn[0] = color.red\n  rgbIn[1] = color.green\n  rgbIn[2] = color.blue\n  }\n```\n\n\n### HSL Conversion\n```kotlin\n\n\n/**\n * Convert HSL components(hue-saturation-lightness) to HSV\n * (hue-saturation-value) components.\n * @param hue in [0..360f]\n * @param saturation in [0..1f]\n * @param lightness in [0..1f]\n */\nfun hslToHSV(\n    hue: Float,\n    saturation: Float,\n    lightness: Float\n): FloatArray {\n    val value = lightness + saturation * lightness.coerceAtMost(1 - lightness)\n    val saturationHSV = if (value == 0f) 0f else 2 * (1 - lightness / value)\n    return floatArrayOf(hue, saturationHSV.coerceIn(0f, 1f), value.coerceIn(0f, 1f))\n}\n\n/**\n * Convert HSL components(hue-saturation-lightness) to HSV\n * (hue-saturation-value) components.\n *\n * ```\n* hsv[0] is Hue [0 .. 360)\n* hsv[1] is Saturation [0...1]\n* hsv[2] is Value [0...1]\n* ```\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun hslToHSV(hslIn: FloatArray): FloatArray {\nreturn hslToHSV(hslIn[0], hslIn[1], hslIn[2])\n}\n\n/*\nHSL-ColorInt Conversions\n*/\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB color in [Integer] format.\n*\n* For instance, red =255, green =0, blue=0 is -65536\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n*/\nfun hslToColorInt(hslIn: FloatArray): Int {\nreturn hslToColorInt(hslIn[0], hslIn[1], hslIn[2])\n}\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB color in [Integer] format.\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n  */\n  fun hslToColorInt(\n  hue: Float,\n  saturation: Float,\n  lightness: Float\n  ): Int {\n  return ColorUtils.HSLToColor(floatArrayOf(hue, saturation, lightness))\n  }\n\n\n/*\nHSL-RGB Conversions\n*/\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array.\n* ```\n* hsl[0] is Hue [0 .. 360)\n* hsl[1] is Saturation [0...1]\n* hsl[2] is Lightness [0...1]\n* ```\n* ```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param hslIn 3 element array which holds the input HSL components.\n  */\n  fun hslToRGB(hslIn: FloatArray): IntArray {\n  return colorIntToRGBArray(hslToColorInt(hslIn))\n  }\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array.\n* ```\n* Hue is [0 .. 360)\n* Saturation is [0...1]\n* Lightness is [0...1]\n* ```\n*\n* ```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n*/\nfun hslToRGB(\nhue: Float,\nsaturation: Float,\nlightness: Float\n): IntArray {\nreturn colorIntToRGBArray(\ncolor = hslToColorInt(hue, saturation, lightness)\n)\n}\n\n/**\n* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array.\n* ```\n* rgb[0] is Red [0 .. 255]\n* rgb[1] is Green [0...255]\n* rgb[2] is Blue [0...255]\n* ```\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n* @param rgbIn 3 element array which holds the input RGB components.\n  */\n  fun hslToRGB(\n  hue: Float,\n  saturation: Float,\n  lightness: Float,\n  rgbIn: IntArray\n  ) {\n  colorIntToRGBArray(hslToColorInt(hue, saturation, lightness), rgbIn)\n  }\n\n\n/**\n* Convert HSL (hue-saturation-lightness) to RGB red, green, blue components in [0f..1f] range.\n* ```\n* rgb[0] is Red [0f .. 1f)\n* rgb[1] is Green [0f...1f]\n* rgb[2] is Blue [0f...1f]\n* ```\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n*\n* @return 3 element array which holds the output RGB components.\n  */\n  fun hslToRGBFloat(\n  hue: Float,\n  saturation: Float,\n  lightness: Float\n  ): FloatArray {\n  val color = Color.hsl(hue, saturation, lightness)\n  return floatArrayOf(color.red, color.green, color.blue)\n  }\n\n/**\n* Convert HSL (hue-saturation-lightness) to RGB red, green, blue components in [0f..1f] range.\n* ```\n* rgb[0] is Red [0f .. 1f)\n* rgb[1] is Green [0f...1f]\n* rgb[2] is Blue [0f...1f]\n* ```\n* @param hue in [0..360f]\n* @param saturation in [0..1f]\n* @param lightness in [0..1f]\n* @param rgbIn 3 element array which holds the output RGB components.\n  */\n  fun hslToRGBFloat(\n  hue: Float,\n  saturation: Float,\n  lightness: Float,\n  rgbIn: FloatArray\n  ) {\n  val color = Color.hsl(hue, saturation, lightness)\n  rgbIn[0] = color.red\n  rgbIn[1] = color.green\n  rgbIn[2] = color.blue\n  }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarttoolfactory%2Fcompose-extended-colors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmarttoolfactory%2Fcompose-extended-colors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarttoolfactory%2Fcompose-extended-colors/lists"}