Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In this article, we will learn about Scaling, the introduction to JavaFX Scaling, the constructor of JavaFX Scaling, the properties of JavaFX Scaling, and examples of JavaFX Scaling. Scaling transformation is used to alter an object's size. You either increase or decrease the object's dimensions throughout the scaling procedure. To scale an object, multiply its original coordinates by the scaling factor until the desired result is obtained.In JavaFX, the class javafx.scene.transform. Scale is used to represent the scaling transformation.
JavaFX Scaling
A type of transformation used to alter an object's size is scaling. It has the ability to either increase or decrease an object's size. By multiplying the item's coordinates by a variable known as the scale factor, the size of the object can be changed. The class javafx.scene.transform in JavaFX. The transition of scaling is represented by scale.
Constructors of Scaling
Constructor
Function
Public Scale()
establishes a new instance using the default parameters.
Public Scale(double X, double Y, double Z)
It will help in creating a new instance of 3D Scale.
Public Scale(double X, double Y)
It will help in creating a new instance of 2D Scale.
Public Scale(double X, double Y, double pivotX, double pivotY)
2D new instances will be created with the specified pivot coordinates.
Public Scale(double X,double Y, double Z, double pivotX, double pivotY, double pivotZ)
3D new instances will be created with the specified pivot coordinates.
Properties and Method of JavaFX Scaling
Method
Description
Pivot X
It is used to indicate the pivot point's x coordinate, and its value is set using the setPivotX(Double value) method.
PivotY
It represents the pivot point's y coordinate, around which scaling is carried out.
PivotZ
It serves as a representation of the pivot point's z coordinate, around which scaling is carried out.
x
It shows how much the object is scaled in relation to the X-axis.
y
It shows how much the object is scaled in relation to the Y-axis.
z
It shows how much the object is scaled in relation to the Z-axis.
Programs to implement JavaFX Scaling
import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Scale;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) {
//Drawing rectangle1
Rectangle rectangle1 = new Rectangle(40,70,220,180);
//Setting the color of the rectangle
rectangle1.setFill(Color.BLUEVIOLET);
//Setting the stroke width of the circle
rectangle1.setStrokeWidth(20);
//Drawing rectangle2
Rectangle rectangle2 = new Rectangle(40,70,220,180);
//Setting the color of the rectangle
rectangle2.setFill(Color.BROWN);
//Setting the stroke width of the Rectangle
rectangle2.setStrokeWidth(50);
//Creating the scale transformation
Scale scale = new Scale();
//Setting the dimensions for the transformation
scale.setX(1.5);
scale.setY(1.5);
//Setting the pivot point for the transformation
scale.setPivotX(200);
scale.setPivotY(100);
//Adding the scale transformation to rectangle1
rectangle1.getTransforms().addAll(scale);
//Creating a Group object
Group root = new Group(rectangle1, rectangle2);
//Creating a scene object
Scene scene = new Scene(root, 500, 300);
//Setting title to the Stage
stage.setTitle("Coding Ninjas");
//Adding scene to the stage
stage.setScene(scene);
//Displaying the contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
You can also try this code with Online Java Compiler
A translation changes the location of an object on the screen. Adding the translation coordinates (tx, ty) to the original coordinates (X, Y) yields the new coordinates (X', Y'), which is how you move a point in two dimensions.
What various transformations does JavaFX support?
Transformations come in a variety of forms, including translation, scaling up or down, rotation, shearing, and more. Nodes can undergo transformations including rotation, scaling, and translation using JavaFX. The classes that represent all of these modifications are part of the package javafx.
What do image scaling and translating mean?
The scaling transformation modifies the proportions of a shape but not its underlying form. An ellipse can be scaled by 0.5 to get an equivalent shape that is half as broad and half as tall as the original. By a specific amount, the translation transformation moves a shape.
Conclusion
In this article, we have extensively discussed the introduction to JavaFX Scaling, the constructor of JavaFX Scaling, the properties of JavaFX Scaling, and examples of JavaFX Scaling.