d4_path library
Say you have some code that draws to a 2D canvas:
drawCircle(context, radius) {
context.moveTo(radius, 0);
context.arc(0, 0, radius, 0, 2 * pi);
}
The d4_path package lets you take this exact code and additionally render to SVG. It works by serializing CanvasPathMethods calls to SVG path data. For example:
final path = Path();
drawCircle(path, 40);
path.toString(); // "M40,0A40,40,0,1,1,-40,0A40,40,0,1,1,40,0"
Now code you write once can be used with both Canvas (for performance) and SVG (for convenience). For a practical example, see d4_shape.
Classes
- Path
- A path serializer that implements CanvasPathMethods.