Argh, this is sucky
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 11 Dec 2008 21:28:25 -0500
changeset 1 67d051d75975
parent 0 75edc5057178
child 2 0830e9aac98b
push id1
push userbsmedberg@mozilla.com
push date2008-12-12 21:25 +0000
Argh, this is sucky
wordle.html
--- a/wordle.html
+++ b/wordle.html
@@ -190,16 +190,34 @@
     if (xval + width / 2 > kWidth / 2)
       for (; xval < kWidth - width; ++xval)
         yield xval;
     else
       for (; xval >= 0; --xval)
         yield xval;
   }
 
+  function yOutbound(yval, height) {
+    if (yval + height / 2 > kHeight / 2)
+      for (; yval >= 0; --yval)
+        yield yval;
+    else
+      for (; yval < kHeight - height; ++yval)
+        yield yval;
+  }
+
+  function yInbound(yval, height) {
+    if (yval + height / 2 > kHeight / 2)
+      for (; yval < kHeight - height; ++yval)
+        yield yval;
+    else
+      for (; yval >= 0; --yval)
+        yield yval;
+  }
+
   function draw()
   {
     let words = getWordList();
 
     let cx = $('cc').getContext('2d');
     cx.clearRect(0, 0, kWidth, kHeight);
 
     cx.textBaseline = 'top';
@@ -287,30 +305,33 @@
               for (x in xInbound(x, twidth)) {
                 if (hitTest(x, y, twidth, size)) {
                   ok = true;
                   break;
                 }
               }
             }
           }
+          if (!ok)
+            vertical = !vertical;
         }
         if (!ok) {
-          alert("Failed to place word: " + word);
+          // alert("Failed to place word: " + word);
           continue;
         }
       }
 
       if (vertical) {
         cx.textAlign = 'right';
-        cx.restore();
+        cx.save();
         cx.translate(x, y);
         cx.rotate(270 * Math.PI / 180);
         cx.fillText(word, x, y);
         cx.restore();
+      }
       else {
         cx.textAlign = 'left';
         cx.fillText(word, x, y);
       }
      
       if (size > 30) {
         curdata = cx.getImageData(0, 0, kWidth, kHeight).data;
       }