Skip to content

Instantly share code, notes, and snippets.

@sugendran
Last active December 17, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sugendran/5641228 to your computer and use it in GitHub Desktop.
Save sugendran/5641228 to your computer and use it in GitHub Desktop.
(function (text) {
var canvas = document.createElement("canvas");
canvas.width = 600;
canvas.height = 100;
var ctx = canvas.getContext("2d");
ctx.font = "28px monospace";
ctx.textBaseline = "top";
ctx.textAlign = "start";
var w = Math.ceil(ctx.measureText(text).width) + 2;
var h = 45;
ctx.fillText(text, 1, 0);
var img = ctx.getImageData(0, 0, w, h);
var key = " x%#";
var lines = [];
for (var y = 0; y < h; y++) {
var row = [];
var empty = true;
for (var x = 3, xx=w*4; x < xx; x+=4) {
var indx = img.data[y * xx + x] >> 6;
if(indx > 0) {
empty = false;
}
row.push(key[indx]);
}
if(!empty) {
lines.push(row.join(""));
}
}
console.log(lines.join("\n"));
})("sugendran");
(function(a){var b=document.createElement("canvas");b.width=600,b.height=100;var c=b.getContext("2d");c.font="28px monospace",c.textBaseline="top",c.textAlign="start";var d=Math.ceil(c.measureText(a).width)+2,e=45;c.fillText(a,1,0);for(var f=c.getImageData(0,0,d,e),g=" x%#",h=[],i=0;e>i;i++){for(var j=[],k=!0,l=3,m=4*d;m>l;l+=4){var n=f.data[i*m+l]>>6;n>0&&(k=!1),j.push(g[n])}k||h.push(j.join(""))}console.log(h.join("\n"))})("sugendran");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment