No. The new color values will be in the range 0.0 ... 1.0
If any color is already at 0.0, darker()
will change no color value.
If any color is already at 1.0, brighter()
will change no color value.
Here is the program that produces the above image.
import javafx.application.*; import javafx.stage.*; import javafx.scene.Scene; import javafx.scene.Group; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.scene.paint.*; public class CircleDarker extends Application { public void start( Stage primaryStage ) { Color myFill = new Color( 0.9, 0.7, 0.9, 1.0 ); double rad = 50.0, yCenter = rad*3/2, xCenter = rad*3/2, shift = rad ; Circle circleA = new Circle( xCenter, yCenter, rad); circleA.setFill( myFill ); circleA.setStroke( Color.PURPLE ); xCenter += shift; myFill = myFill.darker(); Circle circleB = new Circle( xCenter, yCenter, rad); circleB.setFill( myFill ); circleB.setStroke( Color.PURPLE ); xCenter += shift; myFill = myFill.darker(); Circle circleC = new Circle( xCenter, yCenter, rad); circleC.setFill( myFill ); circleC.setStroke( Color.PURPLE ); Pane pane = new Pane( circleA, circleB, circleC ); Scene scene = new Scene( pane, rad*5, rad*3, Color.AQUA.brighter() ); primaryStage.setTitle("Darker Circles"); primaryStage.setScene( scene ); primaryStage.show(); } }
Things to note:
1. The fill colors of the right two circles is a darker version of the left circle fill color.
2. Although the colors get darker left to right, the opacity of the colors does not change.
3. The location of each circle is calculated based on the radius. This is much more convenient than hard-coded literals.
double rad = 50.0, yCenter = rad*3/2, xCenter = rad*3/2, shift = rad ;
4. All three circles are added to the Pane
Pane pane = new Pane( circleA, circleB, circleC );
5. ThePane
added to theScene
. The size of theScene
is calculated from the radii\us:
Scene scene = new Scene( pane, rad*5, rad*3, Color.AQUA.brighter() )
6. The circles are drawn in the order that they were added to the Pane
,
so the last added circle is in front of the other two.
Think of how to finish this code so that it draws a single circle centered in the window:
double radius = 100.0, yCenter = , xCenter = ; Circle circle = new Circle( xCenter, yCenter, radius ); circle.setFill( Color.YELLOW ); circle.setStroke( Color.DARKCYAN ); Pane pane = new Pane( circle ); Scene scene = new Scene( pane, , , Color.GHOSTWHITE );