r/tinycode • • 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

12 comments sorted by

View all comments

Show parent comment

1

u/Jellonator May 04 '16

I really hate to ask, but what the hell is this:

eval(unescape(escape('♶♡♲☠♩☽♤♯♣♵♭♥♮♴☮♣♲♥♡♴♥♅♬♥♭♥♮♴☨☧♣♡♮♶♡♳☧☩☬♣[portion removed for brevity]☰♝☮♡♰♰♥♮♤♃♨♩♬♤☨♭☩☻').replace(/u../g,'')))

It looks like some kind of black magic

2

u/err4nt May 04 '16

Oh no worries! Short answer: it's the icon.

Long answer:

Suppose you wanted to draw and attach a page icon with code instead of using an external image file - you could write some JavaScript that creates a canvas element, draws your graphics, creates the icon links and then uses the image data as the img src="".

Here's an explanation of how to draw the icons with canvas

So why is it all garbled? Well just to get the icon code out of the way. I ran it through a really simple 'encoder' that basically just shifts the character set from normal characters to the character range of those fun happy symbols :) Wouldn't you rather look at those? I used this tool.

So basically when the page loads, that string of symbols gets shifted back to a boring character set, it's really just minified JavaScript instructions on how to draw and attach an icon.