Java Reference
In-Depth Information
The applet shows how points off the gradient line have the same color as the normal projection onto the
line. This is always the case, regardless of the orientation of the gradient line. You could try changing the
definition of g1 for the upper rectangle to:
GradientPaint g1 = new GradientPaint(p1.x, p1.y - 20, Color.WHITE,
p2.x, p2.y + 20, Color.DARK_GRAY,
true);
// Cyclic
gradient
You also need to draw the gradient line in its new orientation:
g2D.draw(rect1); // Fill the
rectangle
//g2D.draw(new Line2D.Float(p1, p2));
g2D.draw(new Line2D.Float(p1.x, p1.y - 20, p2.x, p2.y + 20));
The annotation for the end points also have to be moved:
g2D.drawString("p1",p1.x - 20,p1.y - 20);
g2D.drawString("p2",p2.x + 10,p2.y + 20);
If you run the applet with these changes, you can see in Figure 19-21 how the gradient is tilted and how
the color of a point off the gradient line matches that of the point that is the orthogonal projection onto it.
FIGURE 19-21
MANAGING SHAPES
When you create shapes in Sketcher, you have no idea of the sequence of shape types that will occur. This
is determined totally by the person using the program to produce a sketch. You therefore need to be able to
 
 
Search WWH ::




Custom Search