Drawable
Updated on August 22, 2024Source codeTests
Drawable
is a class that enriches a stroke (an array of points as [x, y, pressure]
), allowing it to:
- Draw additional points on the stroke
- Store a
d
(i.e. a string that can be set to thed
attribute of an SVG<path>
), updated automatically after drawing additional points - Store a status (
ready
,drawing
, ordrawn
)
Construct a Drawable
instance
The Drawable
constructor accepts two parameters:
stroke
[x, y, pressure]
.options
Drawable
instance. See the Drawable
constructor options section for more guidance.Drawable
constructor options
toD
toD
A function that, when called, returns a d
(String) for the Drawable
instance.
Defaults to the toD
function exported from Baleada Logic, which is an adaptation of the perfect-freehand
rendering example.
Baleada Logic also exports a toFlattenedD
function, adapted from the perfect-freehand
flattening example, which you can pass to the toD
option if you want to flatten your strokes.
State and methods
stroke
The stroke
(Array) passed to the constructor.
If you assign a value directly to stroke
, a setter will pass the new value to setStroke
.
status
Drawable
instance. status
is ready
after the instance is constructed, and changes to drawing
while the instance is drawing and drawn
after the instance is done drawing.d
d
(String) generated by the toD
function passed to the constructor.toD
toD
(Function) passed to the constructor.draw(points, options)
An array of points as [x, y, pressure]
and options for the getStroke
function from perfect-freehand
.
See the perfect-freehand
docs for more guidance.
Drawable
instanceAPI design compliance
options
object.stroke
setStroke
set<Property>
methodsstatus
, d
fetch
, get
, patch
, post
, put
, delete
, abort
stop
methodable