sampleShapePoints

Returns perimeter points for a named shape centred at a point, starting at twelve o'clock and going clockwise, or an empty list for an unknown shape.

@internote/canvas-sdkFunction
On this page
import { sampleShapePoints } from '@internote/canvas-sdk';

The shapes are circle, square, rectangle, triangle, diamond, hexagon, star, cross and tick. Two shapes sampled with the same count morph into each other point by point.

#Signature

(
    x: number,
    y: number,
    r: number,
    type: string,
    n: number,
    halfHeight?: number,
): Vec2[]

#Parameters

x
The centre's x.
y
The centre's y.
r
The shape's radius, or half-size — a rectangle's half-width.
type
The shape's name, in any case.
n
How many points to sample.
halfHeight
A rectangle's half-height; absent, 0.6 of r.

#Example

const points = sampleShapePoints(cx, cy, size / 2, attrs.shape, 32);
<polygon points={points.map(([px, py]) => `${px},${py}`).join(' ')} />

Declared in packages/canvas-sdk/src/geometry/polygon-sampling.ts:73.

Last updated