Skip to main content

colors

modeling/colors

所有形状(基本几何体或运算结果)都可以被指定颜色(RGBA 格式)。在所有情况下,函数均返回运算结果,且不会修改原始形状。

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)

将指定的颜色分配给指定的对象。

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)

将 CSS 颜色表示法(十六进制值字符串)转换为 RGB 数值。

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)

将HSV 颜色值转换为 RGB 颜色值。

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)

将色相值转换为一个颜色分量(即 R、G、B 中的一个)。

Kind: static method of modeling/colors
Returns: Number - color component

ParamType
pNumber
qNumber
tNumber

modeling/colors.rgbToHex(...values)

将给定的 RGB 颜色值 转换为 CSS 颜色表示法(字符串形式)。

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