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
) →qolor
Alias: q
Constructs a Qt Quick's
color
from any other color.Examples:
color
¶
-
Type: ( color
:any-color
) →color
Alias: cc
Constructs an instance of the
Color
class 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: rgb
Creates a color either from RGBA parameters (1) or from a
color
andalpha
(2). In the latter case, if thecolor
has 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: rgb24
Creates a color either from RGBA parameters (1) or from a
color
andalpha
(2). In the latter case, if thecolor
has 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
) →qolor
Creates 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
) →qolor
Creates 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
) →qolor
Alias: hsl
Creates 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
) →qolor
Alias: hsv
Creates 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
) →qolor
Alias: hwb
Creates 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
) →qolor
Increases or decreases one or more properties of the
color
by 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
):alpha
keyword can be specified separately.- Among
rgb
,hsl
,hsv
, andhwb
, only one may be used at a time. - All keyword arguments are of type
offset
and optional.
Examples:
adjustHue
¶
-
Type: ( color
:any-color
,offset
:offset
) →qolor
Alias: spin
Increases or decreases the
color
's hue.Examples:
change
¶
-
Type: ( color
:any-color
,change
:change-object
) →qolor
Sets one or more properties of the
color
to new values and returns a new adjusted instance of color.Restrictions (for more details see
change-object
):alpha
keyword can be specified separately.- Among
rgb
,hsl
,hsv
, andhwb
, only one may be used at a time. - All keyword arguments are of type
norm
and optional.
Examples:
complement
¶
-
Type: ( color
:any-color
) →qolor
Returns the RGB complement of the
color
.This is identical to
adjustHue(color, -180 .deg)
.Examples:
darken
¶
-
Type: ( color
:any-color
,amount = 0.25
:norm
) →qolor
Makes the
color
darker by specifiedamount
(by decreasing the HSL lightness).Examples:
desaturate
¶
-
Type: ( color
:any-color
,amount = 0.25
:norm
) →qolor
Makes the
color
less saturated by specifiedamount
(by decreasing the HSL saturation).Examples:
grayscale
¶
-
Type: ( color
:any-color
) →qolor
Alias: greyscale
Returns 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
) →qolor
Returns the negative of the
color
.A higher
weight
means the result will be closer to the negative, and a lowerweight
means it will be closer to the originalcolor
.weight = 0.5
will always produce#808080
.Examples:
See also:
complement
,%
.
lighten
¶
-
Type: ( color
:any-color
,amount = 0.25
:norm
) →qolor
Makes the
color
lighter by specifiedamount
(by increasing the HSL lightness).Examples:
mix
¶
-
Type: ( color1
,color2
:any-color
,weight = 0.5
:norm
) →qolor
Returns a new color that’s a mixture of
color1
andcolor2
.Both the
weight
and the relative opacity of each color determines how much of each color is in the result. A largerweight
indicates that more ofcolor1
should be used, and a smallerweight
indicates that more ofcolor2
should be used.By default, the colors are mixed in equal proportions.
Examples:
See also:
%
.
opacify
¶
-
Type: ( color
:any-color
,amount = 0.25
:norm
) →qolor
Alias: fadeIn
Makes the
color
more opaque by increasing the alpha channel byamount
.Examples:
saturate
¶
-
Type: ( color
:any-color
,amount = 0.25
:norm
) →qolor
Makes the
color
more saturated by specifiedamount
(by increasing the HSL saturation).Examples:
scale
¶
-
Type: ( color
:any-color
,change
:offset-object
) →qolor
Fluidly scales one or more properties of the
color
and returns a new adjusted instance of color.Each keyword argument indicates how far the corresponding property of the
color
should 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 thecolor
50% closer to maximum lightness without making it fully white.Restrictions (for more details see
offset-object
):alpha
keyword can be specified separately.- Among
rgb
,hsl
,hsv
, andhwb
, only one may be used at a time. - All keyword arguments are of type
offset
and optional. - Although it is possible to specify
hue
for 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
) →qolor
Alias: fadeOut
Makes the
color
less 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
) →qolor
This function creates a unique (to some extent) color based on
text
.- It does guarantee that for the same
text
it 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‽ ↩