r/tinycode • u/err4nt • May 04 '16
Canvas Napkin Sketch - 611 bytes
Here’s a canvas element you can draw on with mouse or touch input. Just for little quick napkin sketches. Copy/paste into your address bar to load, click or tap to draw. Right click to save as PNG.
data:text/html,<body style=margin:0><canvas id=c><script>var a,x=c.getContext('2d');c.width=innerWidth;c.height=innerHeight;x.lineWidth=3;document.onmousedown=document.ontouchstart=function(e){e.preventDefault();a=true;x.moveTo(e.clientX||e.touches[0].clientX,e.clientY||e.touches[0].clientY);x.beginPath()};document.onmousemove=document.ontouchmove=function(e){if(a){x.lineTo(e.clientX||e.touches[0].clientX,e.clientY||e.touches[0].clientY)}};document.onmouseup=document.ontouchend=function(e){a=false;x.lineTo(e.clientX||e.changedTouches[0].clientX,e.clientY||e.changedTouches[0].clientY);x.stroke()}</script>
16
Upvotes
View all comments
Show parent comment
1
u/err4nt May 04 '16
I've updated it with my own ugly hack version, in this comment
It's super easy to write your own from scratch with the settings you like, easy to make multiple versions like multiple notepads or sketchpads :D