Question
How to draw for free (using the mouse / fingers) on the canvas element, how can you do this in paint with a pencil?
About this question
There are many questions that want to achieve free drawing on canvas:
- draw with mouse HTML5 canvas
- KineticJS - draw for free with the mouse
- Free canvas art using fabric.js
- Outline with JS
- Paint does not work properly
- Mouse position on canvas
- Implement smooth sketching and drawing on an element
So, I thought it would be nice to make a reference question, where each answer will be a wiki community and contains an explanation of only one JavaScript / pure JavaScript library, how to draw on canvas.
Response structure
Answers must be a community wiki and use the following template:
## [Name of library](Link to project page) ### Simple example A basic, complete example. That means it has to contain HTML and JavaScript. You can start with this: <!DOCTYPE html> <html> <head> <title>Simple example</title> <script type='text/javascript' src='http://cdnjs.com/[your library]'></script> <style type='text/css'> #sheet { border:1px solid black; } </style> <script type='text/javascript'> window.onload=function(){ </script> </head> <body> <canvas id="sheet" width="400" height="400"></canvas> </body> </html> If possible, this example should work with both, mouse and touch events. [JSFiddle](Link to code on jsfiddle.net) This solution works with: * Desktop computers: * [Browser + Version list] * Touch devices: * [Browser + Version list] on [Device name] ### Import / Export Some explanations how to import / export user drawn images. ### Line smoothing Explanations about how to manipulate the line the user draws. This can include: * BΓ©zier curves * Controlling thickness of lines
javascript canvas
Martin Thoma Apr 6 2018-11-14T00: 00Z
source share