Method to convert HSV colour to RGB, for Unity3D
It's a quick snippet, not meant to be pretty or efficient, but it is useful. Printing of strings using Debug.DrawLine. It has the advantage that you can print anywhere in your code for debugging purposes inline without using OnGUI(). It uses a 16 segment display. If you want more characters, just add them.
Enjoy.
/*
* a b
* cdefg
* h i
* jklmn
* o p
*
* bits: abcd efgh ijkl mnop
*/
void DebugText(Vector3 p, string v,float size=1.0f) {
Color col = Color.white;
float dur = 0.0f;
Vector4[] lines = new Vector4[] {
new Vector4( -1,1,0,1 ), // a
new Vector4( 0,1,1,1), // b
new Vector4( -1,1,-1,0), // c
new Vector4( -1,1,0,0), // d
new Vector4( 0,1,0,0), // e
new Vector4( 1,1,0,0), // f
new Vector4( 1,1,1,0), // g
new Vector4( -1,0,0,0), // h
new Vector4(0,0,1,0), // i
new Vector4(-1,0,-1,-1), // j
new Vector4(0,0,-1,0-1), // k
new Vector4(0,0,0,-1), // l
new Vector4(0,0,1,-1), // m
new Vector4(1,0,1,-1), // n
new Vector4(-1,-1,0,-1), // o
new Vector4(0,-1,1,-1), // p
};
int[] chars = {
0xe667, // 0
0x0604, // 1
0xc3c3, // 2
0xc287, // 3
0x2990, // 4
0xe187, // 5
0xe1c7, // 6
0xc410, // 7
0xe3c7, // 8
0xe384, // 9
0xe3c4, // A
0xca97, // B
0xe043, // C
0xca17, // D
0xe1c3, // E
0xe140, // F
0xe0c7, // G
0x23c4, // H
0xc813, // I
0xc852, // J
0x2548, // K
0x2043, // L
0x3644, // M
0x324c, // N
0xe247, // O
0xe3c0, // P
0xe24f, // Q
0xe3c8, // R
0xd087, // S
0xc810, // T
0x2247, // U
0x2460, // V
0x226c, // W
0x1428, // X
0x1410, // Y
0xc423, // Z
0x0000, // space
0x0002, // .
0x0100, // -
};
for (int m = 0; m < v.Length; m++) {
int n = v[m];
int c =-1;
if (n >= '0' && n <= '9') {
n = n - '0';
c = chars[n];
} else if (n >= 'A' && n <= 'Z') {
n = n - 'A' + 10;
c = chars[n];
} else if (n >= 'a' && n <= 'z') {
n = n - 'a' + 10;
c = chars[n];
} else if (n == ' ') {
c = chars[26 + 10];
} else if (n == '.') {
c = chars[26 + 11];
} else if (n == '-') {
c = chars[26 + 11];
}
for (int i = 0; i < 16; i++) {
if ((c & (1 << (15 - i))) != 0) {
Debug.DrawLine(
new Vector3(m * 2.0f * size + p.x + lines[i].x / 2 * size, p.y, p.z + lines[i].y * size),
new Vector3(m * 2.0f * size + p.x + lines[i].z / 2 * size, p.y, p.z + lines[i].w * size),
col,
dur);
}
}
}
}
Enjoy.
/*
* a b
* cdefg
* h i
* jklmn
* o p
*
* bits: abcd efgh ijkl mnop
*/
void DebugText(Vector3 p, string v,float size=1.0f) {
Color col = Color.white;
float dur = 0.0f;
Vector4[] lines = new Vector4[] {
new Vector4( -1,1,0,1 ), // a
new Vector4( 0,1,1,1), // b
new Vector4( -1,1,-1,0), // c
new Vector4( -1,1,0,0), // d
new Vector4( 0,1,0,0), // e
new Vector4( 1,1,0,0), // f
new Vector4( 1,1,1,0), // g
new Vector4( -1,0,0,0), // h
new Vector4(0,0,1,0), // i
new Vector4(-1,0,-1,-1), // j
new Vector4(0,0,-1,0-1), // k
new Vector4(0,0,0,-1), // l
new Vector4(0,0,1,-1), // m
new Vector4(1,0,1,-1), // n
new Vector4(-1,-1,0,-1), // o
new Vector4(0,-1,1,-1), // p
};
int[] chars = {
0xe667, // 0
0x0604, // 1
0xc3c3, // 2
0xc287, // 3
0x2990, // 4
0xe187, // 5
0xe1c7, // 6
0xc410, // 7
0xe3c7, // 8
0xe384, // 9
0xe3c4, // A
0xca97, // B
0xe043, // C
0xca17, // D
0xe1c3, // E
0xe140, // F
0xe0c7, // G
0x23c4, // H
0xc813, // I
0xc852, // J
0x2548, // K
0x2043, // L
0x3644, // M
0x324c, // N
0xe247, // O
0xe3c0, // P
0xe24f, // Q
0xe3c8, // R
0xd087, // S
0xc810, // T
0x2247, // U
0x2460, // V
0x226c, // W
0x1428, // X
0x1410, // Y
0xc423, // Z
0x0000, // space
0x0002, // .
0x0100, // -
};
for (int m = 0; m < v.Length; m++) {
int n = v[m];
int c =-1;
if (n >= '0' && n <= '9') {
n = n - '0';
c = chars[n];
} else if (n >= 'A' && n <= 'Z') {
n = n - 'A' + 10;
c = chars[n];
} else if (n >= 'a' && n <= 'z') {
n = n - 'a' + 10;
c = chars[n];
} else if (n == ' ') {
c = chars[26 + 10];
} else if (n == '.') {
c = chars[26 + 11];
} else if (n == '-') {
c = chars[26 + 11];
}
for (int i = 0; i < 16; i++) {
if ((c & (1 << (15 - i))) != 0) {
Debug.DrawLine(
new Vector3(m * 2.0f * size + p.x + lines[i].x / 2 * size, p.y, p.z + lines[i].y * size),
new Vector3(m * 2.0f * size + p.x + lines[i].z / 2 * size, p.y, p.z + lines[i].w * size),
col,
dur);
}
}
}
}