meta data for this page
  •  

Color

Shapes can exhibit different colors. And just like the other transformations, adding color to a shape produces a new shape, i.e. one with color.

Colors are not only important for visual rendering but also controlling the selection of filaments during 3D printing. Therefore, colors should be applied as the last step in designs to insure proper printing.

const myshape = colorize([1, 0, 0], sphere()) // RGB red
const myshape = colorize([1, 0.5, 0.3], sphere()) // color
const myshape = colorize([1, 0.5, 0.3, 0.6], sphere()) // color plus alpha transparency

Note: There are known issues with transparency, and depending on the order of colors, objects may not seem transparent. Try different 'alpha' values or colors.

Color Space Conversion

There are several functions to convert between color spaces, including color names.

const wildcylinder = colorize(colorNameToRgb('fuchsia'), cylinder())
 
const bluesphere = colorize(hexToRgb('#000080'), sphere()) // navy blue
 
const mysphere = colorize(hslToRgb([0.9166666666666666, 1, 0.5]), sphere())
 
const mysphere = colorize(hsvToRgb([0.9166666666666666, 1, 1]), sphere())

whereas

See the Extended Color Keywords for all available colors. Color keywords are case-insensitive, e.g. 'RED' is the same as 'red'.