Hello,
Could I get some feedback on a package I have been working on quite a while? Its called Elm-Canvas. Here is the link to the repo: https://github.com/Elm-Canvas/elm-canvas . At the bottom of this post I have some links of code examples and the docs.
Its primarily meant to expose the Html Canvas api into Elm. At this point, after a year of use, I am ready to iterate on the package and make a major update. I would appreciate any thoughts on how I and the other contributors to the project have gone about making this package.
Use Case
My primary use case was a drawing application. Ive been working on that drawing application for a year and a half now, and I have been using Elm-Canvas continuously since the beginning. Aside from myself, the next two biggest contributors (in terms of loc) to the project were also working on drawing applications.
So I suppose the narrow use case is drawing applications, but the better and more abstract use case is for low-level high-performance graphics that cant be summarized as shapes, image assets, or document elements. Another way of putting this is that virtual doms only work when the source data is much smaller than the rendered data (like how āhiā is smaller than <p class=\"greeting\">Hi</p>
, or ā./mega-man.pngā is much smaller than the full pixel data of how mega man looks), but not when the source data is equally large to the rendered data (like when a list of pixel values in memory correspond exactly to whats getting rendered).
Our approach
We have just exposed the Canvas api in the most direct possible way, much like how Elm-Css exposes css directly. We have a Canvas
type, and a toHtml
function, and along the way you can modify Canvas
using another type called Ctx
, which represents all the methods and properties in the Canvas api. Originally Elm-Canvas was fairly indirect and abstract, but it wasnt very performant and it couldnt accomidate use cases that didnt want pixel perfect drawing, so thats when we changed to this direct approach.
Future
I just hope this will be a better project that others will find useful. I would like to make something good enough to one day be a part of the core programming language, or could greatly inform how Canvas will eventually be incorporated into Elm (Im not that optimistic about this however).
Feedback
Ill keep most of my thoughts to myself so as not to contaminate whatever feedback you all might offer, but I do have one question. Currently there are some possible run time errors, like if you initialize a canvas with a size of { width = 0, height = 0 }. What should be done about that? I suppose thats no worse than the existing run time errors in core; but still.
Links
Here are the docs:
http://elm-canvas-docs.surge.sh/
Here are two examples:
Drawing images - http://elm-canvas-docs.surge.sh/draw-image
Animation frame - http://elm-canvas-docs.surge.sh/animation-frame
Here is the code to the examples: