diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-22 19:23:29 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-22 19:23:29 -0700 |
commit | 971738ae5942c3439568c54393708a3dd63c87f6 (patch) | |
tree | b3a6f6ff623f163ac68b2e6f2d2c0776265cb473 /library/src/main | |
parent | 1d1322523492f3cc805d364ca9e3ef9a25b0fbad (diff) | |
download | kau-971738ae5942c3439568c54393708a3dd63c87f6.tar.gz kau-971738ae5942c3439568c54393708a3dd63c87f6.tar.bz2 kau-971738ae5942c3439568c54393708a3dd63c87f6.zip |
Change color lighten and darken
Diffstat (limited to 'library/src/main')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt index eaa6d91..2c5a395 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -71,14 +71,14 @@ fun Int.withMinAlpha(@IntRange(from = 0L, to = 255L) alpha: Int): Int @ColorInt fun Int.lighten(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int { val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this)) - .map { Math.min(it * (1 + factor), 255.0f).toInt() } + .map { Math.min(255f * factor + it, 255f).toInt() } return Color.argb(Color.alpha(this), red, green, blue) } @ColorInt fun Int.darken(@FloatRange(from = 0.0, to = 1.0) factor: Float = 0.2f): Int { val (red, green, blue) = intArrayOf(Color.red(this), Color.green(this), Color.blue(this)) - .map { Math.max(it * (1 - factor), 0f).toInt() } + .map { Math.max(it - 255f * factor, 0f).toInt() } return Color.argb(Color.alpha(this), red, green, blue) } |