forked from AtomicGameEngine/AtomicGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.cs
More file actions
61 lines (51 loc) · 2.12 KB
/
Color.cs
File metadata and controls
61 lines (51 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.Runtime.InteropServices;
namespace AtomicEngine
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Color
{
public Color(float r, float g, float b, float a = 1.0f)
{
R = r;
G = g;
B = b;
A = a;
}
public uint ToUInt()
{
uint r = (uint)(R * 255.0f);
uint g = (uint)(G * 255.0f);
uint b = (uint)(B * 255.0f);
uint a = (uint)(A * 255.0f);
return (a << 24) | (b << 16) | (g << 8) | r;
}
public static readonly Color White = new Color(1, 1, 1);
public static readonly Color Gray = new Color(0.5f, 0.5f, 0.5f);
public static readonly Color Black = new Color(0.0f, 0.0f, 0.0f);
public static readonly Color Red = new Color(1.0f, 0.0f, 0.0f);
public static readonly Color Green = new Color(0.0f, 1.0f, 0.0f);
public static readonly Color Blue = new Color(0.0f, 0.0f, 1.0f);
public static readonly Color Cyan = new Color(0.0f, 1.0f, 1.0f);
public static readonly Color Magenta = new Color(1.0f, 0.0f, 1.0f);
public static readonly Color Yellow = new Color(1.0f, 1.0f, 0.0f);
public static readonly Color LightBlue = new Color(0.50f, 0.88f, 0.81f);
public static readonly Color Transparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
public static Color operator *(Color value, float scale)
{
return new Color((float)(value.R * scale), (float)(value.G * scale), (float)(value.B * scale), (float)(value.A * scale));
}
public static Color Lerp(Color value1, Color value2, float amount)
{
amount = MathHelper.Clamp(amount, 0, 1);
return new Color(
MathHelper.Lerp(value1.R, value2.R, amount),
MathHelper.Lerp(value1.G, value2.G, amount),
MathHelper.Lerp(value1.B, value2.B, amount),
MathHelper.Lerp(value1.A, value2.A, amount));
}
public float R;
public float G;
public float B;
public float A;
}
}