All shapes (primitives or the results of operations) can be assigned a color (RGBA). In all cases, the function returns the results, and never changes the original shapes.
- Source:
Example
const { colorize, hexToRgb } = require('@jscad/modeling').colors
Members
(static, constant) cssColors :Array
- Source:
- See:
-
- CSS color table from http://www.w3.org/TR/css3-color/
Properties:
Name | Type | Description |
---|---|---|
black |
Array | |
silver |
Array | |
gray |
Array | |
white |
Array | |
maroon |
Array | |
red |
Array | |
purple |
Array | |
fuchsia |
Array | |
green |
Array | |
lime |
Array | |
olive |
Array | |
yellow |
Array | |
navy |
Array | |
blue |
Array | |
teal |
Array | |
aqua |
Array | |
aliceblue |
Array | |
antiquewhite |
Array | |
aquamarine |
Array | |
azure |
Array | |
beige |
Array | |
bisque |
Array | |
blanchedalmond |
Array | |
blueviolet |
Array | |
brown |
Array | |
burlywood |
Array | |
cadetblue |
Array | |
chartreuse |
Array | |
chocolate |
Array | |
coral |
Array | |
cornflowerblue |
Array | |
cornsilk |
Array | |
crimson |
Array | |
cyan |
Array | |
darkblue |
Array | |
darkcyan |
Array | |
darkgoldenrod |
Array | |
darkgray |
Array | |
darkgreen |
Array | |
darkgrey |
Array | |
darkkhaki |
Array | |
darkmagenta |
Array | |
darkolivegreen |
Array | |
darkorange |
Array | |
darkorchid |
Array | |
darkred |
Array | |
darksalmon |
Array | |
darkseagreen |
Array | |
darkslateblue |
Array | |
darkslategray |
Array | |
darkslategrey |
Array | |
darkturquoise |
Array | |
darkviolet |
Array | |
deeppink |
Array | |
deepskyblue |
Array | |
dimgray |
Array | |
dimgrey |
Array | |
dodgerblue |
Array | |
firebrick |
Array | |
floralwhite |
Array | |
forestgreen |
Array | |
gainsboro |
Array | |
ghostwhite |
Array | |
gold |
Array | |
goldenrod |
Array | |
greenyellow |
Array | |
grey |
Array | |
honeydew |
Array | |
hotpink |
Array | |
indianred |
Array | |
indigo |
Array | |
ivory |
Array | |
khaki |
Array | |
lavender |
Array | |
lavenderblush |
Array | |
lawngreen |
Array | |
lemonchiffon |
Array | |
lightblue |
Array | |
lightcoral |
Array | |
lightcyan |
Array | |
lightgoldenrodyellow |
Array | |
lightgray |
Array | |
lightgreen |
Array | |
lightgrey |
Array | |
lightpink |
Array | |
lightsalmon |
Array | |
lightseagreen |
Array | |
lightskyblue |
Array | |
lightslategray |
Array | |
lightslategrey |
Array | |
lightsteelblue |
Array | |
lightyellow |
Array | |
limegreen |
Array | |
linen |
Array | |
magenta |
Array | |
mediumaquamarine |
Array | |
mediumblue |
Array | |
mediumorchid |
Array | |
mediumpurple |
Array | |
mediumseagreen |
Array | |
mediumslateblue |
Array | |
mediumspringgreen |
Array | |
mediumturquoise |
Array | |
mediumvioletred |
Array | |
midnightblue |
Array | |
mintcream |
Array | |
mistyrose |
Array | |
moccasin |
Array | |
navajowhite |
Array | |
oldlace |
Array | |
olivedrab |
Array | |
orange |
Array | |
orangered |
Array | |
orchid |
Array | |
palegoldenrod |
Array | |
palegreen |
Array | |
paleturquoise |
Array | |
palevioletred |
Array | |
papayawhip |
Array | |
peachpuff |
Array | |
peru |
Array | |
pink |
Array | |
plum |
Array | |
powderblue |
Array | |
rosybrown |
Array | |
royalblue |
Array | |
saddlebrown |
Array | |
salmon |
Array | |
sandybrown |
Array | |
seagreen |
Array | |
seashell |
Array | |
sienna |
Array | |
skyblue |
Array | |
slateblue |
Array | |
slategray |
Array | |
slategrey |
Array | |
snow |
Array | |
springgreen |
Array | |
steelblue |
Array | |
tan |
Array | |
thistle |
Array | |
tomato |
Array | |
turquoise |
Array | |
violet |
Array | |
wheat |
Array | |
whitesmoke |
Array | |
yellowgreen |
Array |
Type:
- Array
Example
let newshape = colorize(cssColors.red, oldshape)
Methods
(static) colorize(color, …objects) → {Object|Array}
- Source:
Assign the given color to the given objects.
Example
let redSphere = colorize([1,0,0], sphere()) // red
let greenCircle = colorize([0,1,0,0.8], circle()) // green transparent
let blueArc = colorize([0,0,1], arc()) // blue
let wildcylinder = colorize(colorNameToRgb('fuchsia'), cylinder()) // CSS color
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
color |
Array | RGBA color values, where each value is between 0 and 1.0 |
|
objects |
Object | Array |
<repeatable> |
the objects of which to apply the given color |
Returns:
new object, or list of new objects with an additional attribute 'color'
- Type
- Object | Array
(static) colorNameToRgb(s) → {Array}
Converts a CSS color name to RGB color.
Example
let mysphere = colorize(colorNameToRgb('lightblue'), sphere())
Parameters:
Name | Type | Description |
---|---|---|
s |
String | the CSS color name |
Returns:
the RGB color, or undefined if not found
- Type
- Array
(static) hexToRgb(notation) → {Array}
Converts CSS color notations (string of hex values) to RGB values.
Example
let mysphere = colorize(hexToRgb('#000080'), sphere()) // navy blue
Parameters:
Name | Type | Description |
---|---|---|
notation |
String | color notation |
Returns:
RGB color values
- Type
- Array
(static) hslToRgb(…values) → {Array}
Converts HSL color values to RGB color values.
Example
let mysphere = colorize(hslToRgb([0.9166666666666666, 1, 0.5]), sphere())
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Number | Array |
<repeatable> |
HSL or HSLA color values |
Returns:
RGB or RGBA color values
- Type
- Array
(static) hsvToRgb(…values) → {Array}
Converts HSV color values to RGB color values.
Example
let mysphere = colorize(hsvToRgb([0.9166666666666666, 1, 1]), sphere())
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Number | Array |
<repeatable> |
HSV or HSVA color values |
Returns:
RGB or RGBA color values
- Type
- Array
(static) hueToColorComponent(p, q, t) → {Number}
Convert hue values to a color component (ie one of r, g, b)
Parameters:
Name | Type | Description |
---|---|---|
p |
Number | |
q |
Number | |
t |
Number |
Returns:
color component
- Type
- Number
(static) rgbToHex(…values) → {String}
Convert the given RGB color values to CSS color notation (string)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Number | Array |
<repeatable> |
RGB or RGBA color values |
Returns:
CSS color notation
- Type
- String
(static) rgbToHsl(…values) → {Array}
- Source:
- See:
Converts an RGB color value to HSL.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Number | Array |
<repeatable> |
RGB or RGBA color values |
Returns:
HSL or HSLA color values
- Type
- Array
(static) rgbToHsv(…values) → {Array}
Converts an RGB color value to HSV.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
values |
Number | Array |
<repeatable> |
RGB or RGBA color values |
Returns:
HSV or HSVA color values
- Type
- Array