meta data for this page
  •  

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, i.e. one with color.

let myshape = color([1, 0, 0], sphere()) // red
let myshape = color([1, 0.5, 0.3], sphere()) // ??
let myshape = color([1, 0.5, 0.3, 0.6], sphere(10), cube(20)) // 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

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)

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