Browse Source

continuing research in fortune's

Brandon Wong 7 years ago
parent
commit
a0b47731f7
1 changed files with 18 additions and 8 deletions
  1. 18 8
      voronoi.js

+ 18 - 8
voronoi.js

@@ -60,7 +60,7 @@ function generateSites(n = 10) {
     }
 
     sites.sort(function (a, b) {
-        return distance(origin, a) - distance(origin, b);
+        return a.y - b.y;
     });
 
     return sites;
@@ -200,7 +200,7 @@ function parabola(focus, directrixY) {
         end = {x: (focus.x + a), y: 0};
 
     ctx.save();
-    ctx.lineWidth = 3;
+    ctx.lineWidth = 1;
     ctx.strokeStyle = '#aaa';
     ctx.beginPath();
     ctx.moveTo(start.x, start.y);
@@ -212,16 +212,26 @@ function parabola(focus, directrixY) {
 
 function demo(dirY) {
     ctx.clearRect(0,0,canvwidth,canvheight);
-    drawSite(250, 200, 'red');
-    drawSite(450, 100, 'blue');
-    parabola({x:250, y:200}, dirY);
-    parabola({x:450, y:100}, dirY);
+    sites.forEach(function parabolas(site) {
+        if( site.y < dirY ) {
+            parabola(site, dirY);
+        }
+    })
+    sites.forEach(function renderSites(site) {
+        drawSite(site.x, site.y);
+    });
     drawLine(0,dirY,canvwidth,dirY);
-    if( dirY < canvheight + 500 ) {
+    if( dirY < canvheight + 1000 ) {
         setTimeout(demo, 10, dirY + 1)
     }
+    else {
+        console.log('done!');
+    }
 }
-demo(200);
+demo(0);
 
+//TODO
+// http://hotmath.com/hotmath_help/topics/finding-the-equation-of-a-parabola-given-focus-and-directrix.html
+// http://www.ams.org/samplings/feature-column/fcarc-voronoi