A cubic curve is drawn. Besides a start and end point, it has 2 control points.
The first control point determines the initial slope of the curve coming from the start point. Here since the control point has only the y-point different, its slope will point downwards in the y-direction.
The second control point determines the final slope of the curve going to the end point. Here since the control point has only the y-point different, its slope will point upwards in the y direction.
package ex03;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.CubicCurve;
import javafx.stage.Stage;
public class Ex03 extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Example 3. Cubic Curve");
Group root = new Group();
Scene scene = new Scene(root, 320, 240, Color.WHITE);
CubicCurve cubicCurve = new CubicCurve(
20, 20, // start x,y
20, 220, // control x1, y1
300, 220, // control x2, y2
300, 20); // end x, y point
cubicCurve.setStroke(Color.BLACK);
cubicCurve.setStrokeWidth(3);
cubicCurve.setFill(Color.WHITE);
root.getChildren().add(cubicCurve);
primaryStage.setScene(scene);
primaryStage.show();
}
}
This is the output:
No comments:
Post a Comment