Skip to main content

Class: default

Defined in: src/lib/brushes/StrokeSampler/index.ts:35

Records a stroke's points over time: the first point (pointer down), then a point at most every sampleRate milliseconds while the pointer moves, and the last point (pointer up). No points are recorded while the pointer is still, even if it is held down.

Example​

const sampler = new StrokeSampler(50);
sampler.start({ x: 0, y: 0 }, 0);
sampler.move({ x: 5, y: 0 }, 20); // undefined (too soon)
sampler.move({ x: 9, y: 0 }, 60); // recorded
sampler.end({ x: 12, y: 0 }, 70); // recorded

Constructors​

Constructor​

new default(sampleRate?): StrokeSampler

Defined in: src/lib/brushes/StrokeSampler/index.ts:44

Parameters​

sampleRate?​

number

Returns​

StrokeSampler

Properties​

points​

readonly points: BrushStrokePoint[] = []

Defined in: src/lib/brushes/StrokeSampler/index.ts:40

Points recorded so far


sampleRate​

readonly sampleRate: number

Defined in: src/lib/brushes/StrokeSampler/index.ts:37

Milliseconds between recorded points

Accessors​

last​

Get Signature​

get last(): BrushStrokePoint | undefined

Defined in: src/lib/brushes/StrokeSampler/index.ts:49

The most recently recorded point

Returns​

BrushStrokePoint | undefined

Methods​

end()​

end(point, time): BrushStrokePoint | undefined

Defined in: src/lib/brushes/StrokeSampler/index.ts:73

Finish the stroke at the pointer-up point. Returns it if recorded (it differs from the last recorded position).

Parameters​

point​

BrushStrokePoint

time​

number

Returns​

BrushStrokePoint | undefined


move()​

move(point, time): BrushStrokePoint | undefined

Defined in: src/lib/brushes/StrokeSampler/index.ts:64

Offer a point while the pointer moves. Returns it if recorded: enough time has passed and the pointer has moved.

Parameters​

point​

BrushStrokePoint

time​

number

Returns​

BrushStrokePoint | undefined


start()​

start(point, time): BrushStrokePoint

Defined in: src/lib/brushes/StrokeSampler/index.ts:56

Begin a stroke at the pointer-down point. Always recorded.

Parameters​

point​

BrushStrokePoint

time​

number

Returns​

BrushStrokePoint