타원은 FabricJS에서 제공하는 다양한 모양 중 하나입니다. 타원을 생성하려면 Fabric.Ellipse 클래스의 인스턴스를 생성하여 캔버스에 추가해야 합니다. 기본적으로 FabricJS의 모든 객체는 중심을 회전점으로 사용합니다. 그러나 centeredRotation 속성을 사용하여 이 동작을 변경할 수 있습니다.
문법
new fabric.Ellipse({ centeredRotation: Boolean }: Object)
매개변수
-
옵션 (선택 사항) - 이 매개변수는 타원에 대한 추가 사용자 정의를 제공하는 객체입니다</em>. 이 매개변수를 사용하면 객체의 색상, 커서, 획 너비 및 centeredRotation 속성과 관련된 기타 여러 속성을 변경할 수 있습니다 .
옵션 키
-
centeredRotation - 이 속성은 컨트롤에 의해 회전될 때 개체가 중심점을 변환 원점으로 사용하는지 여부를 제어할 수 있는 부울 값을 허용합니다. 기본값은 True 입니다 .
실시예 1
FabricJS에서 타원 회전의 기본 동작
타원 객체의 기본 동작을 설명하는 예를 살펴보겠습니다. centeredRotation 속성은 기본적으로 "true"로 설정되어 있으므로 타원 객체는 중심을 회전점으로 사용합니다.
<!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 disable the centered rotation of Ellipse using FabricJS?</h2>
<p>Select the object and rotate it. The ellipse will by default rotate around its center. This is the default behavior.</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: 215,
top: 100,
fill: "white",
rx: 90,
ry: 50,
stroke: "#c154c1",
strokeWidth: 5,
borderColor: "#daa520",
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
실시예 2
"false" 값으로 centeredRotation 키를 전달합니다.
이제 기본 동작을 살펴보았으므로 centeredRotation 속성에 "false" 값이 할당될 때 어떤 일이 발생하는지 이해하기 위해 코드를 살펴보겠습니다 . 여기서 타원은 더 이상 타원의 중심을 회전 원점으로 사용하지 않고 타원의 측면 중 하나를 사용합니다.
<!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 disable the centered rotation of Ellipse using FabricJS?</h2>
<p>Select the object and try to rotate it. The ellipse will not rotate around its center because we have set <b>centeredRotation</b> to False. </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: 215,
top: 100,
fill: "white",
rx: 90,
ry: 50,
stroke: "#c154c1",
strokeWidth: 5,
borderColor: "#daa520",
centeredRotation: false,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>