From 43e88e50d620d933b4bb4703823236f971a2b86e Mon Sep 17 00:00:00 2001 From: Smart Tool Factory Date: Fri, 29 Apr 2022 17:45:58 +0300 Subject: [PATCH] get lib dependency from jitpack --- README.md | 216 +++++++++++++++++++++++++++++++++++++++++++++++ app/build.gradle | 3 +- settings.gradle | 1 + 3 files changed, 219 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a36f0a..e00d440 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Jetpack Compose Extended Colors +[![](https://jitpack.io/v/SmartToolFactory/Compose-Extended-Colors.svg)](https://jitpack.io/#SmartToolFactory/Compose-Extended-Colors) + * Utility library that extends Compose Colors with Material Design2 colors, Color swatches like in [Flutter](https://api.flutter.dev/flutter/material/Colors-class.html). @@ -17,6 +19,31 @@ | ----------|-----------| -----------| | | | | +## Gradle Setup + +To get a Git project into your build: + +* Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end + of repositories: + +``` +allprojects { + repositories { + ... + maven { url 'https://jitpack.io' } + } +} +``` + +* Step 2. Add the dependency + +``` +dependencies { + implementation 'com.github.SmartToolFactory:Compose-Extended-Colors:' +} +``` + + ## Material Design 2 Colors & Swatches ### Material Colors @@ -750,3 +777,192 @@ color = hslToColorInt(hue, saturation, lightness) rgbIn[2] = color.blue } ``` + + +### HSL Conversion +```kotlin + + +/** + * Convert HSL components(hue-saturation-lightness) to HSV + * (hue-saturation-value) components. + * @param hue in [0..360f] + * @param saturation in [0..1f] + * @param lightness in [0..1f] + */ +fun hslToHSV( + hue: Float, + saturation: Float, + lightness: Float +): FloatArray { + val value = lightness + saturation * lightness.coerceAtMost(1 - lightness) + val saturationHSV = if (value == 0f) 0f else 2 * (1 - lightness / value) + return floatArrayOf(hue, saturationHSV.coerceIn(0f, 1f), value.coerceIn(0f, 1f)) +} + +/** + * Convert HSL components(hue-saturation-lightness) to HSV + * (hue-saturation-value) components. + * + * ``` +* hsv[0] is Hue [0 .. 360) +* hsv[1] is Saturation [0...1] +* hsv[2] is Value [0...1] +* ``` +* ``` +* hsl[0] is Hue [0 .. 360) +* hsl[1] is Saturation [0...1] +* hsl[2] is Lightness [0...1] +* ``` +*/ +fun hslToHSV(hslIn: FloatArray): FloatArray { +return hslToHSV(hslIn[0], hslIn[1], hslIn[2]) +} + +/* +HSL-ColorInt Conversions +*/ + +/** +* Convert HSL (hue-saturation-lightness) components to a RGB color in [Integer] format. +* +* For instance, red =255, green =0, blue=0 is -65536 +* ``` +* hsl[0] is Hue [0 .. 360) +* hsl[1] is Saturation [0...1] +* hsl[2] is Lightness [0...1] +* ``` +*/ +fun hslToColorInt(hslIn: FloatArray): Int { +return hslToColorInt(hslIn[0], hslIn[1], hslIn[2]) +} + +/** +* Convert HSL (hue-saturation-lightness) components to a RGB color in [Integer] format. +* @param hue in [0..360f] +* @param saturation in [0..1f] +* @param lightness in [0..1f] + */ + fun hslToColorInt( + hue: Float, + saturation: Float, + lightness: Float + ): Int { + return ColorUtils.HSLToColor(floatArrayOf(hue, saturation, lightness)) + } + + +/* +HSL-RGB Conversions +*/ + +/** +* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array. +* ``` +* hsl[0] is Hue [0 .. 360) +* hsl[1] is Saturation [0...1] +* hsl[2] is Lightness [0...1] +* ``` +* ``` +* rgb[0] is Red [0 .. 255] +* rgb[1] is Green [0...255] +* rgb[2] is Blue [0...255] +* ``` +* @param hslIn 3 element array which holds the input HSL components. + */ + fun hslToRGB(hslIn: FloatArray): IntArray { + return colorIntToRGBArray(hslToColorInt(hslIn)) + } + +/** +* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array. +* ``` +* Hue is [0 .. 360) +* Saturation is [0...1] +* Lightness is [0...1] +* ``` +* +* ``` +* rgb[0] is Red [0 .. 255] +* rgb[1] is Green [0...255] +* rgb[2] is Blue [0...255] +* ``` +*/ +fun hslToRGB( +hue: Float, +saturation: Float, +lightness: Float +): IntArray { +return colorIntToRGBArray( +color = hslToColorInt(hue, saturation, lightness) +) +} + +/** +* Convert HSL (hue-saturation-lightness) components to a RGB red, green blue array. +* ``` +* rgb[0] is Red [0 .. 255] +* rgb[1] is Green [0...255] +* rgb[2] is Blue [0...255] +* ``` +* @param hue in [0..360f] +* @param saturation in [0..1f] +* @param lightness in [0..1f] +* @param rgbIn 3 element array which holds the input RGB components. + */ + fun hslToRGB( + hue: Float, + saturation: Float, + lightness: Float, + rgbIn: IntArray + ) { + colorIntToRGBArray(hslToColorInt(hue, saturation, lightness), rgbIn) + } + + +/** +* Convert HSL (hue-saturation-lightness) to RGB red, green, blue components in [0f..1f] range. +* ``` +* rgb[0] is Red [0f .. 1f) +* rgb[1] is Green [0f...1f] +* rgb[2] is Blue [0f...1f] +* ``` +* @param hue in [0..360f] +* @param saturation in [0..1f] +* @param lightness in [0..1f] +* +* @return 3 element array which holds the output RGB components. + */ + fun hslToRGBFloat( + hue: Float, + saturation: Float, + lightness: Float + ): FloatArray { + val color = Color.hsl(hue, saturation, lightness) + return floatArrayOf(color.red, color.green, color.blue) + } + +/** +* Convert HSL (hue-saturation-lightness) to RGB red, green, blue components in [0f..1f] range. +* ``` +* rgb[0] is Red [0f .. 1f) +* rgb[1] is Green [0f...1f] +* rgb[2] is Blue [0f...1f] +* ``` +* @param hue in [0..360f] +* @param saturation in [0..1f] +* @param lightness in [0..1f] +* @param rgbIn 3 element array which holds the output RGB components. + */ + fun hslToRGBFloat( + hue: Float, + saturation: Float, + lightness: Float, + rgbIn: FloatArray + ) { + val color = Color.hsl(hue, saturation, lightness) + rgbIn[0] = color.red + rgbIn[1] = color.green + rgbIn[2] = color.blue + } +``` diff --git a/app/build.gradle b/app/build.gradle index 0882fd8..3d1ebdf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,9 +47,10 @@ android { dependencies { - implementation project(':extendedcolors') implementation 'androidx.core:core-ktx:1.7.0' + implementation 'com.github.SmartToolFactory:Compose-Extended-Colors:1.0.0-alpha02' + implementation "androidx.compose.ui:ui:$compose_version" implementation "androidx.compose.material:material:$compose_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" diff --git a/settings.gradle b/settings.gradle index 3812352..55b0aec 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,6 +10,7 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { url 'https://jitpack.io' } } } rootProject.name = "Compose Colors Extended"