Skip to main content

Shapes

Presenter.js provides four general-purpose filled and stroked shapes: Rectangle, Circle, Polygon, and Path.

import { Anchor, Circle, Color, Path, Polygon, Rectangle } from "presenter";
const rectangle = Rectangle({  x: 330,  y: 500,  width: 1300,  height: 520,  cornerRadius: 80,  fillColor: Color("#3b82f6"),});
const circle = Circle({  x: 2860,  y: 760,  radius: 300,  anchor: Anchor.CENTER,  fillColor: Color("#34d399"),});
const polygon = Polygon({  points: [    { x: 380, y: 1940 },    { x: 980, y: 1390 },    { x: 1580, y: 1940 },  ],  fillColor: Color("#f59e0b"),});
const path = Path({  path: "M 50 6.58 L 60.78 39.75 L 95.65 39.75 ... Z",  x: 2550,  y: 1390,  width: 620,  height: 620,  viewboxWidth: 100,  viewboxHeight: 100,  fillColor: Color("#f472b6"),});

These shapes support fillColor, strokeColor, strokeWidth, and drawn properties. Animate drawn from 0 to 1 to reveal the outline. Fill can then be animated separately:

import { Animate, Color, Slide } from "presenter";
const slide = Slide({  objects: [star],  animations: [    [      Animate(star, { drawn: 1 }, { block: true }),      Animate(star, { fillColor: Color("#fde68a") }, { duration: 500 }),    ],  ],});

Rectangle

Set x, y, width, and height. Use cornerRadius for rounded corners.

The full list of available Rectangle properties is below:

PropertyTypeDescriptionDefault
anchorAnchorDefines which point of shape sits at (x, y)Anchor.TOP_LEFT
cornerRadiusnumberAmount of corner rounding, in pixels0
descriptionstring | nullAccessible description of shapenull
drawnnumberProportion of the shape that is drawn1
heightnumberHeight of shape, in pixels100
fillColorColorColor of shape's fillColor.BLACK
opacitynumberOpacity of shape1
strokeColorColorColor of shape's borderColor.BLACK
strokeWidthnumberSize of shape's border in pixels0
widthnumberWidth of shape, in pixels100
xnumberHorizontal position of shape0
ynumberVertical position of shape0

Circle

Set the center with x and y, then use radius for size.

The full list of available Circle properties is below:

PropertyTypeDescriptionDefault
anchorAnchorDefines which point of shape sits at (x, y)Anchor.TOP_LEFT
drawnnumberProportion of the shape that is drawn1
descriptionstring | nullAccessible description of shapenull
fillColorColorColor of shape's fillColor.BLACK
opacitynumberOpacity of shape1
radiusnumberRadius of circle, in pixels50
strokeColorColorColor of shape's borderColor.BLACK
strokeWidthnumberSize of shape's border in pixels0
xnumberHorizontal position of shape0
ynumberVertical position of shape0

Polygon

points is an array of { x, y } coordinates in slide space. Presenter.js connects the final point back to the first, so the polygon is always closed.

The full list of available Polygon properties is below:

PropertyTypeDescriptionDefault
anchorAnchorDefines which point of shape sits at (x, y)Anchor.TOP_LEFT
descriptionstring | nullAccessible description of shapenull
drawnnumberProportion of the shape that is drawn1
fillColorColorColor of shape's fillColor.BLACK
opacitynumberOpacity of shape1
pointsPosition[]{ x, y } coordinates of polygon vertices[{ x: 0, y: 0 },
{ x: 100, y: 0 },
{ x: 100, y: 100 }]
strokeColorColorColor of shape's borderColor.BLACK
strokeWidthnumberSize of shape's border in pixels0

Path

path accepts SVG path data. viewboxWidth and viewboxHeight describe the coordinate system used by that data; width and height control its rendered size. This makes one path easy to reuse at different sizes.

The full list of available Path properties is below:

PropertyTypeDescriptionDefault
anchorAnchorDefines which point of shape sits at (x, y)Anchor.TOP_LEFT
descriptionstring | nullAccessible description of shapenull
drawnnumberProportion of the shape that is drawn1
fillColorColorColor of shape's fillTransparent()
heightnumberHeight of shape, in pixels100
isRoundedbooleanWhether stroke has rounded line capsfalse
opacitynumberOpacity of shape1
pathstringSVG path stringM 0 0 L 100 100
pathLengthnumberLength of SVG pathComputed path length
strokeColorColorColor of shape's borderColor.BLACK
strokeWidthnumberSize of shape's border in pixels4
viewboxHeightnumberCoordinate height of SVG viewboxheight
viewboxWidthnumberCoordinate width of SVG viewboxwidth
widthnumberWidth of shape, in pixels100
xnumberHorizontal position of shape0
ynumberVertical position of shape0