This is an old revision of the document!
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.
color([1,0.5,0.3],sphere()) color([1,0.5,0.3],sphere(10),cube(20)) color("Red",sphere(),cube().translate([2,0,0]))
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
sphere().setColor(1,0.5,0.3) sphere().setColor([1,0.5,0.3,0.7]) object.setColor(css2rgb('dodgerblue'));
The CSG library functions use RGB values between 0 and 1, not 0 and 255.
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.
Following functions to convert between color spaces.
var hsl = rgb2hsl(r,g,b); // or rgb2hsl([r,g,b]); var rgb = hsl2rgb(h,s,l); // or hsl2rgb([h,s,l]); var hsv = rgb2hsv(r,g,b); // or rgb2hsv([r,g,b]); var rgb = hsv2rgb(h,s,v); // or hsv2rgb([h,s,v]);
E.g. to create a rainbow, t = 0..1 and .setColor(hsl2rgb(t,1,0.5))
See the http://openjscad.org/#examples/slices/tor.jscad Tor (multi-color) for an example.