Add color to board depending on values..
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sun, 07 Sep 2014 14:16:26 +0300
changeset 13 b3bfa9d1b537
parent 12 a9a44cfc3e08
child 14 9b49e710f5a7
Add color to board depending on values..
2048.html
--- a/2048.html	Sun Sep 07 03:33:33 2014 +0300
+++ b/2048.html	Sun Sep 07 14:16:26 2014 +0300
@@ -120,7 +120,10 @@
     var ui = {};
     ui.board = {};
     ui.board.set = function(i, j, val) {
-      boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j].innerHTML = val;
+      var dom = boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j];
+      dom.innerHTML = val;
+      var rgb = 'rgb(255,'+ (255-5*val-2*(val%2)) +','+ (255-10*val-5*((val-1)%2)) +')';
+      dom.style.backgroundColor = rgb;
     }
     ui.board.update = function(brd) {
       for (var i = 0; i < 4; i++) {