colors library
Very primitive colors utilities HSL and HSV at wikipedia TODO to include more functions (adapted/copied from TinyColor) TODO more test TODO a demo, a color tool (picker + display other, like agave color scheme) TODO add a parser (String to irgba)
Properties
const aliceblue #
const aliceblue = 0xf0f8ffff
const antiquewhite #
const antiquewhite = 0xfaebd7ff
const aqua #
const aqua = 0x0ffff
const aquamarine #
const aquamarine = 0x7fffd4ff
const azure #
const azure = 0xf0ffffff
const beige #
const beige = 0xf5f5dcff
const bisque #
const bisque = 0xffe4c4ff
const black #
const black = 0x000ff
const blanchedalmond #
const blanchedalmond = 0xffebcdff
const blue #
const blue = 0x00fff
const blueviolet #
const blueviolet = 0x8a2be2ff
const brown #
const brown = 0xa52a2aff
const burlywood #
const burlywood = 0xdeb887ff
const burntsienna #
const burntsienna = 0xea7e5dff
const cadetblue #
const cadetblue = 0x5f9ea0ff
const chartreuse #
const chartreuse = 0x7fff00ff
const chocolate #
const chocolate = 0xd2691eff
const coral #
const coral = 0xff7f50ff
const cornflowerblue #
const cornflowerblue = 0x6495edff
const cornsilk #
const cornsilk = 0xfff8dcff
const crimson #
const crimson = 0xdc143cff
const cyan #
const cyan = 0x0ffff
const darkblue #
const darkblue = 0x00008bff
const darkcyan #
const darkcyan = 0x008b8bff
const darkgoldenrod #
const darkgoldenrod = 0xb8860bff
const darkgray #
const darkgray = 0xa9a9a9ff
const darkgreen #
const darkgreen = 0x006400ff
const darkgrey #
const darkgrey = 0xa9a9a9ff
const darkkhaki #
const darkkhaki = 0xbdb76bff
const darkmagenta #
const darkmagenta = 0x8b008bff
const darkolivegreen #
const darkolivegreen = 0x556b2fff
const darkorange #
const darkorange = 0xff8c00ff
const darkorchid #
const darkorchid = 0x9932ccff
const darkred #
const darkred = 0x8b0000ff
const darksalmon #
const darksalmon = 0xe9967aff
const darkseagreen #
const darkseagreen = 0x8fbc8fff
const darkslateblue #
const darkslateblue = 0x483d8bff
const darkslategray #
const darkslategray = 0x2f4f4fff
const darkslategrey #
const darkslategrey = 0x2f4f4fff
const darkturquoise #
const darkturquoise = 0x00ced1ff
const darkviolet #
const darkviolet = 0x9400d3ff
const deeppink #
const deeppink = 0xff1493ff
const deepskyblue #
const deepskyblue = 0x00bfffff
const dimgray #
const dimgray = 0x696969ff
const dimgrey #
const dimgrey = 0x696969ff
const dodgerblue #
const dodgerblue = 0x1e90ffff
const firebrick #
const firebrick = 0xb22222ff
const floralwhite #
const floralwhite = 0xfffaf0ff
const forestgreen #
const forestgreen = 0x228b22ff
const fuchsia #
const fuchsia = 0xf0fff
const gainsboro #
const gainsboro = 0xdcdcdcff
const ghostwhite #
const ghostwhite = 0xf8f8ffff
const gold #
const gold = 0xffd700ff
const goldenrod #
const goldenrod = 0xdaa520ff
const gray #
const gray = 0x808080ff
const green #
const green = 0x008000ff
const greenyellow #
const greenyellow = 0xadff2fff
const grey #
const grey = 0x808080ff
const honeydew #
const honeydew = 0xf0fff0ff
const hotpink #
const hotpink = 0xff69b4ff
const indianred #
const indianred = 0xcd5c5cff
const indigo #
const indigo = 0x4b0082ff
const ivory #
const ivory = 0xfffff0ff
const khaki #
const khaki = 0xf0e68cff
const lavender #
const lavender = 0xe6e6faff
const lavenderblush #
const lavenderblush = 0xfff0f5ff
const lawngreen #
const lawngreen = 0x7cfc00ff
const lemonchiffon #
const lemonchiffon = 0xfffacdff
const lightblue #
const lightblue = 0xadd8e6ff
const lightcoral #
const lightcoral = 0xf08080ff
const lightcyan #
const lightcyan = 0xe0ffffff
const lightgoldenrodyellow #
const lightgoldenrodyellow = 0xfafad2ff
const lightgray #
const lightgray = 0xd3d3d3ff
const lightgreen #
const lightgreen = 0x90ee90ff
const lightgrey #
const lightgrey = 0xd3d3d3ff
const lightpink #
const lightpink = 0xffb6c1ff
const lightsalmon #
const lightsalmon = 0xffa07aff
const lightseagreen #
const lightseagreen = 0x20b2aaff
const lightskyblue #
const lightskyblue = 0x87cefaff
const lightslategray #
const lightslategray = 0x789ff
const lightslategrey #
const lightslategrey = 0x789ff
const lightsteelblue #
const lightsteelblue = 0xb0c4deff
const lightyellow #
const lightyellow = 0xffffe0ff
const lime #
const lime = 0x0f0ff
const limegreen #
const limegreen = 0x32cd32ff
const linen #
const linen = 0xfaf0e6ff
const magenta #
const magenta = 0xf0fff
const maroon #
const maroon = 0x800000ff
const mediumaquamarine #
const mediumaquamarine = 0x66cdaaff
const mediumblue #
const mediumblue = 0x0000cdff
const mediumorchid #
const mediumorchid = 0xba55d3ff
const mediumpurple #
const mediumpurple = 0x9370dbff
const mediumseagreen #
const mediumseagreen = 0x3cb371ff
const mediumslateblue #
const mediumslateblue = 0x7b68eeff
const mediumspringgreen #
const mediumspringgreen = 0x00fa9aff
const mediumturquoise #
const mediumturquoise = 0x48d1ccff
const mediumvioletred #
const mediumvioletred = 0xc71585ff
const midnightblue #
const midnightblue = 0x191970ff
const mintcream #
const mintcream = 0xf5fffaff
const mistyrose #
const mistyrose = 0xffe4e1ff
const moccasin #
const moccasin = 0xffe4b5ff
const navajowhite #
const navajowhite = 0xffdeadff
const navy #
const navy = 0x000080ff
const oldlace #
const oldlace = 0xfdf5e6ff
const olive #
const olive = 0x808000ff
const olivedrab #
const olivedrab = 0x6b8e23ff
const orange #
const orange = 0xffa500ff
const orangered #
const orangered = 0xff4500ff
const orchid #
const orchid = 0xda70d6ff
const palegoldenrod #
const palegoldenrod = 0xeee8aaff
const palegreen #
const palegreen = 0x98fb98ff
const paleturquoise #
const paleturquoise = 0xafeeeeff
const palevioletred #
const palevioletred = 0xdb7093ff
const papayawhip #
const papayawhip = 0xffefd5ff
const peachpuff #
const peachpuff = 0xffdab9ff
const peru #
const peru = 0xcd853fff
const pink #
const pink = 0xffc0cbff
const plum #
const plum = 0xdda0ddff
const powderblue #
const powderblue = 0xb0e0e6ff
const purple #
const purple = 0x800080ff
const red #
const red = 0xf00ff
const rosybrown #
const rosybrown = 0xbc8f8fff
const royalblue #
const royalblue = 0x4169e1ff
const saddlebrown #
const saddlebrown = 0x8b4513ff
const salmon #
const salmon = 0xfa8072ff
const sandybrown #
const sandybrown = 0xf4a460ff
const seagreen #
const seagreen = 0x2e8b57ff
const seashell #
const seashell = 0xfff5eeff
const sienna #
const sienna = 0xa0522dff
const silver #
const silver = 0xc0c0c0ff
const skyblue #
const skyblue = 0x87ceebff
const slateblue #
const slateblue = 0x6a5acdff
const slategray #
const slategray = 0x708090ff
const slategrey #
const slategrey = 0x708090ff
const snow #
const snow = 0xfffafaff
const springgreen #
const springgreen = 0x00ff7fff
const steelblue #
const steelblue = 0x4682b4ff
const tan #
const tan = 0xd2b48cff
const teal #
const teal = 0x008080ff
const thistle #
const thistle = 0xd8bfd8ff
const tomato #
const tomato = 0xff6347ff
const turquoise #
const turquoise = 0x40e0d0ff
const violet #
const violet = 0xee82eeff
const wheat #
const wheat = 0xf5deb3ff
const white #
const white = 0xfffff
const whitesmoke #
const whitesmoke = 0xf5f5f5ff
const yellow #
const yellow = 0xff0ff
const yellowgreen #
const yellowgreen = 0x9acd32ff
Functions
dynamic hexString_irgba(String s) #
hexString_irgba(String s) { if (s == null || s.length < 3) s = "0x0"; return int.parse(s.substring(2), radix : 16); }
dynamic irgba_hexString(int c) #
irgba_hexString(int c) { var x = (c >> 8) | 0x1000000; //0x100000000 is too bigger on js return "0x" + x.toRadixString(16).substring(1) + (c & 0xff | 0x100).toRadixString(16).substring(1); }
dynamic hexHtml_irgba(String s) #
hexHtml_irgba(String s) { if (s == null || s.length < 2) s = "#0"; return int.parse(s.substring(1), radix : 16) << 8 | 0x000000ff; }
dynamic irgba_hexHtml(int c) #
irgba_hexHtml(int c) { var x = (c >> 8) | 0x1000000; // start with 1 for padding with 0 return '#' + x.toRadixString(16).substring(1); }
dynamic irgba_hex3String(int c) #
Converts an RGB color to hex Returns a 6 character hex (no prefix)
test('irgba_hex3String',(){
expect(irgba_hex3String(0xff000000), 'ff0000');
expect(irgba_hex3String(0x00ff0000), '00ff00');
expect(irgba_hex3String(0x0000ff00), '0000ff');
expect(irgba_hex3String(0xffffff00), 'ffffff');
expect(irgba_hex3String(0x00000000), '000000');
expect(irgba_hex3String(0x000000ff), '000000');
});
irgba_hex3String(int c) { var x = (c >> 8) | 0x1000000; // start with 1 for padding with 0 return x.toRadixString(16).substring(1); }
dynamic irgba_rgbaString(int c) #
test('irgba_rgbaString',(){
expect(irgba_rgbaString(0xff000000), 'rgba(255, 0, 0, 0.0)');
expect(irgba_rgbaString(0x00ff0000), 'rgba(0, 255, 0, 0.0)');
expect(irgba_rgbaString(0x0000ff00), 'rgba(0, 0, 255, 0.0)');
expect(irgba_rgbaString(0xffffffff), 'rgba(255, 255, 255, 1.0)');
expect(irgba_rgbaString(0x00000000), 'rgba(0, 0, 0, 0.0)');
expect(irgba_rgbaString(0x000000ff), 'rgba(0, 0, 0, 1.0)');
});
irgba_rgbaString(int c) { var r = irgba_r255(c); var g = irgba_g255(c); var b = irgba_b255(c); var a = irgba_a1(c); return 'rgba(${r}, ${g}, ${b}, ${a})'; }
dynamic irgba_rgbString(int c) #
test('irgba_rgbString',(){
expect(irgba_rgbString(0xff000000), 'rgb(255, 0, 0)');
expect(irgba_rgbString(0x00ff0000), 'rgb(0, 255, 0)');
expect(irgba_rgbString(0x0000ff00), 'rgb(0, 0, 255)');
expect(irgba_rgbString(0xffffffff), 'rgb(255, 255, 255)');
expect(irgba_rgbString(0x00000000), 'rgb(0, 0, 0)');
expect(irgba_rgbString(0x000000ff), 'rgb(0, 0, 0)');
});
irgba_rgbString(int c) { var r = irgba_r255(c); var g = irgba_g255(c); var b = irgba_b255(c); return 'rgb(${r}, ${g}, ${b})'; }
List<List<double>> hsv_monochromatic(List<double> hsv, [int results = 6]) #
List<List<double>> hsv_monochromatic(List<double> hsv, [int results = 6]) { var h = hsv[0], s = hsv[1], v = hsv[2]; var ret = new List<List<double>>(results); var modification = 1.0 / results; ret[0] = hsv; for (var i = 1; i < results; ++i) { v = (v + modification) % 1.0; ret[i] = [h, s, v]; } return ret; }
List<List<double>> hsl_analogous(List<double> hsl, [int results = 6, int slices = 30]) #
List<List<double>> hsl_analogous(List<double> hsl, [int results = 6, int slices = 30]) { var part = 360 ~/ slices; var ret = new List<List<double>>(results); ret[0] = hsl; var h = ((hsl[0] * 360 - (part * results >> 1)) + 720) % 360, s = hsl[1], l = hsl[2]; for (var i = 1; i < results; ++i) { h = (h + part) % 360; ret[i] = [h / 360, s, l]; } return ret; }
dynamic hsl_splitcomplement(List<double> hsl) #
hsl_splitcomplement(List<double> hsl) { var h = hsl[0]; return [ hsl, [(h + 0.20) % 1.0, hsl[1], hsl[2]], // h + 72° [(h + 0.60) % 1.0, hsl[1], hsl[2]], // h + 216° ]; }
dynamic hsl_tetrad(List<double> hsl) #
hsl_tetrad(List<double> hsl) { var h = hsl[0]; return [ hsl, [(h + 0.25) % 1.0, hsl[1], hsl[2]], // h + 90° [(h + 0.50) % 1.0, hsl[1], hsl[2]], // h + 180° [(h + 0.75) % 1.0, hsl[1], hsl[2]], // h + 270° ]; }
dynamic hsl_triad(List<double> hsl) #
hsl_triad(List<double> hsl) { var h = hsl[0]; return [ hsl, [(h + 0.333) % 1.0, hsl[1], hsl[2]], // h + 120° [(h + 0.666) % 1.0, hsl[1], hsl[2]], // h + 240° ]; }
dynamic hsl_complement(List<double> hsl) #
hsl is modified and return
hsl_complement(List<double> hsl) { hsl[0] = (hsl[0] + 0.5) % 1.0; return hsl; }
dynamic hsl_darken(List<double> hsl, [amount = 10]) #
hsl is modified and return amount is a percent (default 10)
hsl_darken(List<double> hsl, [amount = 10]) { hsl[2] -= (amount / 100); hsl[2] = math.max(0.0, hsl[2]); return hsl; }
dynamic hsl_lighten(List<double> hsl, [amount = 10]) #
hsl is modified and return amount is a percent (default 10)
hsl_lighten(List<double> hsl, [amount = 10]) { hsl[2] += (amount / 100); hsl[2] = math.min(1.0, hsl[2]); return hsl; }
dynamic hsl_greyscale(List<double> hsl) #
hsl is modified and return
hsl_greyscale(List<double> hsl) => hsl_desaturate(hsl, 100);
dynamic hsl_saturate(List<double> hsl, [amount = 10]) #
hsl is modified and return amount is a percent (default 10)
hsl_saturate(List<double> hsl, [amount = 10]) { hsl[1] += (amount / 100); hsl[1] = math.min(1.0, hsl[1]); return hsl; }
dynamic hsl_desaturate(List<double> hsl, [amount = 10]) #
hsl is modified and return amount is a percent (default 10)
hsl_desaturate(List<double> hsl, [amount = 10]) { hsl[1] -= (amount / 100); hsl[1] = math.max(0.0, hsl[1]); return hsl; }
dynamic hsv_irgba(List<double> hsv) #
hsv_irgba(List<double> hsv) { var h2 = hsv[0] * 6; var s = hsv[1]; var v = hsv[2]; var c = v * s; var x = c * ( 1 - (h2 % 2 - 1).abs()); var i = h2.floor() % 6; var r = 0.0; var g = 0.0; var b = 0.0; switch(i) { case 0 : r = c ; g = x ; b = 0.0; break; case 1 : r = x ; g = c ; b = 0.0; break; case 2 : r = 0.0; g = c ; b = x; break; case 3 : r = 0.0; g = x ; b = c ; break; case 4 : r = x ; g = 0.0; b = c ; break; case 5 : r = c ; g = 0.0; b = x ; break; } var m = v - c; return rgb1_irgba(r + m, g + m, b + m); // var i = h.floor(), // f = h - i, // p = v * (1 - s), // q = v * (1 - f * s), // t = v * (1 - (1 - f) * s), // mod = i % 6, // r = [v, q, p, p, t, v][mod], // g = [t, v, v, q, p, p][mod], // b = [p, p, t, v, v, q][mod]; // return rgb1_irgba(r, g, b); }
dynamic irgba_hsv(int c) #
Converts an rgba (int) color value to h, s, v
each value in 0.0, 1.0
.
irgba_hsv(int c) { var r = irgba_r1(c); var g = irgba_g1(c); var b = irgba_b1(c); var max = math.max(math.max(r, g), b); var min = math.min(math.min(r, g), b); var h, s, v = max; var d = max - min; s = (max == 0.0) ? 0.0 : d / max; if(max == min) { h = 0.0; // achromatic } else { h = (max == r) ? (g - b) / d + (g < b ? 6 : 0) : (max == g) ? (b - r) / d + 2 : (r - g) / d + 4 ; h /= 6; } return [h, s, v]; }
int hsl_irgba(List<double> hsl) #
int hsl_irgba(List<double> hsl) { var r, g, b; var h = hsl[0]; var s = hsl[1]; var l = hsl[2]; hue2rgb(p, q, t) { if(t < 0) t += 1; if(t > 1) t -= 1; if(t < 1/6) return p + (q - p) * 6 * t; if(t < 1/2) return q; if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; return p; } if(s == 0.0) { r = g = b = l; // achromatic } else { var q = l < 0.5 ? l * (1 + s) : l + s - l * s; var p = 2 * l - q; r = hue2rgb(p, q, h + 1/3); g = hue2rgb(p, q, h); b = hue2rgb(p, q, h - 1/3); } return rgb1_irgba(r, g, b); }
List<double> irgba_hsl(int c) #
List<double> irgba_hsl(int c) { var r = irgba_r1(c); var g = irgba_g1(c); var b = irgba_b1(c); var max = math.max(math.max(r, g), b); var min = math.min(math.min(r, g), b); var h, s, l = (max + min) / 2; if (max == min) { h = s = 0; // achromatic } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); h = (max == r) ? (g - b) / d + (g < b ? 6 : 0) : (max == g) ? (b - r) / d + 2 : (r - g) / d + 4 ; h /= 6; } return [h, s, l]; }
int rgb_irgba(List<double> rgb) #
int rgb_irgba(List<double> rgb) => rgb1_irgba(rgb[0], rgb[1], rgb[2]);
List<double> irgba_rgb(int c) #
List<double> irgba_rgb(int c) { return [irgba_r1(c), irgba_g1(c), irgba_b1(c)]; }
int rgb1_irgba(double r, double g, double b) #
int rgb1_irgba(double r, double g, double b) { return 0x000000ff | ((r * 255).toInt() << 24) | ((g * 255).toInt() << 16) | ((b * 255).toInt() << 8); }
dynamic irgba_b255_set(int c, int b) #
irgba_b255_set(int c, int b) => ((c & 0xffff00ff) | (b << 8));
dynamic irgba_g255_set(int c, int g) #
irgba_g255_set(int c, int g) => ((c & 0xff00ffff) | (g << 16));