Skip to main content

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

NameTypeDefault
blackArray["","",""]
silverArray["","",""]
grayArray["","",""]
whiteArray["","",""]
maroonArray["","",""]
redArray["","",""]
purpleArray["","",""]
fuchsiaArray["","",""]
greenArray["","",""]
limeArray["","",""]
oliveArray["","",""]
yellowArray["","",""]
navyArray["","",""]
blueArray["","",""]
tealArray["","",""]
aquaArray["","",""]
aliceblueArray["","",""]
antiquewhiteArray["","",""]
aquamarineArray["","",""]
azureArray["","",""]
beigeArray["","",""]
bisqueArray["","",""]
blanchedalmondArray["","",""]
bluevioletArray["","",""]
brownArray["","",""]
burlywoodArray["","",""]
cadetblueArray["","",""]
chartreuseArray["","",""]
chocolateArray["","",""]
coralArray["","",""]
cornflowerblueArray["","",""]
cornsilkArray["","",""]
crimsonArray["","",""]
cyanArray["","",""]
darkblueArray["","",""]
darkcyanArray["","",""]
darkgoldenrodArray["","",""]
darkgrayArray["","",""]
darkgreenArray["","",""]
darkgreyArray["","",""]
darkkhakiArray["","",""]
darkmagentaArray["","",""]
darkolivegreenArray["","",""]
darkorangeArray["","",""]
darkorchidArray["","",""]
darkredArray["","",""]
darksalmonArray["","",""]
darkseagreenArray["","",""]
darkslateblueArray["","",""]
darkslategrayArray["","",""]
darkslategreyArray["","",""]
darkturquoiseArray["","",""]
darkvioletArray["","",""]
deeppinkArray["","",""]
deepskyblueArray["","",""]
dimgrayArray["","",""]
dimgreyArray["","",""]
dodgerblueArray["","",""]
firebrickArray["","",""]
floralwhiteArray["","",""]
forestgreenArray["","",""]
gainsboroArray["","",""]
ghostwhiteArray["","",""]
goldArray["","",""]
goldenrodArray["","",""]
greenyellowArray["","",""]
greyArray["","",""]
honeydewArray["","",""]
hotpinkArray["","",""]
indianredArray["","",""]
indigoArray["","",""]
ivoryArray["","",""]
khakiArray["","",""]
lavenderArray["","",""]
lavenderblushArray["","",""]
lawngreenArray["","",""]
lemonchiffonArray["","",""]
lightblueArray["","",""]
lightcoralArray["","",""]
lightcyanArray["","",""]
lightgoldenrodyellowArray["","",""]
lightgrayArray["","",""]
lightgreenArray["","",""]
lightgreyArray["","",""]
lightpinkArray["","",""]
lightsalmonArray["","",""]
lightseagreenArray["","",""]
lightskyblueArray["","",""]
lightslategrayArray["","",""]
lightslategreyArray["","",""]
lightsteelblueArray["","",""]
lightyellowArray["","",""]
limegreenArray["","",""]
linenArray["","",""]
magentaArray["","",""]
mediumaquamarineArray["","",""]
mediumblueArray["","",""]
mediumorchidArray["","",""]
mediumpurpleArray["","",""]
mediumseagreenArray["","",""]
mediumslateblueArray["","",""]
mediumspringgreenArray["","",""]
mediumturquoiseArray["","",""]
mediumvioletredArray["","",""]
midnightblueArray["","",""]
mintcreamArray["","",""]
mistyroseArray["","",""]
moccasinArray["","",""]
navajowhiteArray["","",""]
oldlaceArray["","",""]
olivedrabArray["","",""]
orangeArray["","",""]
orangeredArray["","",""]
orchidArray["","",""]
palegoldenrodArray["","",""]
palegreenArray["","",""]
paleturquoiseArray["","",""]
palevioletredArray["","",""]
papayawhipArray["","",""]
peachpuffArray["","",""]
peruArray["","",""]
pinkArray["","",""]
plumArray["","",""]
powderblueArray["","",""]
rosybrownArray["","",""]
royalblueArray["","",""]
saddlebrownArray["","",""]
salmonArray["","",""]
sandybrownArray["","",""]
seagreenArray["","",""]
seashellArray["","",""]
siennaArray["","",""]
skyblueArray["","",""]
slateblueArray["","",""]
slategrayArray["","",""]
slategreyArray["","",""]
snowArray["","",""]
springgreenArray["","",""]
steelblueArray["","",""]
tanArray["","",""]
thistleArray["","",""]
tomatoArray["","",""]
turquoiseArray["","",""]
violetArray["","",""]
wheatArray["","",""]
whitesmokeArray["","",""]
yellowgreenArray["","",""]

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: ObjectArray - new object, or list of new objects with an additional attribute 'color'

ParamTypeDescription
colorArrayRGBA color values, where each value is between 0 and 1.0
...objectsObject | Arraythe 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

ParamTypeDescription
sStringthe 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/

ParamTypeDescription
notationStringcolor 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

ParamTypeDescription
...valuesNumber | ArrayHSL 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.

ParamTypeDescription
...valuesNumber | ArrayHSV 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

ParamType
pNumber
qNumber
tNumber

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/

ParamTypeDescription
...valuesNumber | ArrayRGB 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

ParamTypeDescription
...valuesNumber | ArrayRGB 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.

ParamTypeDescription
...valuesNumber | ArrayRGB or RGBA color values