Functions¶
This page describes global functions
If you are looking for tagged literals or the Color class' methods, check the links.
Constructors¶
qolor¶
-
Type: ( color:any-color) →qolorAlias: qConstructs a Qt Quick's
colorfrom any other color.Examples:
color¶
-
Type: ( color:any-color) →colorAlias: ccConstructs an instance of the
Colorclass from any other color.Examples:
rgba¶
-
Type: ( red,green,blue,alpha = 1.0:norm) →qolor
(color:any-color,alpha = 1.0:norm) →qolor(1) (2) Alias: rgbCreates a color either from RGBA parameters (1) or from a
colorandalpha(2). In the latter case, if thecolorhas already some transparency, it will be overridden by a specified value of alpha channel.If this function can't construct a color from its parameters, an exception is raised.
Examples:
(no alpha):
rgba32¶
-
Type: ( red,green,blue,alpha = 255:8bit) →qolor
(color:any-color,alpha = 255:8bit) →qolor(1) (2) Alias: rgb24Creates a color either from RGBA parameters (1) or from a
colorandalpha(2). In the latter case, if thecolorhas already some transparency, it will be overridden by a specified value of alpha channel.If this function can't construct a color from its parameters, an exception is raised.
Examples:
(no alpha):
argb¶
-
Type: ( alpha,red,green,blue:norm) →qolorCreates a color from ARGB parameters.
If this function can't construct a color from its parameters, an exception is raised.
Examples:
argb32¶
-
Type: ( alpha,red,green,blue:8bit) →qolorCreates a color from ARGB parameters.
If this function can't construct a color from its parameters, an exception is raised.
Examples:
hsla¶
-
Type: ( hue,saturation,lightness,alpha = 1.0:norm) →qolorAlias: hslCreates a color from HSLA parameters.
If this function can't construct a color from its parameters, an exception is raised.
Examples:
(no alpha):
hsva¶
-
Type: ( hue,saturation,value,alpha = 1.0:norm) →qolorAlias: hsvCreates a color from HSVA parameters.
If this function can't construct a color from its parameters, an exception is raised.
Examples:
(no alpha):
hwba¶
-
Type: ( hue,whiteness,blackness,alpha = 1.0:norm) →qolorAlias: hwbCreates a color from HWBA parameters.
If this function can't construct a color from its parameters, an exception is raised.
Examples:
(no alpha):
Modificators¶
How to access these functions
To avoid clashes with your own functions' names, all modifying functions are defined not globally but on the $ global object instead (similarly to jQuery1).
It means that you can call them the following way:
| Category | Functions (and aliases) |
|---|---|
| Multi-changes | adjust, change, scale |
| Hue | adjustHue (or spin), complement |
| Brightness | darken, lighten |
| Saturation | desaturate, grayscale (or greyscale), saturate |
| Opacity | opacify (or fadeIn), transparentize (or fadeOut) |
| Other | invert, mix |
adjust¶
-
Type: ( color:any-color,change:offset-object) →qolorIncreases or decreases one or more properties of the
colorby fixed amounts.Adds the value passed for each keyword argument to the corresponding property of the
color, and returns a new adjusted instance of color.Restrictions (for more details see
offset-object):alphakeyword can be specified separately.- Among
rgb,hsl,hsv, andhwb, only one may be used at a time. - All keyword arguments are of type
offsetand optional.
Examples:
adjustHue¶
-
Type: ( color:any-color,offset:offset) →qolorAlias: spinIncreases or decreases the
color's hue.Examples:
change¶
-
Type: ( color:any-color,change:change-object) →qolorSets one or more properties of the
colorto new values and returns a new adjusted instance of color.Restrictions (for more details see
change-object):alphakeyword can be specified separately.- Among
rgb,hsl,hsv, andhwb, only one may be used at a time. - All keyword arguments are of type
normand optional.
Examples:
complement¶
-
Type: ( color:any-color) →qolorReturns the RGB complement of the
color.This is identical to
adjustHue(color, -180 .deg).Examples:
darken¶
-
Type: ( color:any-color,amount = 0.25:norm) →qolorMakes the
colordarker by specifiedamount(by decreasing the HSL lightness).Examples:
desaturate¶
-
Type: ( color:any-color,amount = 0.25:norm) →qolorMakes the
colorless saturated by specifiedamount(by decreasing the HSL saturation).Examples:
grayscale¶
-
Type: ( color:any-color) →qolorAlias: greyscaleReturns a gray color with the same lightness as the
color's one.This is identical to
change(color, {hsl: {saturation: 0}}).Examples:
See also:
change.
invert¶
-
Type: ( color:any-color,weight = 1.0:norm) →qolorReturns the negative of the
color.A higher
weightmeans the result will be closer to the negative, and a lowerweightmeans it will be closer to the originalcolor.weight = 0.5will always produce#808080.Examples:
See also:
complement,%.
lighten¶
-
Type: ( color:any-color,amount = 0.25:norm) →qolorMakes the
colorlighter by specifiedamount(by increasing the HSL lightness).Examples:
mix¶
-
Type: ( color1,color2:any-color,weight = 0.5:norm) →qolorReturns a new color that’s a mixture of
color1andcolor2.Both the
weightand the relative opacity of each color determines how much of each color is in the result. A largerweightindicates that more ofcolor1should be used, and a smallerweightindicates that more ofcolor2should be used.By default, the colors are mixed in equal proportions.
Examples:
See also:
%.
opacify¶
-
Type: ( color:any-color,amount = 0.25:norm) →qolorAlias: fadeInMakes the
colormore opaque by increasing the alpha channel byamount.Examples:
saturate¶
-
Type: ( color:any-color,amount = 0.25:norm) →qolorMakes the
colormore saturated by specifiedamount(by increasing the HSL saturation).Examples:
scale¶
-
Type: ( color:any-color,change:offset-object) →qolorFluidly scales one or more properties of the
colorand returns a new adjusted instance of color.Each keyword argument indicates how far the corresponding property of the
colorshould be moved from its original position towards the maximum (if the argument is positive) or the minimum (if the argument is negative). This means that, for example,{hsl: {lightness: +50['%']}}will make thecolor50% closer to maximum lightness without making it fully white.Restrictions (for more details see
offset-object):alphakeyword can be specified separately.- Among
rgb,hsl,hsv, andhwb, only one may be used at a time. - All keyword arguments are of type
offsetand optional. - Although it is possible to specify
huefor HSL, HSV, or HWB keyword arguments, it doesn't make much sense because the menthal model of such a change is vague IMO.
Examples:
transparentize¶
-
Type: ( color:any-color,amount = 0.25:norm) →qolorAlias: fadeOutMakes the
colorless opaque by decreasing the alpha channel byamount.Examples:
Utilities¶
How to access these functions
To avoid clashes with your own functions' names, all utility functions are defined not globally but on the $ global object instead.
Please, see examples below.
textToColor¶
-
Type: ( text:string) →qolorThis function creates a unique (to some extent) color based on
text.- It does guarantee that for the same
textit always returns the same color. - It does not guarantee that for any two different texts the resulting colors will also be different.
Examples:
- It does guarantee that for the same
-
Oh, God, what have I done‽ ↩