Canvas Commons Documentation
website·Indexed 31 days ago
https://canvascommons.ioA framework for creating explanatory animations using code. Features include a node-based hierarchy, tweening and spring animations, LaTeX support, project variables, and a plugin system for Node.js, runtime, and editor extensions. Includes tools for rendering animations via image sequences or FFmpeg video export, as well as a presentation mode with slide management.
What's inside Canvas Commons
- Canvas Commons is a specialized toolset designed for creating informative vector animations and synchronizing them with voice-overs. It is not intended as a replacement for traditional video editing software. The system consists of two primary components: a TypeScript library that utilizes generators to program animations, and an editor that provides a real-time preview of those animations and allows for the editing of specific animation aspects (such as time events).
Overview of GeneratorScene
GeneratorSceneTis the default implementation of theSceneinterface. It uses generators to control animations and manages the lifecycle, rendering, and state of a scene within the project.abstract class GeneratorSceneT implements SceneThreadGeneratorFactoryTThreadableOverview of PathDataBuilder
PathDataBuilder is a utility class used to programmatically construct SVG path data strings. It provides a fluent interface to define shapes and paths that can be passed to Path2D objects or other renderers such as Rough.js.const builder = new PathDataBuilder(); const pathData = builder.moveTo(0, 0).lineTo(10, 10).toString();Overview of the Curve abstract class
TheCurveclass is an abstract extension ofShape. It provides the base functionality for all curve-based components in the 2D API. Subclasses that extendCurveincludeBezier,Circle,Line,Path,Polygon,Ray,Rect, andSpline.Canvas Commons animation and typesetting features
Canvas Commons provides advanced programmatic control over visuals and text, including:
- Typesetting: Support for
Txt.split()(grapheme/word/sentence nodes), text along SVG paths or live Curves, Knuth–Plass wrapMode, hyphenation, justification, and wrapping text around shapes. - Animation: Rough/hand-drawn shape rendering, animated layouts, explicit space positioning, and improved interpolation for paths, SVGs, and images.
- LaTeX: Simplified editing for LaTeX mathematical expressions.
- Workflow: Ability to export/copy frames and copy coordinates in viewport space.
- Typesetting: Support for
Implement the Inspectable interface for Scene components
Scenes can implement theInspectableinterface to enable their components to be inspected via the UI. This interface provides a set of methods to handle how elements are identified, transformed, and displayed in the properties panel and on the canvas overlay.Draw Cubic and Quadratic Bézier curves
Canvas Commons providesCubicBezierandQuadBeziercomponents to draw Bézier curves. A Quadratic Bézier curve uses one control point, while a Cubic Bézier curve uses two. For more complex shapes, use theSplinecomponent instead.Implement a custom exporter using the Exporter interface
TheExporterinterface is the main interface used to implement custom exporters. It provides a lifecycle for preparing configuration, initializing resources, handling individual rendered frames, and performing final cleanup.Matrix2D Overview and Representation
The
Matrix2Dclass implementsTypeWebGLConvertibleand represents a 2D transformation using a specialized 2x3 matrix. It contains six elements defined as[a, b, c, d, tx, ty], which serves as a shortcut for a 3x3 matrix of the form[a, b, 0, c, d, 0, tx, ty, 1].Because it ignores z-values, it does not satisfy all standard 3x3 matrix properties: it has no transpose, and certain distributive and scalar properties (e.g., A(B + C) = AB + AC) do not hold.
SplineProps Interface Overview
TheSplinePropsinterface extendsCurveProps, providing a set of properties used to configure spline curves in a 2D canvas environment. It includes properties for layout, positioning, visual styling, and curve-specific behavior.interface SplineProps extends CurvePropsUnderstand Canvas Commons versioning and compatibility
Canvas Commons uses the semver (semantic versioning) scheme. Releases sharing the same major version are backwards compatible. For example, an animation created with v3.2.0 will remain compatible with v3.2.1, v3.3.0, and v3.4.0.Use the SVG class for drawing and animating SVG images
TheSVGclass extendsShapeand is used to create a Node specifically for drawing and animating SVG images. If animation is not required, theImgcomponent is recommended as an alternative.class SVG extends Shape