User Tools


This is an old revision of the document!


Color

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

NOTE: 2D shapes cannot exhibit colors today. This is a known issue.

let a = color("Red",sphere())
let b = color([1, 0.5, 0.3],sphere())
let c = color([1, 0.5, 0.3, 0.6],sphere(10),cube(20))

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

The CSG library functions can also be used. NOTE: Deprecated in the V2 API

let a = object.setColor(css2rgb('dodgerblue'))
let b = sphere().setColor(1, 0.5, 0.3)
let c = sphere().setColor([1, 0.5,0.3, 0.7])

Note: There are some Transparency_Sorting|OpenGL Transparency Limitations, e.g. and depending on the order of colors, you might not see through otherwise partially transparent objects.

Color Space Conversion

Following functions to convert between color spaces.

let rgb = css2rgb('navy')
let rgb = html2rgb('#RRGGBB')
 
let rgb = hsl2rgb(h,s,l) // or hsl2rgb([h,s,l])
let rgb = hsv2rgb(h,s,v) // or hsv2rgb([h,s,v])
 
let hsv = rgb2hsv(r,g,b) // or rgb2hsv([r,g,b])
let hsl = rgb2hsl(r,g,b) // or rgb2hsl([r,g,b])
let html = rgb2html(r,g,b)

whereas

  • r,g,b (red, green, blue)
  • h,s,l (hue, saturation, lightness)
  • h,s,v (hue, saturation, value)