Jump to content

OpenSCAD User Manual/First Steps/Changing the color of an object

From Wikibooks, open books for an open world

Any object, or a group of them, may be colored by preceding the object module call with the color() operator module.

There are two ways to specify the color to set:

RGB vector
three floats in the range [0.0:1.0] in a three element vector [<redval>,<greenval>,<blueval>]
"<colorname>"
a string containing a color name from the list of Web Colors.

Note:
changing the colors works only in Preview mode (F5); render mode (F6) does not currently support color


Usage example 1 - changing the color of an object:
color([1,0,0])
   cube([2,3,4]);
translate([3,0,0])
   color([0,1,0])
      cube([2,3,4]);
translate([6,0,0])
   color([0,0,1])
      cube([2,3,4]);
OpenSCAD changing the color of an object

A color() operator may be included, the same as any other operator, like translate(), in a stack of operators that precede call to an object module.

Using braces ("{}") to define a level of scope will apply color, or any other operator module, to all of the objects included in the scope

color([0,0,1]) {
    translate([6,0,0])
       cube([2,3,4]);
    translate([-6,0,0])
       cube([2,3,4]);
    }

In a stack of operators the first call to color() overrides all others that come later.

green arrow pointing left to previous page
Positioning an object
First Steps green arrow pointing right to next page
First Steps: Model views
Changing the color of an object