Wednesday, June 29, 2016

89. Shear

With shear, we can change angle between the x and y axis. All the sides maintain their length.


The pivot point is 50, 75, and which is center of left side, and which does not move during the transformation.


package ex89;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Shear;
import javafx.stage.Stage;

public class Ex89 extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        Rectangle rect1 = new Rectangle(50, 50, 100, 50);
        rect1.setFill(Color.rgb(255, 0, 0, 0.5));

        Rectangle rect2 = new Rectangle(50, 50, 100, 50);
        rect2.setFill(Color.rgb(0, 255, 0, 0.5));
        
        Shear shear = new Shear(0.5, 0.5, 50, 75);
        rect2.getTransforms().add(shear);
        
        Group root = new Group(rect1, rect2);
        Scene scene = new Scene(root,300,200);
        
        stage.setScene(scene);
        stage.setTitle("Example 89. Shear");
        stage.show();
    }
}

This is the output:


No comments:

Post a Comment