RgbColor class
Implements
Constructors
factory RgbColor(int r, int g, int b) #
factory RgbColor(int r, int g, int b) { _validateComponent(r, 'r'); _validateComponent(g, 'g'); _validateComponent(b, 'b'); return new RgbColor._internal(r, g, b); }
factory RgbColor.fromHex(String hexColor) #
factory RgbColor.fromHex(String hexColor) { requireArgumentNotNull(hexColor, 'hexColor'); hexColor = _normalizeHex(hexColor); var r = math.parseInt('0x'.concat(hexColor.substring(1, 3))); var g = math.parseInt('0x'.concat(hexColor.substring(3, 5))); var b = math.parseInt('0x'.concat(hexColor.substring(5, 7))); return new RgbColor(r,g,b); }
const RgbColor._internal(int r, int g, int b) #
const RgbColor._internal(this.r, this.g, this.b);
Fields
final int b #
final int r, g, b;
final int g #
final int r, g, b;
final int r #
final int r, g, b;
Methods
bool operator ==(RgbColor other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.
bool operator ==(RgbColor other) { return other != null && other.r == r && other.g == g && other.b == b; }
int hashCode() #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==
. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.
int hashCode() => Util.getHashCode([r,g,b]);
noSuchMethod(String name, List args) #
noSuchMethod
is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod
. If noSuchMethod
returns a value, that value becomes the result of the original
invocation.
The default behavior of noSuchMethod
is to throw a
noSuchMethodError
.
external Dynamic noSuchMethod(String name, List args);
Type get runtimeType() #
A representation of the runtime type of the object.
external Type get runtimeType;
String toHex() #
String toHex() { final buffer = new StringBuffer('#'); [r,g,b].forEach((c) { buffer.add(_prependZeroIfNecessaryHelper(c.toRadixString(16))); }); return buffer.toString(); }
HslColor toHsl() #
HslColor toHsl() { // First must normalize r, g, b to be between 0 and 1. final normR = r / 255; final normG = g / 255; final normB = b / 255; final max = math.max(normR, math.max(normG, normB)); final min = math.min(normR, math.min(normG, normB)); // Luminosity is the average of the max and min rgb color intensities. final l = 0.5 * (max + min); double h = 0.0; double s = 0.0; // The hue and saturation are dependent on which color intensity is the max. // If max and min are equal, the color is gray and h and s should be 0. if (max != min) { if (max == normR) { h = 60 * (normG - normB) / (max - min); } else if (max == normG) { h = 60 * (normB - normR) / (max - min) + 120; } else if (max == normB) { h = 60 * (normR - normG) / (max - min) + 240; } if (0 < l && l <= 0.5) { s = (max - min) / (2 * l); } else { s = (max - min) / (2 - 2 * l); // handle a nice case where s can be just over 1 s = math.min(1.0, s); } } return new HslColor(h, s, l); }
String toString() #
Returns a string representation of this object.
String toString() => '{RgbColor: $r, $g, $b}';