|
@@ -60,7 +60,7 @@ function generateSites(n = 10) {
|
|
}
|
|
}
|
|
|
|
|
|
sites.sort(function (a, b) {
|
|
sites.sort(function (a, b) {
|
|
- return distance(origin, a) - distance(origin, b);
|
|
|
|
|
|
+ return a.y - b.y;
|
|
});
|
|
});
|
|
|
|
|
|
return sites;
|
|
return sites;
|
|
@@ -200,7 +200,7 @@ function parabola(focus, directrixY) {
|
|
end = {x: (focus.x + a), y: 0};
|
|
end = {x: (focus.x + a), y: 0};
|
|
|
|
|
|
ctx.save();
|
|
ctx.save();
|
|
- ctx.lineWidth = 3;
|
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
ctx.strokeStyle = '#aaa';
|
|
ctx.strokeStyle = '#aaa';
|
|
ctx.beginPath();
|
|
ctx.beginPath();
|
|
ctx.moveTo(start.x, start.y);
|
|
ctx.moveTo(start.x, start.y);
|
|
@@ -212,16 +212,26 @@ function parabola(focus, directrixY) {
|
|
|
|
|
|
function demo(dirY) {
|
|
function demo(dirY) {
|
|
ctx.clearRect(0,0,canvwidth,canvheight);
|
|
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);
|
|
drawLine(0,dirY,canvwidth,dirY);
|
|
- if( dirY < canvheight + 500 ) {
|
|
|
|
|
|
+ if( dirY < canvheight + 1000 ) {
|
|
setTimeout(demo, 10, dirY + 1)
|
|
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
|
|
|
|
|
|
|
|
|