Java Reference
In-Depth Information
coloringattributes
ColoringAttributes controls how the various primitives will be colored. Colors can be
specified in a variety of methods. As an example, colors may be defined at each vertex of
a geometry object. In this case, as the geometry is created, the colors used in the geometry
object will override the intrinsic color in ColoringAttributes. In addition, if lighting is
used, the ColoringAttributes intrinsic color will be ignored completely and material color
is used instead.
The code fragment in Figure 16 shows a simple example illustrating how the color of
the object can be specified or changed. Line 21 creates a new ColoringAttributes object, and
line 23 sets the new color. In this example, the use of Color3f(1.0f, 0.0f, 0.0f) corresponds
to the use of red. Green and blue can similarly be specified by using (0.0f, 1.0f, 0.0f) and
(0.0f, 0.0f, 1.0f), respectively.
Figure 16. Code segment and result of AppearanceCOLOR.java
1.
public class AppearanceCOLOR extends Applet
2.
{
3.
public class Letter_E extends Shape3D
4.
{
5.
int vertex = 4;
6.
//constructor
7.
public Letter_E()
8.
{
9.
10.
this.setGeometry(Quad1Geometry());
11.
this.addGeometry(Quad2Geometry());
12.
this.addGeometry(Quad3Geometry());
13.
this.addGeometry(Quad4Geometry());
14.
this.setAppearance(Letter_E_Appearance());
15.
16.
}
17.
18.
private Appearance Letter_E_Appearance()
19.
{
20.
Appearance look = new Appearance();
21.
ColoringAttributes colorAttrib = new ColoringAttributes();
22.
//set new color for the object
23.
colorAttrib.setColor(new Color3f(1.0f,0.0f,0.0f));
24.
PolygonAttributes polyAttrib = new PolygonAttributes();
25.
//to make both sides of the face appear
26.
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
27.
look.setColoringAttributes(colorAttrib);
28.
look.setPolygonAttributes(polyAttrib);
29.
return look;
30.
}
31.
Search WWH ::




Custom Search