-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExtensionMethods.cs
More file actions
33 lines (30 loc) · 1.05 KB
/
Copy pathExtensionMethods.cs
File metadata and controls
33 lines (30 loc) · 1.05 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
using System;
using System.Drawing;
namespace RubiksCubeSimulator
{
static class ExtensionMethods
{
public static Color Desaturate(this Color color)
{
var b = (int)(255 * color.GetBrightness());
return Color.FromArgb(b, b, b);
}
public static Color ChangeBrightness(this Color color, int factor)
{
int R = (color.R + factor > 255) ? 255 : color.R + factor;
int G = (color.G + factor > 255) ? 255 : color.G + factor;
int B = (color.B + factor > 255) ? 255 : color.B + factor;
R = (color.R + factor < 0) ? 0 : R;
G = (color.G + factor < 0) ? 0 : G;
B = (color.B + factor < 0) ? 0 : B;
return Color.FromArgb(R, G, B);
}
/// <summary>
/// Compares two colors using there RGB value (and not their names).
/// </summary>
public static bool RgbEquals(this Color c, Color color)
{
return (color.R == c.R && color.G == c.G && color.B == c.B);
}
}
}