Created
October 1, 2016 22:49
-
-
Save vinaydotblog/35c40afe27dc5620ff6cf52b5bd60b35 to your computer and use it in GitHub Desktop.
Flat digits array to image
This file contains 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
<canvas id="can" width="800" height="800"></canvas> | |
<script> | |
var lol = [0.0, 0.0, 0.0, 0.0, 11.0, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 15.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 16.0, 11.0, 0.0, 0.0, 0.0, 0.0, 9.0, 16.0, 16.0, 10.0, 0.0, 0.0, 0.0, 4.0, 16.0, 12.0, 16.0, 12.0, 0.0, 0.0, 0.0, 3.0, 10.0, 3.0, 16.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 16.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 11.0, 0.0, 0.0]; | |
var img = []; | |
while( lol.length ){ img.push( lol.splice(0,8) ) } | |
var can = document.querySelector('#can'); | |
var ctx = can.getContext('2d'); | |
var base = 10; | |
var base2 = 10; | |
img.forEach(function(line, i){ | |
line.forEach(function(dot, j){ | |
if(dot){ | |
ctx.globalAlpha = j / 16; | |
ctx.fillRect(i * base,j * base2, base, base2); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment