Skip to content

Commit

Permalink
get lib dependency from jitpack
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartToolFactory committed Apr 29, 2022
1 parent b2d5c62 commit 43e88e5
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 1 deletion.
216 changes: 216 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand All @@ -17,6 +19,31 @@
| ----------|-----------| -----------|
| <img src="./screenshots/material_design2.gif" width="300">| <img src="./screenshots/material_design3.gif" width="300"> | <img src="./screenshots/gradient_rotation.gif" width="300"> |

## 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:<version>'
}
```


## Material Design 2 Colors & Swatches

### Material Colors
Expand Down Expand Up @@ -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
}
```
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "Compose Colors Extended"
Expand Down

0 comments on commit 43e88e5

Please sign in to comment.