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 thedattribute 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].optionsDrawable instance. See the Drawable constructor options section for more guidance.Drawable constructor options
toDtoDA 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
strokeThe stroke (Array) passed to the constructor.
If you assign a value directly to stroke, a setter will pass the new value to setStroke.
statusDrawable 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.dd (String) generated by the toD function passed to the constructor.toDtoD (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.strokesetStrokeset<Property> methodsstatus, dfetch, get, patch, post, put, delete, abortstop methodable