]> git.scottworley.com Git - nt3d/blobdiff - wrap_sphere.html
Factor out finger()
[nt3d] / wrap_sphere.html
index 13729396abb7e6c496b995afcc21126bedc7d71b..4d51914ce20aabf988a1e8e34a31e7c3a934e414 100644 (file)
@@ -3,28 +3,28 @@
     <title>Wrap Sphere</title>
     <script type="text/javascript" src="nt3d.js"></script>
     <script type="text/javascript">
     <title>Wrap Sphere</title>
     <script type="text/javascript" src="nt3d.js"></script>
     <script type="text/javascript">
-      function wrap_sphere(sphere_radius, extrusion_radius, turns, circle_angle, aspect_ratio, distortion_angle, steps_around, steps_along) {
+      function wrap_sphere(params) {
         // Spiral path along sphere surface
         var path = [];
         // Spiral path along sphere surface
         var path = [];
-        for (var i = 0; i < steps_along; i++) {
-          var progress_0to2 = i / (steps_along/2);
+        for (var i = 0; i < params.steps_along; i++) {
+          var progress_0to2 = i / (params.steps_along/2);
           var progress_0to1andback = progress_0to2 < 1 ? progress_0to2 : 2 - progress_0to2;
           var progress_neg1to1andback = progress_0to1andback * 2 - 1;
           var progress_0to1andback = progress_0to2 < 1 ? progress_0to2 : 2 - progress_0to2;
           var progress_neg1to1andback = progress_0to1andback * 2 - 1;
-          var z = progress_neg1to1andback * sphere_radius;
-          var r = Math.sqrt(sphere_radius*sphere_radius - z*z);
+          var z = progress_neg1to1andback * params.sphere_radius;
+          var r = Math.sqrt(params.sphere_radius*params.sphere_radius - z*z);
           var phase_adjust = progress_0to2 < 1 ? 0 : Math.PI;
           var phase_adjust = progress_0to2 < 1 ? 0 : Math.PI;
-          var x = r*Math.cos(progress_0to1andback*turns*2*Math.PI + phase_adjust);
-          var y = r*Math.sin(progress_0to1andback*turns*2*Math.PI + phase_adjust);
+          var x = r*Math.cos(progress_0to1andback*params.turns*2*Math.PI + phase_adjust);
+          var y = r*Math.sin(progress_0to1andback*params.turns*2*Math.PI + phase_adjust);
           path.push([x,y,z]);
         }
 
         // Shape to be extruded
           path.push([x,y,z]);
         }
 
         // Shape to be extruded
-        var shape = nt3d.circle(extrusion_radius, steps_around);
-        shape = nt3d.rotate_about_origin(shape, [0,0,1], circle_angle*Math.PI*2);
+        var shape = nt3d.circle(params.extrusion_radius, params.steps_around);
+        shape = nt3d.rotate_about_origin(shape, [0,0,1], params.circle_angle*Math.PI*2);
         for (var i = 0; i < shape.length; i++) {
         for (var i = 0; i < shape.length; i++) {
-          shape[i][0] *= aspect_ratio;
+          shape[i][0] *= params.aspect_ratio;
         }
         }
-        shape = nt3d.rotate_about_origin(shape, [0,0,1], distortion_angle*Math.PI*2);
+        shape = nt3d.rotate_about_origin(shape, [0,0,1], params.distortion_angle*Math.PI*2);
 
         return nt3d.closed_extrude(
           path,
 
         return nt3d.closed_extrude(
           path,
           nt3d.shapenormals_from_closed_path(path),
           nt3d.pathnormals_from_point(path, [0, 0, 0]));
       }
           nt3d.shapenormals_from_closed_path(path),
           nt3d.pathnormals_from_point(path, [0, 0, 0]));
       }
-      var params = [["Sphere radius", 100],
-                    ["Extrusion radius", 5],
-                    ["Turns", 3],
-                    ["Angle of circle (in turns) (useful when steps_around is small)", .125],
-                    ["Aspect ratio", 2],
-                    ["Angle of distortion (in turns)", .25],
-                    ["Steps around", 4],
-                    ["Steps along", 500]];
+      var params = [["sphere_radius", 100],
+                    ["extrusion_radius", 5],
+                    ["turns", 3],
+                    ["circle_angle", .125, "Angle of circle (in turns) (useful when steps_around is small)"],
+                    ["aspect_ratio", 2],
+                    ["distortion_angle", .25, "Distortion Angle (in turns)"],
+                    ["steps_around", 4],
+                    ["steps_along", 500]];
     </script>
   </head>
   <body onload="nt3d.framework(wrap_sphere, params)">
     </script>
   </head>
   <body onload="nt3d.framework(wrap_sphere, params)">