var xAngle = 0.5, yAngle = 2.5;
var nx = 16, ny = 16;

function drawPlasma() {
  var xa = xAngle;
  var ya = yAngle;

  for (var y = 0; y < ny; y++) {
    var xaa = xa;
    for (var x = 0; x < nx; x++) {
      var e = document.getElementById("plasma-" + x + "-" + y);
      var xx = 192 + -16 * x + Math.sin(xaa) * 192;
      var yy = 192 + -16 * y + Math.sin(ya) * 192;
      e.style.backgroundPosition = xx + "px " + yy + "px";
      xaa += 0.033;
    }
    xa += 0.032;
    ya += 0.053;
  }
  xAngle += 0.027;
  yAngle += 0.039;
}

function initializePlasma() {
  document.write('<style type="text/css">');
  document.write('div.plasma {');
  document.write('position: absolute;');
  document.write('left: 1px;');
  document.write('top: 1px;');
  document.write('width: 16px;');
  document.write('height: 16px;');
  document.write('background-image: url("img/plasma.jpg");');
  document.write('z-index: 3;');
  document.write('}');
  document.write('</style>');
  for (var y = 0; y < ny; y++) {
    for (var x = 0; x < nx; x++) {
      document.write("<div id=\"plasma-" + x + "-" + y +"\" class=\"plasma\"></div>");
      var e = document.getElementById("plasma-" + x + "-" + y);
      e.style.left = (1 + 16 * x) + "px";
      e.style.top = (1 + 16 * y) + "px";
    }
  }
}

randomInitializeFunctions.push(initializePlasma);
randomDrawFunctions.push(drawPlasma);
