Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to set the angle of skew on Y-axis of Ellipse using FabricJS?
In this tutorial, we are going to learn how to set the angle of skew on Y-axis of an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will have to create an instance of fabric.Ellipse class and add it to the canvas. Our ellipse object can be customized in various ways like changing its dimensions, adding a background color or by changing the angle of skew on Y-axis. We can do this by using the skewY property.
Syntax
new fabric.Ellipse({ skewY : Number }: Object)
Parameters
-
options (optional) ? This parameter is an Object which provides additional customizations to our ellipse. Using this parameter color, cursor, stroke width and a lot of other properties can be changed related to the object of which skewY is a property.
Options Keys
-
skewY ? This property accepts a Number which determines the angle of skew on Y-axis of an object. The value is specified in degrees.
Example 1: Default Ellipse Without Skew
Let's see a code to understand how our ellipse object appears when the skewY property is not applied. In this case, there will be no skew in our ellipse object.
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>How to set the angle of skew on Y-axis of Ellipse using FabricJS?</h2>
<p>Notice there is no angle of skew here as we have not applied the <b>skewX</b> or <b>skewY</b> property. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 115,
top: 50,
rx: 80,
ry: 50,
fill: "#ff1493",
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
Example 2: Applying skewY Property
In this example, we will see how we can assign a numerical value to the skewY property. The value that is being passed will determine the skew along the Y-axis. Here we use a 30-degree skew to demonstrate the transformation effect.
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>How to set the angle of skew on y-axis of Ellipse using FabricJS?</h2>
<p>Here the ellipse is skewed on the Y-axis by 30 degrees, as we have applied the <b>skewY</b> property. </p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 115,
top: 50,
rx: 80,
ry: 50,
fill: "#ff1493",
skewY: 30,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
Key Points
The
skewYproperty accepts positive or negative numerical values in degreesPositive values skew the ellipse in one direction, negative values skew in the opposite direction
The skew transformation is applied along the vertical (Y) axis
This property can be combined with other transformation properties like
skewX,scaleX, androtation
Conclusion
The skewY property in FabricJS provides an easy way to apply vertical skew transformations to ellipse objects. By adjusting the numerical value, you can control the degree and direction of the skew effect on the Y-axis.
