Skip to content
On this page

Rect Shape

TIP

This class is a descendant of Shape it also inherits all the options that Shape provides.

TIP

This component also supports a return function

To create a rectangle with fcanvas, we can instantiate a Rect object.

You can define corner radius for Rect. It can be simple number or array of numbers [topLeft, topRight, bottomRight, bottomLeft].

In addition, this shape also provides a few other parameters:

Require Options

NameTypeDescription
widthMayBeRef<number>width length
heightMayBeRef<number>height length

Inherit Shape

NameTypeDescription
xMayBeRef<number>offset x
yMayBeRef<number>offset y

Optional Options

NameTypeDefaultDescription
cornerRadiusMayBeRef<number | [number, number] | [number, number, number, number]>0This property is same as border-radius in css

Demo

ts
import { Stage, Layer, Rect } from "fcanvas"

const stage = new Stage({ height: 200 }).mount("#app")
const layer = new Layer().addTo(stage)

const rect1 = new Rect({
  x: 20,
  y: 20,
  width: 100,
  height: 50,
  fill: "green",
  stroke: "black",
  strokeWidth: 4
}).addTo(layer)
const rect2 = new Rect({
  x: 150,
  y: 40,
  width: 100,
  height: 50,
  fill: "red",
  shadowBlur: 10,
  cornerRadius: 10
}).addTo(layer)
const rect3 = new Rect({
  x: 50,
  y: 120,
  width: 100,
  height: 100,
  fill: "blue",
  cornerRadius: [0, 10, 20, 30]
}).addTo(layer)

Released under the MIT License.