]> git.scottworley.com Git - nt3d/blobdiff - rmm.html
Use a params object rather than loose arguments
[nt3d] / rmm.html
index dd212e51c0d901032a3aa23e0e1c31e99e331809..8264bd160372a906707b85ad9fbee29caff92140 100644 (file)
--- a/rmm.html
+++ b/rmm.html
@@ -9,43 +9,41 @@
         // https://plus.google.com/101508799331795210529/posts/Yg7LmV8BpTw
         return 3.7*x + (Math.log(1-.95*x)-Math.log(.95*x+1));
       }
-      function rmm(base_separation, base_offset,
-                   width, short_arc_height, tall_arc_height,
-                   tube_width, steps_along, steps_around) {
+      function rmm(params) {
         var tau = Math.PI*2;
         var path = [];
         // Short arc
-        for (var i = 0; i < steps_along; i++) {
-          var progress = i/steps_along;
-          var x_separation =  Math.cos(progress*tau/2)*base_separation;
-          var y_offset     = -Math.sin(progress*tau/4)*base_offset;
-          var y_arc        =  Math.sin(progress*tau)*width;
-          var z_arc        = -Math.cos(progress*tau)*short_arc_height + short_arc_height;
+        for (var i = 0; i < params.steps_along; i++) {
+          var progress = i/params.steps_along;
+          var x_separation =  Math.cos(progress*tau/2)*params.base_separation;
+          var y_offset     = -Math.sin(progress*tau/4)*params.base_offset;
+          var y_arc        =  Math.sin(progress*tau)*params.width;
+          var z_arc        = -Math.cos(progress*tau)*params.short_arc_height + params.short_arc_height;
           path.push([x_separation, y_offset + y_arc, z_arc]);
         }
         // Tall arc
-        for (var i = 0; i < steps_along; i++) {
-          var progress = i/steps_along;
-          var x_arc        = -Math.cos(progress*tau*1.5)*base_separation;
-          var y_offset     = -Math.cos(progress*tau/4)*base_offset;
-          var y_twist      = -pointy_sin(progress*2 - 1)*width/2;
-          var z_arc        = -Math.cos(progress*tau)*tall_arc_height + tall_arc_height;
+        for (var i = 0; i < params.steps_along; i++) {
+          var progress = i/params.steps_along;
+          var x_arc        = -Math.cos(progress*tau*1.5)*params.base_separation;
+          var y_offset     = -Math.cos(progress*tau/4)*params.base_offset;
+          var y_twist      = -pointy_sin(progress*2 - 1)*params.width/2;
+          var z_arc        = -Math.cos(progress*tau)*params.tall_arc_height + params.tall_arc_height;
           path.push([x_arc, y_offset + y_twist, z_arc]);
         }
         return nt3d.closed_extrude(
           path,
-          nt3d.circle(tube_width, steps_around),
+          nt3d.circle(params.tube_width, params.steps_around),
           nt3d.shapenormals_from_closed_path(path),
           nt3d.pathnormals_from_point(path, [0,0,0]));
       }
-      var params = [["Base separation", 30],
-                    ["Base offset", 10],
-                    ["Width", 40],
-                    ["Short arc height", 60],
-                    ["Tall arc height", 80],
-                    ["Tube width", 10],
-                    ["Steps along each arc", 70],
-                    ["Steps around", 12]];
+      var params = [["base_separation", 30],
+                    ["base_offset", 10],
+                    ["width", 40],
+                    ["short_arc_height", 60],
+                    ["tall_arc_height", 80],
+                    ["tube_width", 10],
+                    ["steps_along", 70, "Steps Along Each Arc"],
+                    ["steps_around", 12]];
     </script>
   </head>
   <body onload="nt3d.framework(rmm, params)">