1 var h = [2 [0,1,0,1,0],3 [1,1,1,1,1],4 [0,1,0,1,0],5 [1,1,1,1,1],6 [0,1,0,1,0],7 ];8 9 function clone(data) {10 return JSON.parse(JSON.stringify(data));11 };12 13 function colorize(bitmap, randomness) {14 var max_value = bitmap.length*bitmap.length;15 16 for (var y in bitmap) {17 var row = bitmap[y];18 for (var x in row) {19 var value = row[x];20 if (value != 0) {21 var rx = 1+parseInt(x) - randomness + Math.floor(Math.random()*randomness*2);22 var ry = 1+parseInt(y) - randomness + Math.floor(Math.random()*randomness*2);23 bitmap[x][y] = 1 - rx*ry/max_value;24 }25 }26 }27 28 return bitmap;29 }30 31 function expand(bitmap, n) {32 result = [];33 for (var y in bitmap) {34 var new_row = [];35 var row = bitmap[y];36 for (var x in row) {37 var value = row[x];38 for (var i=0; i<n; i++) {39 new_row.push(value);40 }41 }42 for (var i=0; i<n; i++) {43 result.push(clone(new_row));44 }45 }46 return result;47 }48 49 function paint_bitmap(bitmap) {50 var result = '<div class="bitmap">';51 52 for (var y in bitmap) {53 result += '<div class="row">';54 var row = bitmap[y];55 for (var x in row) {56 var value = row[x];57 if (value != 0) {58 result += '<div class="cell" style="background-color: rgba(120, 150, 240,'+value+'")></div>';59 } else {60 result += '<div class="cell"></div>';61 }62 }63 result += '</div>';64 }65 66 result += '</div>';67 return result;68 }69 70
Enlace
El enlace para compartir es: