Nuestro conocimiento compartido. Nuestro tesoro compartido. Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

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


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