Wednesday, May 25, 2016

7. QuadCurve

A QuadCurve is a polynomial in the power of 2. In contrast we have already seen a CubicCurve, a polynomial in the power of 3.


A QuadCurve needs a start point, end point, as well as a control point. Here both the start and endpoints are on the horizontal middle line at y = 200.


The control point is the in middle, that is x = 200, but since y = 0, it acts to pull up the curve.



package ex07;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.QuadCurve;
import javafx.stage.Stage;

public class Ex07 extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        
        QuadCurve quad = new QuadCurve(
                0, 200,   // start x,y
                200, 0,   // control x,y
                400,200);  // end x,y
        quad.setFill(Color.RED);
        Group root = new Group();
        root.getChildren().add(quad);
        
        Scene scene = new Scene(root, 400, 400, Color.GHOSTWHITE);
        
        primaryStage.setTitle("Example 7. QuadCurve");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
    
}

This is the output:


No comments:

Post a Comment