Created
December 30, 2015 18:27
-
-
Save tonyonodi/5c463894a96865b69f67 to your computer and use it in GitHub Desktop.
Code that outputs its own source to a canvas as grayscale values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(F=(L,d)=>{(C=d.createElement("canvas")).width=C.height=L;X=C.getContext("2d");for(i=L*L;i--;)X.fillStyle=`rgb(${n=`(F=${F})(16,document)`.charCodeAt(i)||32},${n},${n})`,X.fillRect(i%L,0|(i/L),1,1);d.body.appendChild(C)})(16,document) | |
// After running this code you should be able to grab the pixel values as a Uint8ClampedArray | |
// from the canvas context 'X' and use that to verify like so: | |
var charCodes = Array.from(X.getImageData(0,0,16,16).data).filter((_,i)=>i%4===0) | |
String.fromCharCode.apply(null, charCodes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment