No al cierre de webs
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

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


Este ShareCode tiene versiones:
  1. Expand factor Randomness Animat... (18/04/2015)
  2. Expand factor Randomness Animat... (18/09/2021)
Enlace
El enlace para compartir es: