Blockly.utils. colour
Utility methods for colour manipulation.
Properties
hsvSaturation
The richness of block colours, regardless of the hue. Must be in the range of 0 (inclusive) to 1 (exclusive).
hsvValue
The intensity of block colours, regardless of the hue. Must be in the range of 0 (inclusive) to 1 (exclusive).
names
non-null Object with string properties
A map that contains the 16 basic colour keywords as defined by W3C: https://www.w3.org/TR/2018/REC-css-color-3-20180619/#html4 The keys of this map are the lowercase "readable" names of the colours, while the values are the "hex" values.
Methods
blend
blend(colour1, colour2, factor) returns string
Blend two colours together, using the specified factor to indicate the weight given to the first colour.
Parameter |
|
---|---|
colour1 |
string First colour. |
colour2 |
string Second colour. |
factor |
number The weight to be given to colour1 over colour2. Values should be in the range [0, 1]. |
- Returns
-
nullable string
Combined colour represented in hex.
getHsvSaturation
getHsvSaturation() returns number
Get the richness of block colours, regardless of the hue.
- Returns
-
number
The current richness.
getHsvValue
getHsvValue() returns number
Get the intensity of block colours, regardless of the hue.
- Returns
-
number
The current intensity.
hexToRgb
hexToRgb(colour) returns Array of number
Converts a colour to RGB.
Parameter |
|
---|---|
colour |
string String representing colour in any colour format ('#ff0000', 'red', '0xff000', etc). |
- Returns
-
non-null Array of number
RGB representation of the colour.
hsvToHex
hsvToHex(h, s, v) returns string
Converts an HSV triplet to hex representation.
Parameter |
|
---|---|
h |
number Hue value in [0, 360]. |
s |
number Saturation value in [0, 1]. |
v |
number Brightness in [0, 255]. |
- Returns
-
string
Hex representation of the colour.
hueToHex
hueToHex(hue) returns string
Convert a hue (HSV model) into an RGB hex triplet.
Parameter |
|
---|---|
hue |
number Hue on a colour wheel (0-360). |
- Returns
-
string
RGB code, e.g. '#5ba65b'.
parse
parse(str) returns string
Parses a colour from a string. .parse('red') -> '#ff0000' .parse('#f00') -> '#ff0000' .parse('#ff0000') -> '#ff0000' .parse('0xff0000') -> '#ff0000' .parse('rgb(255, 0, 0)') -> '#ff0000'
Parameter |
|
---|---|
str |
(string or number) Colour in some CSS format. |
- Returns
-
nullable string
A string containing a hex representation of the colour, or null if can't be parsed.
rgbToHex
rgbToHex(r, g, b) returns string
Converts a colour from RGB to hex representation.
Parameter |
|
---|---|
r |
number Amount of red, int between 0 and 255. |
g |
number Amount of green, int between 0 and 255. |
b |
number Amount of blue, int between 0 and 255. |
- Returns
-
string
Hex representation of the colour.
setHsvSaturation
setHsvSaturation(newSaturation)
Set the richness of block colours, regardless of the hue.
Parameter |
|
---|---|
newSaturation |
number The new richness, in the range of 0 (inclusive) to 1 (exclusive) |
setHsvValue
setHsvValue(newValue)
Set the intensity of block colours, regardless of the hue.
Parameter |
|
---|---|
newValue |
number The new intensity, in the range of 0 (inclusive) to 1 (exclusive) |