vinnizworld
10/1/2016 - 10:49 PM

Flat digits array to image

Flat digits array to image


<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>