Skip to content

Commit

Permalink
feat: blend colors
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Jan 11, 2025
1 parent 43fb7de commit 4ae6d92
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ object ColorUtils {

fun rainbow(offset: Long, alpha: Int) = rainbow(offset, alpha.toFloat() / 255)

fun blendColors(color: Color, color2: Color): Color {
val alpha = color2.alpha / 255.0
val red = (color2.red * alpha + color.red * (1 - alpha)).toInt()
val green = (color2.green * alpha + color.green * (1 - alpha)).toInt()
val blue = (color2.blue * alpha + color.blue * (1 - alpha)).toInt()
return Color(red, green, blue)
}

fun rainbow(offset: Long = 400000L, alpha: Float = 1f): Color {
val currentColor = Color(Color.HSBtoRGB((System.nanoTime() + offset) / 10000000000F % 1, 1F, 1F))
return Color(currentColor.red / 255F, currentColor.green / 255F, currentColor.blue / 255F, alpha)
Expand Down

0 comments on commit 4ae6d92

Please sign in to comment.