jakubfiala / atrament

A small JS library for beautiful drawing and handwriting on the HTML Canvas.
http://fiala.space/atrament/demo
MIT License
1.57k stars 115 forks source link

Save strokes with uniform sizes #57

Closed uriberto closed 4 years ago

uriberto commented 4 years ago

I'm not sure if this is a bug or a feature, but the canvas does not handle resizing on its own. In particular, because the strokes are saved with absolute x/y coordinates, you have to be careful when you repaint the canvas that the size of the original canvas was the same as the size of the current canvas. I suggest saving the points in strokes always to a canvas of a uniform (large) size, then having the repaint function (.draw or .beginStroke, etc.) adjust for the size of the canvas.

Again, this might be the intended behavior (and once I realized what was happening, it wasn't a big deal to fix it in my own project), but I think it would be a nice feature if an atrament sketchpad could auto-resize when the underlying canvas was resized.

jakubfiala commented 4 years ago

@uriberto thanks for the suggestion! my original thought with this particular way of representing the strokes was that the library shouldn't be opinionated on how (and whether) strokes are saved. If I implement this behaviour, the library would have to keep track of all the strokes that are currently on the canvas, but I can't guarantee it would do it in a way that the application requires.

For instance, the re-rendering operation would have to be throttled so it doesn't slow down the app - but then I'd have to choose a reasonable default timeout for the throttling. Or I could use debouncing, but then what if the developer wants a gradual resize instead of a sharp debounced jump?

Another issue is the data representation - if, for instance, I saved the stroke coordinates as percentages of the canvas dimensions, I would have to adjust for the change of aspect ratio at every resize step. With a complex drawing with 1000s of points, this could get very slow. Perhaps some apps could tolerate that, but some others wouldn't, so sadly I have to limit the power of Atrament in order to cater for a broad set of use cases.

Let me know in case I misunderstood what you meant - in any case, I do really appreciate your interest and I hope you'll find Atrament a useful tool :)

jakubfiala commented 4 years ago

closing this for now, happy to reopen if there are any new suggestions!