mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 13:21:51 +09:00
more Kotlin, UIs now can open/close with animation, working world time with skybox colour changing (sunlight transition is still WIP), fixed project library settings so that the suggestion in IntelliJ IDEA would work properly
Former-commit-id: 82c857164f2636ad943d5a43f0690a3431ab0f26 Former-commit-id: 7c8b70e6b267f7c5c050d7d0902278739ec18b44
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
package com.Torvald.ColourUtil;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-11.
|
||||
*/
|
||||
public class Col216 implements LimitedColours {
|
||||
|
||||
private byte data;
|
||||
private static transient final int[] LOOKUP = {0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF};
|
||||
|
||||
public static final int MUL = 6;
|
||||
public static final int MUL_2 = MUL * MUL;
|
||||
public static final int MAX_STEP = MUL - 1;
|
||||
public static final int COLOUR_DOMAIN_SIZE = MUL_2 * MUL;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public Col216(byte data) {
|
||||
create(data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param r 0-5
|
||||
* @param g 0-5
|
||||
* @param b 0-5
|
||||
*/
|
||||
public Col216(int r, int g, int b) {
|
||||
create(r, g, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color createSlickColor(int raw) {
|
||||
assertRaw(raw);
|
||||
int r = raw / MUL_2;
|
||||
int g = (raw % MUL_2) / MUL;
|
||||
int b = raw % MUL;
|
||||
|
||||
return createSlickColor(r, g, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color createSlickColor(int r, int g, int b) {
|
||||
assertRGB(r, g, b);
|
||||
return new Color(LOOKUP[r], LOOKUP[g], LOOKUP[b]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(int raw) {
|
||||
assertRaw(raw);
|
||||
data = (byte) raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(int r, int g, int b) {
|
||||
assertRGB(r, g, b);
|
||||
data = (byte) (MUL_2 * r + MUL * g + b);
|
||||
}
|
||||
|
||||
public byte getRaw() { return data; }
|
||||
|
||||
private void assertRaw(int i) {
|
||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||
System.out.println("i: " + String.valueOf(i));
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertRGB(int r, int g, int b) {
|
||||
if (r > MAX_STEP || g > MAX_STEP || b > MAX_STEP || r < 0 || g < 0 || b < 0) {
|
||||
System.out.println("r: " + String.valueOf(r));
|
||||
System.out.println("g: " + String.valueOf(g));
|
||||
System.out.println("b: " + String.valueOf(b));
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
82
src/com/Torvald/ColourUtil/Col216.kt
Normal file
82
src/com/Torvald/ColourUtil/Col216.kt
Normal file
@@ -0,0 +1,82 @@
|
||||
package com.Torvald.ColourUtil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* 6-Step RGB with builtin utils.
|
||||
* Created by minjaesong on 16-02-11.
|
||||
*/
|
||||
class Col216 : LimitedColours {
|
||||
|
||||
var raw: Byte = 0
|
||||
private set
|
||||
|
||||
/**
|
||||
|
||||
* @param data
|
||||
*/
|
||||
constructor(data: Byte) {
|
||||
create(data.toInt())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @param r 0-5
|
||||
* *
|
||||
* @param g 0-5
|
||||
* *
|
||||
* @param b 0-5
|
||||
*/
|
||||
constructor(r: Int, g: Int, b: Int) {
|
||||
create(r, g, b)
|
||||
}
|
||||
|
||||
override fun createSlickColor(raw: Int): Color {
|
||||
assertRaw(raw)
|
||||
val r = raw / MUL_2
|
||||
val g = raw % MUL_2 / MUL
|
||||
val b = raw % MUL
|
||||
|
||||
return createSlickColor(r, g, b)
|
||||
}
|
||||
|
||||
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||
assertRGB(r, g, b)
|
||||
return Color(LOOKUP[r], LOOKUP[g], LOOKUP[b])
|
||||
}
|
||||
|
||||
override fun create(raw: Int) {
|
||||
assertRaw(raw)
|
||||
this.raw = raw.toByte()
|
||||
}
|
||||
|
||||
override fun create(r: Int, g: Int, b: Int) {
|
||||
assertRGB(r, g, b)
|
||||
raw = (MUL_2 * r + MUL * g + b).toByte()
|
||||
}
|
||||
|
||||
private fun assertRaw(i: Int) {
|
||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||
println("i: " + i.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertRGB(r: Int, g: Int, b: Int) {
|
||||
if (r !in 0..MAX_STEP || g !in 0..MAX_STEP || b !in 0..MAX_STEP) {
|
||||
println("r: " + r.toString())
|
||||
println("g: " + g.toString())
|
||||
println("b: " + b.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Transient private val LOOKUP = intArrayOf(0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF)
|
||||
|
||||
const val MUL = 6
|
||||
const val MUL_2 = MUL * MUL
|
||||
const val MAX_STEP = MUL - 1
|
||||
const val COLOUR_DOMAIN_SIZE = MUL_2 * MUL
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package com.Torvald.ColourUtil;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-20.
|
||||
*/
|
||||
public class Col40 implements LimitedColours {
|
||||
|
||||
private char data;
|
||||
private static transient final int[] LOOKUP = {0,7,13,20,26,33,39,46,52,59,65,72,78,85,92,98,105,111,118,124
|
||||
,131,137,144,150,157,163,170,177,183,190,196,203,209,216,222,229,235,242,248,255};
|
||||
|
||||
public static final int MUL = 40;
|
||||
public static final int MUL_2 = MUL * MUL;
|
||||
public static final int MAX_STEP = MUL - 1;
|
||||
public static final int COLOUR_DOMAIN_SIZE = MUL_2 * MUL;
|
||||
|
||||
@Override
|
||||
public Color createSlickColor(int raw) {
|
||||
assertRaw(raw);
|
||||
int r = raw / MUL_2;
|
||||
int g = (raw % MUL_2) / MUL;
|
||||
int b = raw % MUL;
|
||||
|
||||
return createSlickColor(r, g, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color createSlickColor(int r, int g, int b) {
|
||||
assertRGB(r, g, b);
|
||||
return new Color((LOOKUP[r] << 16) | (LOOKUP[g] << 8) | LOOKUP[b]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(int raw) {
|
||||
assertRaw(raw);
|
||||
data = (char) raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(int r, int g, int b) {
|
||||
assertRGB(r, g, b);
|
||||
data = (char) (MUL_2 * r + MUL * g + b);
|
||||
}
|
||||
|
||||
public char getRaw() { return data; }
|
||||
|
||||
private void assertRaw(int i) {
|
||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||
System.out.println("i: " + String.valueOf(i));
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertRGB(int r, int g, int b) {
|
||||
if (r > MAX_STEP || g > MAX_STEP || b > MAX_STEP || r < 0 || g < 0 || b < 0) {
|
||||
System.out.println("r: " + String.valueOf(r));
|
||||
System.out.println("g: " + String.valueOf(g));
|
||||
System.out.println("b: " + String.valueOf(b));
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
72
src/com/Torvald/ColourUtil/Col40.kt
Normal file
72
src/com/Torvald/ColourUtil/Col40.kt
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.Torvald.ColourUtil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* 40-Step RGB with builtin utils.
|
||||
* Created by minjaesong on 16-02-20.
|
||||
*/
|
||||
class Col40 : LimitedColours {
|
||||
|
||||
var raw: Char = ' '
|
||||
private set
|
||||
|
||||
override fun createSlickColor(raw: Int): Color {
|
||||
assertRaw(raw)
|
||||
val r = raw / MUL_2
|
||||
val g = raw % MUL_2 / MUL
|
||||
val b = raw % MUL
|
||||
|
||||
return createSlickColor(r, g, b)
|
||||
}
|
||||
|
||||
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||
assertRGB(r, g, b)
|
||||
return Color(LOOKUP[r] shl 16 or (LOOKUP[g] shl 8) or LOOKUP[b])
|
||||
}
|
||||
|
||||
override fun create(raw: Int) {
|
||||
assertRaw(raw)
|
||||
this.raw = raw.toChar()
|
||||
}
|
||||
|
||||
override fun create(r: Int, g: Int, b: Int) {
|
||||
assertRGB(r, g, b)
|
||||
raw = (MUL_2 * r + MUL * g + b).toChar()
|
||||
}
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
constructor(c: Color) {
|
||||
create(
|
||||
Math.round(c.r * (MUL - 1)),
|
||||
Math.round(c.g * (MUL - 1)),
|
||||
Math.round(c.b * (MUL - 1)))
|
||||
}
|
||||
|
||||
private fun assertRaw(i: Int) {
|
||||
if (i >= COLOUR_DOMAIN_SIZE || i < 0) {
|
||||
println("i: " + i.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertRGB(r: Int, g: Int, b: Int) {
|
||||
if (r !in 0..MAX_STEP || g !in 0..MAX_STEP || b !in 0..MAX_STEP) {
|
||||
println("r: " + r.toString())
|
||||
println("g: " + g.toString())
|
||||
println("b: " + b.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Transient private val LOOKUP = intArrayOf(0, 7, 13, 20, 26, 33, 39, 46, 52, 59, 65, 72, 78, 85, 92, 98, 105, 111, 118, 124, 131, 137, 144, 150, 157, 163, 170, 177, 183, 190, 196, 203, 209, 216, 222, 229, 235, 242, 248, 255)
|
||||
|
||||
const val MUL = 40
|
||||
const val MUL_2 = MUL * MUL
|
||||
const val MAX_STEP = MUL - 1
|
||||
const val COLOUR_DOMAIN_SIZE = MUL_2 * MUL
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package com.Torvald.ColourUtil;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-23.
|
||||
*
|
||||
* 12-bit RGB
|
||||
*/
|
||||
public class Col4096 implements LimitedColours {
|
||||
|
||||
private short data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public Col4096(int data) {
|
||||
create(data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param r 0-15
|
||||
* @param g 0-15
|
||||
* @param b 0-15
|
||||
*/
|
||||
public Col4096(int r, int g, int b) {
|
||||
create(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Col4096 colour and convert it to Slick Color
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public Color createSlickColor(int i) {
|
||||
assertRaw(i);
|
||||
|
||||
int a, r, g, b;
|
||||
|
||||
r = (i & 0xF00) >> 8;
|
||||
g = (i & 0x0F0) >> 4;
|
||||
b = i & 0x00F;
|
||||
|
||||
if (i > 0xFFF) {
|
||||
a = (i & 0xF000) >> 12;
|
||||
|
||||
return new Color(
|
||||
(r << 4) | r
|
||||
, (g << 4) | g
|
||||
, (b << 4) | b
|
||||
, (a << 4) | a
|
||||
);
|
||||
}
|
||||
else {
|
||||
return new Color(
|
||||
(r << 4) | r
|
||||
, (g << 4) | g
|
||||
, (b << 4) | b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color createSlickColor(int r, int g, int b) {
|
||||
assertARGB(0, r, g, b);
|
||||
return createSlickColor(r << 8 | g << 4 | b);
|
||||
}
|
||||
|
||||
public Color createSlickColor(int a, int r, int g, int b) {
|
||||
assertARGB(a, r, g, b);
|
||||
return createSlickColor(a << 12 |r << 8 | g << 4 | b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(int raw) {
|
||||
assertRaw(raw);
|
||||
data = (short) (raw & 0xFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(int r, int g, int b) {
|
||||
assertARGB(0, r, g, b);
|
||||
data = (short) (r << 8 | g << 4 | b);
|
||||
}
|
||||
|
||||
public void create(int a, int r, int g, int b) {
|
||||
assertARGB(a, r, g, b);
|
||||
data = (short) (a << 12 | r << 8 | g << 4 | b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to 3 byte values, for raster imaging.
|
||||
* @return byte[RR, GG, BB] e.g. 0x4B3 -> 0x44, 0xBB, 0x33
|
||||
*/
|
||||
public byte[] toByteArray() {
|
||||
byte[] ret = new byte[3];
|
||||
int r = (data & 0xF00) >> 8;
|
||||
int g = (data & 0x0F0) >> 4;
|
||||
int b = data & 0x00F;
|
||||
|
||||
ret[0] = (byte) ((r << 4) | r);
|
||||
ret[1] = (byte) ((g << 4) | g);
|
||||
ret[2] = (byte) ((b << 4) | b);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve raw ARGB value
|
||||
* @return 0xARGB
|
||||
*/
|
||||
public short getRaw() {
|
||||
return data;
|
||||
}
|
||||
|
||||
private void assertRaw(int i) {
|
||||
if (i > 0xFFFF || i < 0) {
|
||||
System.out.println("i: " + String.valueOf(i));
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertARGB(int a, int r, int g, int b) {
|
||||
if (a > 16 || r > 16 || g > 16 || b > 16 || r < 0 || g < 0 || b < 0 || a < 0) {
|
||||
System.out.println("a: " + String.valueOf(a));
|
||||
System.out.println("r: " + String.valueOf(r));
|
||||
System.out.println("g: " + String.valueOf(g));
|
||||
System.out.println("b: " + String.valueOf(b));
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
127
src/com/Torvald/ColourUtil/Col4096.kt
Normal file
127
src/com/Torvald/ColourUtil/Col4096.kt
Normal file
@@ -0,0 +1,127 @@
|
||||
package com.Torvald.ColourUtil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* 12-bit (16-step) RGB with builtin utils.
|
||||
* Created by minjaesong on 16-01-23.
|
||||
*/
|
||||
class Col4096 : LimitedColours {
|
||||
|
||||
/**
|
||||
* Retrieve raw ARGB value
|
||||
* @return 0xARGB
|
||||
*/
|
||||
var raw: Short = 0
|
||||
private set
|
||||
|
||||
/**
|
||||
|
||||
* @param data
|
||||
*/
|
||||
constructor(data: Int) {
|
||||
create(data)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @param r 0-15
|
||||
* *
|
||||
* @param g 0-15
|
||||
* *
|
||||
* @param b 0-15
|
||||
*/
|
||||
constructor(r: Int, g: Int, b: Int) {
|
||||
create(r, g, b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Col4096 colour and convert it to Slick Color
|
||||
* @param i
|
||||
* *
|
||||
* @return
|
||||
*/
|
||||
override fun createSlickColor(raw: Int): Color {
|
||||
assertRaw(raw)
|
||||
|
||||
val a: Int
|
||||
val r: Int
|
||||
val g: Int
|
||||
val b: Int
|
||||
|
||||
r = raw and 0xF00 shr 8
|
||||
g = raw and 0x0F0 shr 4
|
||||
b = raw and 0x00F
|
||||
|
||||
if (raw > 0xFFF) {
|
||||
a = raw and 0xF000 shr 12
|
||||
|
||||
return Color(
|
||||
r shl 4 or r, g shl 4 or g, b shl 4 or b, a shl 4 or a)
|
||||
}
|
||||
else {
|
||||
return Color(
|
||||
r shl 4 or r, g shl 4 or g, b shl 4 or b)
|
||||
}
|
||||
}
|
||||
|
||||
override fun createSlickColor(r: Int, g: Int, b: Int): Color {
|
||||
assertARGB(0, r, g, b)
|
||||
return createSlickColor(r shl 8 or g shl 4 or b)
|
||||
}
|
||||
|
||||
fun createSlickColor(a: Int, r: Int, g: Int, b: Int): Color {
|
||||
assertARGB(a, r, g, b)
|
||||
return createSlickColor(a shl 12 or r shl 8 or g shl 4 or b)
|
||||
}
|
||||
|
||||
override fun create(raw: Int) {
|
||||
assertRaw(raw)
|
||||
this.raw = (raw and 0xFFFF).toShort()
|
||||
}
|
||||
|
||||
override fun create(r: Int, g: Int, b: Int) {
|
||||
assertARGB(0, r, g, b)
|
||||
raw = (r shl 8 or g shl 4 or b).toShort()
|
||||
}
|
||||
|
||||
fun create(a: Int, r: Int, g: Int, b: Int) {
|
||||
assertARGB(a, r, g, b)
|
||||
raw = (a shl 12 or r shl 8 or g shl 4 or b).toShort()
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to 3 byte values, for raster imaging.
|
||||
* @return byte[RR, GG, BB] e.g. 0x4B3 -> 0x44, 0xBB, 0x33
|
||||
*/
|
||||
fun toByteArray(): ByteArray {
|
||||
val ret = ByteArray(3)
|
||||
val r = (raw.toInt() and 0xF00) shr 8
|
||||
val g = (raw.toInt() and 0x0F0) shr 4
|
||||
val b = (raw.toInt() and 0x00F)
|
||||
|
||||
ret[0] = (r shl 4 or r).toByte()
|
||||
ret[1] = (g shl 4 or g).toByte()
|
||||
ret[2] = (b shl 4 or b).toByte()
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
private fun assertRaw(i: Int) {
|
||||
if (i > 0xFFFF || i < 0) {
|
||||
println("i: " + i.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertARGB(a: Int, r: Int, g: Int, b: Int) {
|
||||
if (a !in 0..16 || r !in 0..16 || g !in 0..16 || b !in 0..16) {
|
||||
println("a: " + a.toString())
|
||||
println("r: " + r.toString())
|
||||
println("g: " + g.toString())
|
||||
println("b: " + b.toString())
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.Torvald.ColourUtil;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-10.
|
||||
*/
|
||||
public class HSV {
|
||||
private float H;
|
||||
private float S;
|
||||
private float V;
|
||||
|
||||
public HSV() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param h 0-359
|
||||
* @param s 0-1
|
||||
* @param v 0-1
|
||||
*/
|
||||
public HSV(float h, float s, float v) {
|
||||
H = h;
|
||||
S = s;
|
||||
V = v;
|
||||
}
|
||||
|
||||
public float getH() {
|
||||
return H;
|
||||
}
|
||||
|
||||
public void setH(float h) {
|
||||
H = h;
|
||||
}
|
||||
|
||||
public float getS() {
|
||||
return S;
|
||||
}
|
||||
|
||||
public void setS(float s) {
|
||||
S = s;
|
||||
}
|
||||
|
||||
public float getV() {
|
||||
return V;
|
||||
}
|
||||
|
||||
public void setV(float v) {
|
||||
V = v;
|
||||
}
|
||||
}
|
||||
15
src/com/Torvald/ColourUtil/HSV.kt
Normal file
15
src/com/Torvald/ColourUtil/HSV.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.Torvald.ColourUtil
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-03-10.
|
||||
*/
|
||||
/**
|
||||
* @param h : Hue 0-359
|
||||
* @param s : Saturation 0-1
|
||||
* @param v : Value (brightness in Adobe Photoshop(TM)) 0-1
|
||||
*/
|
||||
data class HSV(
|
||||
var h: Float,
|
||||
var s: Float,
|
||||
var v: Float
|
||||
)
|
||||
@@ -1,109 +0,0 @@
|
||||
package com.Torvald.ColourUtil;
|
||||
|
||||
import com.jme3.math.FastMath;
|
||||
import org.newdawn.slick.Color;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-16.
|
||||
*/
|
||||
public class HSVUtil {
|
||||
|
||||
/**
|
||||
* Convert HSV parameters to RGB color.
|
||||
* @param H 0-359 Hue
|
||||
* @param S 0-1 Saturation
|
||||
* @param V 0-1 Value
|
||||
* @return org.newdawn.slick.Color
|
||||
* @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
|
||||
*/
|
||||
public static Color toRGB(float H, float S, float V) {
|
||||
H %= 360;
|
||||
|
||||
float C = V * S;
|
||||
float X = C * (1 - FastMath.abs(
|
||||
(H / 60f) % 2 - 1
|
||||
));
|
||||
float m = V - C;
|
||||
|
||||
float R_prime = Float.NaN;
|
||||
float G_prime = Float.NaN;
|
||||
float B_prime = Float.NaN;
|
||||
|
||||
if (H < 60) {
|
||||
R_prime = C;
|
||||
G_prime = X;
|
||||
B_prime = 0;
|
||||
}
|
||||
else if (H < 120) {
|
||||
R_prime = X;
|
||||
G_prime = C;
|
||||
B_prime = 0;
|
||||
}
|
||||
else if (H < 180) {
|
||||
R_prime = 0;
|
||||
G_prime = C;
|
||||
B_prime = X;
|
||||
}
|
||||
else if (H < 240) {
|
||||
R_prime = 0;
|
||||
G_prime = X;
|
||||
B_prime = C;
|
||||
}
|
||||
else if (H < 300) {
|
||||
R_prime = X;
|
||||
G_prime = 0;
|
||||
B_prime = C;
|
||||
}
|
||||
else if (H < 360) {
|
||||
R_prime = C;
|
||||
G_prime = 0;
|
||||
B_prime = X;
|
||||
}
|
||||
|
||||
return new Color(
|
||||
(R_prime + m)
|
||||
, (G_prime + m)
|
||||
, (B_prime + m)
|
||||
);
|
||||
}
|
||||
|
||||
public static Color toRGB(HSV hsv) {
|
||||
return toRGB(hsv.getH(), hsv.getS(), hsv.getV());
|
||||
}
|
||||
|
||||
public static HSV fromRGB(Color color) {
|
||||
float r = color.r;
|
||||
float g = color.g;
|
||||
float b = color.b;
|
||||
|
||||
float rgbMin = FastMath.min(r, g, b);
|
||||
float rgbMax = FastMath.max(r, g, b);
|
||||
|
||||
float h;
|
||||
float s;
|
||||
float v = rgbMax;
|
||||
|
||||
float delta = rgbMax - rgbMin;
|
||||
|
||||
if (rgbMax != 0)
|
||||
s = delta / rgbMax;
|
||||
else {
|
||||
h = 0;
|
||||
s = 0;
|
||||
return new HSV(h, s, v);
|
||||
}
|
||||
|
||||
if (r == rgbMax)
|
||||
h = (g - b) / delta;
|
||||
else if (g == rgbMax)
|
||||
h = 2 + (b - r) / delta;
|
||||
else
|
||||
h = 4 + (r - g) / delta;
|
||||
|
||||
h *= 60;
|
||||
if (h < 0) h += 360;
|
||||
|
||||
return new HSV(h, s, v);
|
||||
}
|
||||
|
||||
}
|
||||
110
src/com/Torvald/ColourUtil/HSVUtil.kt
Normal file
110
src/com/Torvald/ColourUtil/HSVUtil.kt
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.Torvald.ColourUtil
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-01-16.
|
||||
*/
|
||||
object HSVUtil {
|
||||
|
||||
/**
|
||||
* Convert HSV parameters to RGB color.
|
||||
* @param H 0-359 Hue
|
||||
* *
|
||||
* @param S 0-1 Saturation
|
||||
* *
|
||||
* @param V 0-1 Value
|
||||
* *
|
||||
* @return org.newdawn.slick.Color
|
||||
* *
|
||||
* @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
|
||||
*/
|
||||
fun toRGB(H: Float, S: Float, V: Float): Color {
|
||||
var H = H
|
||||
H %= 360f
|
||||
|
||||
val C = V * S
|
||||
val X = C * (1 - FastMath.abs(
|
||||
H / 60f % 2 - 1))
|
||||
val m = V - C
|
||||
|
||||
var R_prime = java.lang.Float.NaN
|
||||
var G_prime = java.lang.Float.NaN
|
||||
var B_prime = java.lang.Float.NaN
|
||||
|
||||
if (H < 60) {
|
||||
R_prime = C
|
||||
G_prime = X
|
||||
B_prime = 0f
|
||||
}
|
||||
else if (H < 120) {
|
||||
R_prime = X
|
||||
G_prime = C
|
||||
B_prime = 0f
|
||||
}
|
||||
else if (H < 180) {
|
||||
R_prime = 0f
|
||||
G_prime = C
|
||||
B_prime = X
|
||||
}
|
||||
else if (H < 240) {
|
||||
R_prime = 0f
|
||||
G_prime = X
|
||||
B_prime = C
|
||||
}
|
||||
else if (H < 300) {
|
||||
R_prime = X
|
||||
G_prime = 0f
|
||||
B_prime = C
|
||||
}
|
||||
else if (H < 360) {
|
||||
R_prime = C
|
||||
G_prime = 0f
|
||||
B_prime = X
|
||||
}
|
||||
|
||||
return Color(
|
||||
R_prime + m, G_prime + m, B_prime + m)
|
||||
}
|
||||
|
||||
fun toRGB(hsv: HSV): Color {
|
||||
return toRGB(hsv.h, hsv.s, hsv.v)
|
||||
}
|
||||
|
||||
fun fromRGB(color: Color): HSV {
|
||||
val r = color.r
|
||||
val g = color.g
|
||||
val b = color.b
|
||||
|
||||
val rgbMin = FastMath.min(r, g, b)
|
||||
val rgbMax = FastMath.max(r, g, b)
|
||||
|
||||
var h: Float
|
||||
val s: Float
|
||||
val v = rgbMax
|
||||
|
||||
val delta = rgbMax - rgbMin
|
||||
|
||||
if (rgbMax != 0f)
|
||||
s = delta / rgbMax
|
||||
else {
|
||||
h = 0f
|
||||
s = 0f
|
||||
return HSV(h, s, v)
|
||||
}
|
||||
|
||||
if (r == rgbMax)
|
||||
h = (g - b) / delta
|
||||
else if (g == rgbMax)
|
||||
h = 2 + (b - r) / delta
|
||||
else
|
||||
h = 4 + (r - g) / delta
|
||||
|
||||
h *= 60f
|
||||
if (h < 0) h += 360f
|
||||
|
||||
return HSV(h, s, v)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.Torvald.ColourUtil;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-11.
|
||||
*/
|
||||
public interface LimitedColours {
|
||||
|
||||
|
||||
|
||||
Color createSlickColor(int raw);
|
||||
Color createSlickColor(int r, int g, int b);
|
||||
|
||||
void create(int raw);
|
||||
void create(int r, int g, int b);
|
||||
|
||||
}
|
||||
17
src/com/Torvald/ColourUtil/LimitedColours.kt
Normal file
17
src/com/Torvald/ColourUtil/LimitedColours.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.Torvald.ColourUtil
|
||||
|
||||
import org.newdawn.slick.Color
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-11.
|
||||
*/
|
||||
interface LimitedColours {
|
||||
|
||||
|
||||
fun createSlickColor(raw: Int): Color
|
||||
fun createSlickColor(r: Int, g: Int, b: Int): Color
|
||||
|
||||
fun create(raw: Int)
|
||||
fun create(r: Int, g: Int, b: Int)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user