changeset 7:35975411a2a1

splines: implement a default_s for new nodes
author Jordi Gutiérrez Hermoso <jordi@ecometrica.com>
date Sun, 26 Aug 2018 10:55:48 -0400
parents d3a25d39a6e2
children 21bff3258a62
files index.html splines.html splines.js
diffstat 2 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
rename from splines.html
rename to index.html
--- a/splines.js
+++ b/splines.js
@@ -8,6 +8,8 @@
 // How many points to plot between nodes
 var tstep = 20;
 
+var default_s = 1;
+
 var dragged = null,
     selected = nodes[0];
 
@@ -128,8 +130,8 @@
 
 function mousedown() {
     var newcirc = d3.mouse(svg.node());
-    newcirc.push(1);
-    slider.value(1);
+    newcirc.push(default_s);
+    slider.value(default_s);
     nodes.push(selected = dragged = newcirc);
     redraw();
 }
@@ -294,24 +296,27 @@
     return at_t;
 }
 
-function approximate_all() {
+function set_all_s() {
     for(var i = 0; i < nodes.length; i++) {
-        nodes[i][2] = 1;
+        nodes[i][2] = default_s;
     }
+}
+
+function approximate_all() {
+    default_s = 1;
+    set_all_s();
     redraw();
 }
 
 function sharply_interpolate_all() {
-    for(var i = 0; i < nodes.length; i++) {
-        nodes[i][2] = 0;
-    }
+    default_s = 0;
+    set_all_s();
     redraw();
 }
 
 function interpolate_all() {
-    for(var i = 0; i < nodes.length; i++) {
-        nodes[i][2] = -1;
-    }
+    default_s = -1;
+    set_all_s();
     redraw();
 }