We have two rectangle, red and green, at same location and with same size. However the green is scaled down 50% in both x and y directions.
The pivot point corresponds to center left of the rectangles (50, 75). This point will not change position during the scaling.
package ex88;
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.Scale;
import javafx.stage.Stage;
public class Ex88 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));
Scale scale = new Scale(0.5, 0.5, 50, 75);
rect2.getTransforms().add(scale);
Group root = new Group(rect1, rect2);
Scene scene = new Scene(root,300,200);
stage.setScene(scene);
stage.setTitle("Example 88. Scale");
stage.show();
}
}
This is the output:
No comments:
Post a Comment