colors
modeling/colors
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.
Example
const { colorize, hexToRgb } = require('@jscad/modeling').colors
modeling/colors.cssColors
Kind: static enum of modeling/colors
See: CSS color table from http://www.w3.org/TR/css3-color/
Properties
| Name | Type | Default |
|---|---|---|
| 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 | ["","",""] |
Example
let newshape = colorize(cssColors.red, oldshape)
modeling/colors.colorize(color, ...objects)
Assign the given color to the given objects.
Kind: static method of modeling/colors
Returns: Object ⎮ Array - new object, or list of new objects with an additional attribute 'color'
| Param | Type | Description |
|---|---|---|
| color | Array | RGBA color values, where each value is between 0 and 1.0 |
| ...objects | Object | Array | the objects of which to apply the given color |
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
modeling/colors.colorNameToRgb(s)
Converts a CSS color name to RGB color.
Kind: static method of modeling/colors
Returns: Array - the RGB color, or undefined if not found
| Param | Type | Description |
|---|---|---|
| s | String | the CSS color name |
Example
let mysphere = colorize(colorNameToRgb('lightblue'), sphere())
modeling/colors.hexToRgb(notation)
Converts CSS color notations (string of hex values) to RGB values.
Kind: static method of modeling/colors
Returns: Array - RGB color values
See: https://www.w3.org/TR/css-color-3/
| Param | Type | Description |
|---|---|---|
| notation | String | color notation |
Example
let mysphere = colorize(hexToRgb('#000080'), sphere()) // navy blue
modeling/colors.hslToRgb(...values)
Converts HSL color values to RGB color values.
Kind: static method of modeling/colors
Returns: Array - RGB or RGBA color values
See: http://en.wikipedia.org/wiki/HSL_color_space
| Param | Type | Description |
|---|---|---|
| ...values | Number | Array | HSL or HSLA color values |
Example
let mysphere = colorize(hslToRgb([0.9166666666666666, 1, 0.5]), sphere())
modeling/colors.hsvToRgb(...values)
Converts HSV color values to RGB color values.
Kind: static method of modeling/colors
Returns: Array - RGB or RGBA color values
See: http://en.wikipedia.org/wiki/HSV_color_space.
| Param | Type | Description |
|---|---|---|
| ...values | Number | Array | HSV or HSVA color values |
Example
let mysphere = colorize(hsvToRgb([0.9166666666666666, 1, 1]), sphere())
modeling/colors.hueToColorComponent(p, q, t)
Convert hue values to a color component (ie one of r, g, b)
Kind: static method of modeling/colors
Returns: Number - color component
| Param | Type |
|---|---|
| p | Number |
| q | Number |
| t | Number |
modeling/colors.rgbToHex(...values)
Convert the given RGB color values to CSS color notation (string)
Kind: static method of modeling/colors
Returns: String - CSS color notation
See: https://www.w3.org/TR/css-color-3/
| Param | Type | Description |
|---|---|---|
| ...values | Number | Array | RGB or RGBA color values |
modeling/colors.rgbToHsl(...values)
Converts an RGB color value to HSL.
Kind: static method of modeling/colors
Returns: Array - HSL or HSLA color values
See
- http://en.wikipedia.org/wiki/HSL_color_space.
- http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
| Param | Type | Description |
|---|---|---|
| ...values | Number | Array | RGB or RGBA color values |
modeling/colors.rgbToHsv(...values)
Converts an RGB color value to HSV.
Kind: static method of modeling/colors
Returns: Array - HSV or HSVA color values
See: http://en.wikipedia.org/wiki/HSV_color_space.
| Param | Type | Description |
|---|---|---|
| ...values | Number | Array | RGB or RGBA color values |