Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: SpecialColor translation #2854

Merged
merged 23 commits into from
Nov 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve decomposing
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
  • Loading branch information
j10a1n15 committed Oct 28, 2024
commit 98f0a822f210527ae13e87ef4a46568782309dc1
8 changes: 4 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ object SpecialColor {
fun specialToChromaRGB(special: String): Int {
if (startTime.isFarPast()) startTime = SimpleTimeMark.now()

val (b, g, r, a, chroma) = decompose(special)
val (hue, sat, bri) = Color.RGBtoHSB(r, g, b, null)
val (chroma, alpha, red, green, blue) = decompose(special)
val (hue, sat, bri) = Color.RGBtoHSB(red, green, blue, null)

val adjustedHue = if (chroma > 0) (hue + (startTime.passedSince().inWholeMilliseconds / 1000f / chromaSpeed(chroma) % 1)).let {
if (it < 0) it + 1f else it
} else hue

return (a and 0xFF) shl 24 or (Color.HSBtoRGB(adjustedHue, sat, bri) and 0x00FFFFFF)
return (alpha and 0xFF) shl 24 or (Color.HSBtoRGB(adjustedHue, sat, bri) and 0x00FFFFFF)
}

private fun decompose(csv: String) = csv.split(":").mapNotNull { it.toIntOrNull() }.reversed().toIntArray()
private fun decompose(csv: String) = csv.split(":").mapNotNull { it.toIntOrNull() }.toIntArray()
private fun chromaSpeed(speed: Int) = (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS
}
Loading