-
Notifications
You must be signed in to change notification settings - Fork 1
Color
Shmellyorc edited this page Aug 31, 2026
·
2 revisions
Color is an RGBA color structure with byte channels for red, green, blue, and alpha. It provides comprehensive color manipulation including hex parsing, arithmetic operations, blending, and pre-defined colors.
| Field | Type | Description |
|---|---|---|
R |
byte |
The red component (0-255) |
G |
byte |
The green component (0-255) |
B |
byte |
The blue component (0-255) |
A |
byte |
The alpha component (0-255) |
| Property | Description |
|---|---|
IsEmpty |
Returns true if all color channels are zero |
Transparent |
Fully transparent color (0, 0, 0, 0) |
White |
White color (255, 255, 255, 255) |
Black |
Black color (0, 0, 0, 255) |
Red |
Red color (255, 0, 0, 255) |
Green |
Green color (0, 255, 0, 255) |
Blue |
Blue color (0, 0, 255, 255) |
Magenta |
Magenta color (255, 0, 255, 255) |
Cyan |
Cyan color (0, 255, 255, 255) |
Yellow |
Yellow color (255, 255, 0, 255) |
Orange |
Orange color (255, 165, 0, 255) |
Purple |
Purple color (128, 0, 128, 255) |
Pink |
Pink color (255, 192, 203, 255) |
Brown |
Brown color (165, 42, 42, 255) |
Gray |
Gray color (128, 128, 128, 255) |
DarkGray |
Dark gray color (64, 64, 64, 255) |
LightGray |
Light gray color (192, 192, 192, 255) |
Gold |
Gold color (255, 215, 0, 255) |
Silver |
Silver color (192, 192, 192, 255) |
Navy |
Navy color (0, 0, 128, 255) |
Olive |
Olive color (128, 128, 0, 255) |
Teal |
Teal color (0, 128, 128, 255) |
Aqua |
Aqua color (0, 255, 255, 255) |
Coral |
Coral color (255, 127, 80, 255) |
Crimson |
Crimson color (220, 20, 60, 255) |
DarkBlue |
Dark blue color (0, 0, 139, 255) |
DarkGreen |
Dark green color (0, 100, 0, 255) |
DarkRed |
Dark red color (139, 0, 0, 255) |
// Create from byte values (R, G, B, A)
var color1 = new Color(255, 128, 64, 255);
// Create from byte values (R, G, B) with alpha defaulting to 255
var color2 = new Color(255, 128, 64);
// Create from float values (0-1)
var color3 = new Color(1f, 0.5f, 0.25f, 1f);
// Create from integer values (0-255)
var color4 = new Color(255, 128, 64, 255);
// Create from hex string
var color5 = new Color("#FF8040");
var color6 = new Color("#AARRGGBB");| Format | Example | Description |
|---|---|---|
#RRGGBB |
#FF8040 |
RGB only, alpha defaults to 255 |
#AARRGGBB |
#80FF8040 |
Full RGBA |
#RGB |
#F84 |
Short RGB (expands to #FF8844) |
#ARGB |
#8F84 |
Short ARGB (expands to #88FF8844) |
Linearly interpolates between two colors.
var color1 = Color.Red;
var color2 = Color.Blue;
var blended = color1.Lerp(color2, 0.5f); // Purple (128, 0, 128)
var blended2 = Color.Lerp(color1, color2, 0.5f);Returns a new color with the same RGB values but a different alpha.
var red = Color.Red;
// Alpha as float (0-1)
var semiTransparent = red.WithAlpha(0.5f);
// Alpha as byte (0-255)
var semiTransparent2 = red.WithAlpha((byte)128);Scales a color by a scalar value or multiplies two colors component-wise.
var color = Color.Red;
// Scale by scalar
var scaled = color * 0.5f; // (127, 0, 0, 127)
// Component-wise multiplication
var a = new Color(255, 128, 64, 255);
var b = new Color(128, 255, 64, 255);
var result = a * b; // (128, 128, 64, 255)Adds or subtracts two colors component-wise.
var a = new Color(100, 50, 25, 255);
var b = new Color(50, 25, 10, 255);
var sum = a + b; // (150, 75, 35, 255)
var diff = a - b; // (50, 25, 15, 255)Compares two colors for equality.
var a = new Color(255, 0, 0, 255);
var b = Color.Red;
bool equal = a == b; // true
bool notEqual = a != Color.Blue; // true| Method | Description |
|---|---|
Lerp |
Linearly interpolates between two colors |
WithAlpha |
Returns a new color with a different alpha |
* |
Scales color by scalar or component-wise multiplication |
+ |
Adds two colors component-wise |
- |
Subtracts two colors component-wise |
== |
Compares two colors for equality |
!= |
Compares two colors for inequality |
- MathHelper
- FileHelper
- HashHelper
- JsonHelper
- MapHelper
- TextHelper
- SoundHelper
- AlignHelpers
- Instance Helper
- Enum Extensions
- String Extensions
- Int Extensions
- Float Extensions
- IEnumerable Extensions
- Random Extensions
- Sound Extensions
- Font Extensions