generate tile colors automatically
generate tile colors automatically

file:a/index.html -> file:b/index.html
--- a/index.html
+++ b/index.html
@@ -45,6 +45,12 @@
         <div class="tile tile-4 tile-position-2-3">
           4
         </div>
+        <div class="tile tile-512 tile-position-3-2">
+          512
+        </div>
+        <div class="tile tile-2048 tile-position-4-4">
+          2048
+        </div>
       </div>
     </div>
   </div>

--- a/style/main.css
+++ b/style/main.css
@@ -129,4 +129,31 @@
     position: absolute;
     left: 363.75px;
     top: 363.75px; }
+  .tile.tile-2 {
+    background: #eee4da; }
+  .tile.tile-4 {
+    background: #ede0ca; }
+  .tile.tile-8 {
+    background: #edddba; }
+  .tile.tile-16 {
+    background: #eddaab; }
+  .tile.tile-32 {
+    background: #edd79b; }
+  .tile.tile-64 {
+    background: #edd48b; }
+  .tile.tile-128 {
+    background: #edd17c;
+    font-size: 45px; }
+  .tile.tile-256 {
+    background: #edce6c;
+    font-size: 45px; }
+  .tile.tile-512 {
+    background: #edcb5c;
+    font-size: 45px; }
+  .tile.tile-1024 {
+    background: #edc84d;
+    font-size: 35px; }
+  .tile.tile-2048 {
+    background: #edc53d;
+    font-size: 35px; }
 

--- a/style/main.scss
+++ b/style/main.scss
@@ -1,3 +1,4 @@
+@import "helpers";
 @import "fonts/clear-sans.css";
 
 $field-width: 500px;
@@ -7,6 +8,7 @@
 $tile-border-radius: 3px;
 
 $tile-color: #eee4da;
+$tile-gold-color: #edc22e;
 
 html, body {
   margin: 0;
@@ -104,6 +106,27 @@
       }
     }
   }
+
+  $base: 2;
+  $exponent: 1;
+  $limit: 11;
+
+  @while $exponent <= $limit {
+    $power: pow($base, $exponent);
+    $percent: (($exponent - 1) / $limit) * 100;
+
+    &.tile-#{$power} {
+      background: mix($tile-gold-color, $tile-color, $percent);
+
+      @if $power >= 100 and $power < 1000 {
+        font-size: 45px;
+      } @else if $power >= 1000 {
+        font-size: 35px;
+      }
+    }
+
+    $exponent: $exponent + 1;
+  }
 }
 
 

comments