forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend: SpecialColor translation (hannibal002#2854)
Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
- Loading branch information
1 parent
952f09e
commit f411297
Showing
11 changed files
with
77 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
src/main/java/at/hannibal2/skyhanni/utils/SpecialColor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package at.hannibal2.skyhanni.utils | ||
|
||
import java.awt.Color | ||
|
||
/** | ||
* Taken from NotEnoughUpdates, | ||
* translated to Kotlin and modified. | ||
*/ | ||
object SpecialColor { | ||
private const val MIN_CHROMA_SECS = 1 | ||
private const val MAX_CHROMA_SECS = 60 | ||
private var startTime = SimpleTimeMark.farPast() | ||
|
||
fun String.toSpecialColor() = Color(toSpecialColorInt(), true) | ||
|
||
fun String.toSpecialColorInt(): Int { | ||
if (startTime.isFarPast()) startTime = SimpleTimeMark.now() | ||
|
||
val (chroma, alpha, red, green, blue) = decompose(this) | ||
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 (alpha and 0xFF) shl 24 or (Color.HSBtoRGB(adjustedHue, sat, bri) and 0x00FFFFFF) | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters