Inspired by the one kilobyte of JS Román Cortés used to Monte-Carlo 3D-render a rose, <http://www.romancortes.com/blog/1k-rose/> <http://js1k.com/2012-love/demo/1022>, I thought I'd see if I could squeeze my JS fixed-width font renderer <http://lists.canonical.org/pipermail/kragen-hacks/2012-January/000533.html> down to under 1K. The following HTML is 1023 bytes, and uses Janne Kujala's 4×6 pixel font to render its own source code. I removed the handling of tab characters and the flexibility to use different fonts and canvas sizes (specializing to 4×6 black-background glyphs and a 512×512 canvas), but left in line wrapping and vertical truncation. I think this is more readable than Cortés's JS1K entry, but also a lot less visually impressive.
This version is on the web at <http://canonical.org/~kragen/sw/dofonts-1k.html>. Like everything else posted to kragen-hacks without an explicit notice to the contrary, this is in the public domain. <body bgcolor="black" onload="r()"> <a href="http://canonical.org/~kragen/sw/dofonts.html">cf</a> <img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAEAAAAAkAQMAAAADwq7RAAAAAXNSR0IArs4c6QAAAAZQTFRFAAAA ////pdmf3QAAAQxJREFUGNMtjlFqg0AYhIcQikhJryBFgoiHWGQR2QfJIaQPfegZRCQEkZxBZCny I9sr+LBIkZBDBPFBQs7QNXTgh2Hg+2ewpZh7Ehtsf26S89XYmvHHbgu8ebVJLJPcDlyyGACDhwzg ifpK4VTomjYnnoSY3LuOkLmQ4XvbIGFI7kF84U6Bpyxzqb7Oyi9dELUn6Z8J6rcbp+C8oKS2lFQS PvX1qMTyT63Sw0I0VwzUCiK3qDFqobhZhrIRD1m4QNElQs4BzPyndmCZ4xReD+yHNOptoWG3tHRB QsZ0kfQF4WX4CJW/yJV4Rf8kmfkRHzB8m9KJ16CLIBFEwJgLFa2lx2ovmsmYfMU2Fv4AgeVrl8Qw sFoAAAAASUVORK5CYII= " id="font" /> <canvas width="512" height="512" id="c"></canvas> <script> d = document function r() { t = d.body.innerHTML x = 0 y = 0 for(i in t) { c = t.charCodeAt(i) if(32<=c && c<128) { fi = c-32 d.getElementById('c').getContext('2d') .drawImage(d.images[0],fi%16*4,~~(fi/16)*6,4,6,x,y,4,6) x += 4 } if(x>508 || c===10) { x = 0 y += 6 if(y>=512) break } } } </script> -- To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-hacks