Basic concepts¶
Before I start explaining to you how to use the library, we need to agree on certain terminology.
Color models¶
This library supports several color models described below.
Alpha-channel
Each model may contain an additional optional alpha-channel that represents transparency (or, to be more precise, opacity). If so, the model's name contains the A letter as you'll see below.
RGB¶
Represents a color as a combination of Red, Green, and Blue components.
More details on Wikipedia.
Variants: RGB, ARGB, RGBA.
HSL¶
It's an alternative representation of a color in RGB color model that uses a combination of:
- Hue \(\in [0°, 360°]\)
- Saturation \(\in [0\%, 100\%]\)
- Lightness \(\in [0\%, 100\%]\)
More details on Wikipedia.
Variants: HSL, HSLA.
HSV¶
It's an alternative representation of a color in RGB color model that uses a combination of:
- Hue \(\in [0°, 360°]\)
- Saturation \(\in [0\%, 100\%]\)
- Value \(\in [0\%, 100\%]\) (AKA brightness)
More details on Wikipedia.
Variants: HSV, HSVA.
HWB¶
It's an alternative representation of a color in RGB color model that uses a combination of:
- Hue \(\in [0°, 360°]\)
- Whiteness \(\in [0\%, 100\%]\)
- Blackness \(\in [0\%, 100\%]\)
More details on Wikipedia.
Variants: HWB, HWBA.
Types¶
Color types¶
color-name¶
-
It's a
stringthat contains one of the extended color keywords from CSS.List of all names
Name Color HEX aliceblue #f0f8ffantiquewhite #faebd7aqua #00ffffaquamarine #7fffd4azure #f0ffffbeige #f5f5dcbisque #ffe4c4black #000000blanchedalmond #ffebcdblue #0000ffblueviolet #8a2be2brown #a52a2aburlywood #deb887cadetblue #5f9ea0chartreuse #7fff00chocolate #d2691ecoral #ff7f50cornflowerblue #6495edcornsilk #fff8dccrimson #dc143ccyan #00ffffdarkblue #00008bdarkcyan #008b8bdarkgoldenrod #b8860bdarkgray #a9a9a9darkgreen #006400darkgrey #a9a9a9darkkhaki #bdb76bdarkmagenta #8b008bdarkolivegreen #556b2fdarkorange #ff8c00darkorchid #9932ccdarkred #8b0000darksalmon #e9967adarkseagreen #8fbc8fdarkslateblue #483d8bdarkslategray #2f4f4fdarkslategrey #2f4f4fdarkturquoise #00ced1darkviolet #9400d3deeppink #ff1493deepskyblue #00bfffdimgray #696969dimgrey #696969dodgerblue #1e90fffirebrick #b22222floralwhite #fffaf0forestgreen #228b22fuchsia #ff00ffgainsboro #dcdcdcghostwhite #f8f8ffgold #ffd700goldenrod #daa520gray #808080green #008000greenyellow #adff2fgrey #808080honeydew #f0fff0hotpink #ff69b4indianred #cd5c5cindigo #4b0082ivory #fffff0khaki #f0e68clavender #e6e6falavenderblush #fff0f5lawngreen #7cfc00lemonchiffon #fffacdlightblue #add8e6lightcoral #f08080lightcyan #e0fffflightgoldenrodyellow #fafad2lightgray #d3d3d3lightgreen #90ee90lightgrey #d3d3d3lightpink #ffb6c1lightsalmon #ffa07alightseagreen #20b2aalightskyblue #87cefalightslategray #778899lightslategrey #778899lightsteelblue #b0c4delightyellow #ffffe0lime #00ff00limegreen #32cd32linen #faf0e6magenta #ff00ffmaroon #800000mediumaquamarine #66cdaamediumblue #0000cdmediumorchid #ba55d3mediumpurple #9370dbmediumseagreen #3cb371mediumslateblue #7b68eemediumspringgreen #00fa9amediumturquoise #48d1ccmediumvioletred #c71585midnightblue #191970mintcream #f5fffamistyrose #ffe4e1moccasin #ffe4b5navajowhite #ffdeadnavy #000080oldlace #fdf5e6olive #808000olivedrab #6b8e23orange #ffa500orangered #ff4500orchid #da70d6palegoldenrod #eee8aapalegreen #98fb98paleturquoise #afeeeepalevioletred #db7093papayawhip #ffefd5peachpuff #ffdab9peru #cd853fpink #ffc0cbplum #dda0ddpowderblue #b0e0e6purple #800080random ???red #ff0000rosybrown #bc8f8froyalblue #4169e1saddlebrown #8b4513salmon #fa8072sandybrown #f4a460seagreen #2e8b57seashell #fff5eesienna #a0522dsilver #c0c0c0skyblue #87ceebslateblue #6a5acdslategray #708090slategrey #708090snow #fffafaspringgreen #00ff7fsteelblue #4682b4tan #d2b48cteal #008080thistle #d8bfd8tomato #ff6347transparent #00000000turquoise #40e0d0violet #ee82eewheat #f5deb3white #ffffffwhitesmoke #f5f5f5yellow #ffff00yellowgreen #9acd32
color-literal¶
-
A string in either form:
'#rgb''#argb''#rrggbb''#aarrggbb'
Every
a,r,g, orbis a hex-digit, i.e. a value 0–9 or A–F (or a–f). They represent alpha, red, green, and blue correspondingly.Expanding rules
The
#aarrggbbis a full form and all other forms are expanded to it with the following rules:- If alpha is omitted, it equals to FF16 (= 25510).
- In short form, every digit is doubled.
Qt color (qolor)¶
-
Qt Quick's
colorbasic type. In this documentation I usually refer to it asqolorto distinguish from theColorclass.Read more about
qolorvscolorin the next chapter.
The Color class (color)¶
-
The bread-and-butter of this library is the
Colorclass which provides all the interesting methods. Essentially, it's just a thin wrapper aroundqolorwhich provides some additional properties and methods.Read more about
qolorvscolorin the next chapter.
Any type of color (any-color)¶
-
This is a union type that allows using any suitable way of constructing a color object.
Can be substituted with:
color-name|color-literal|qolor|color.
Auxiliary types¶
change-object¶
-
This type is used only as a parameter of a single method
changeand corresponding function.Every individual component of this object is of type
norm.The default value of each component is
null(i.e. no change). This makes every component – optional!The object itself contains:
alphaora- one of the following:
- {
rgb: {red,green,blue}}
or {rgb: {r,g,b}} - {
hsl: {hue,saturation,lightness}}
or {hsl: {h,s,l}} - {
hsv: {hue,saturation,value}}
or {hsv: {h,s,v}} - {
hwb: {hue,whiteness,blackness}}
or {hwb: {h,w,b}}
- {
offset-object¶
-
This type is used only as a parameter of two methods:
adjustandscaleand corresponding functions.Essentially, it's the same as
change-objectbut every individual component of this object is of typeoffsetinstead ofnorm.The default value of each component is
0.0(i.e. no change). This makes every component – optional!The object itself contains:
alphaora- one of the following:
- {
rgb: {red,green,blue}}
or {rgb: {r,g,b}} - {
hsl: {hue,saturation,lightness}}
or {hsl: {h,s,l}} - {
hsv: {hue,saturation,value}}
or {hsv: {h,s,v}} - {
hwb: {hue,whiteness,blackness}}
or {hwb: {h,w,b}}
- {
Valid examples
Value ranges¶
Normalized real interval (norm)¶
$$ n \in [0, 1] $$ Almost all functions work with arguments that belong to the normalized interval. Also, all color components' values are stored internally as normalized real values.
For example, rgba(0.5, 0, 1, 1).
Normalized real offset interval (offset)¶
$$ r \in [-1, 1] $$ This one is mainly used to denote an offset/change of a normalized value.
For instance, {hsl: {saturation: -0.3}}.
Integer interval (8bit)¶
$$
u \in [0, 255]
$$
This should be quite familiar for those coming from CSS where color components are specified using integers. Usually, functions, that work with such values, have suffix 24 or 32.
For example, rgb24(128, 0, 255).
Integer offset interval (9bit)¶
$$ s \in [-255, 255] $$ AFAIR, there are no functions that work with this interval, however, you can use such values, for instance, together with units.
Example: {alpha: -128 .int}.