seedy projeckt jolked
This commit is contained in:
53
src/main/kotlin/Util.kt
Normal file
53
src/main/kotlin/Util.kt
Normal file
@ -0,0 +1,53 @@
|
||||
package gay.pizza.CavesOfJolk
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import ktx.math.div
|
||||
import ktx.math.times
|
||||
import org.hsluv.HUSLColorConverter
|
||||
import kotlin.math.pow
|
||||
|
||||
fun Float.axisDeadzone(min: Float, max: Float): Float
|
||||
{
|
||||
val xabs = Math.abs(this)
|
||||
return if (xabs <= min) 0.0f
|
||||
else if (xabs >= max) Math.copySign(1.0f, this)
|
||||
else Math.copySign(xabs - min, this) / (max - min)
|
||||
}
|
||||
|
||||
fun Vector2.cardinalDeadzone(min: Float, max: Float)
|
||||
= Vector2(this.x.axisDeadzone(min, max), this.y.axisDeadzone(min, max))
|
||||
|
||||
fun Vector2.radialDeadzone(min: Float, max: Float): Vector2
|
||||
{
|
||||
val magnitude = this.len()
|
||||
if (magnitude == 0.0f || magnitude < min)
|
||||
return Vector2()
|
||||
if (magnitude > max)
|
||||
return this / magnitude
|
||||
val rescale = (magnitude - min) / (max - min)
|
||||
return this / magnitude * rescale
|
||||
}
|
||||
|
||||
val Double.saturate get() = if (this > 1.0) 1.0 else if (this < 0.0) 0.0 else this
|
||||
|
||||
class Util
|
||||
{
|
||||
companion object
|
||||
{
|
||||
public fun colorFromAbgr8888(abgr8888: UInt) = Color(
|
||||
(abgr8888 and 0xFFu).toFloat() / 255.0f,
|
||||
((abgr8888 and 0xFF00u) shr 8).toFloat() / 255.0f,
|
||||
((abgr8888 and 0xFF0000u) shr 16).toFloat() / 255.0f,
|
||||
((abgr8888 and 0xFF000000u) shr 24).toFloat() / 255.0f)
|
||||
}
|
||||
}
|
||||
|
||||
fun Color.lighten(ld: Double): Color
|
||||
{
|
||||
val hsl = HUSLColorConverter.rgbToHsluv(doubleArrayOf(r.toDouble(), g.toDouble(), b.toDouble()))
|
||||
val gamma = 3.0
|
||||
hsl[2] = ((hsl[2] / 100.0).pow(1.0 / gamma) + ld * 0.8).saturate.pow(gamma) * 100.0
|
||||
val rgb = HUSLColorConverter.hsluvToRgb(hsl)
|
||||
return Color(rgb[0].toFloat(), rgb[1].toFloat(), rgb[2].toFloat(), a)
|
||||
}
|
Reference in New Issue
Block a user