]> git.scottworley.com Git - nt3d/commitdiff
Factor out finger()
authorScott Worley <scottworley@scottworley.com>
Fri, 23 May 2014 06:35:44 +0000 (23:35 -0700)
committerScott Worley <scottworley@scottworley.com>
Fri, 23 May 2014 06:35:44 +0000 (23:35 -0700)
medusa.html

index 69ea3ba39594dfb892b94b6816356b9d873f1d09..17181cce5113e57c986faabe7520718d256954f0 100644 (file)
@@ -3,6 +3,16 @@
     <title>Medusa</title>
     <script type="text/javascript" src="nt3d.js"></script>
     <script type="text/javascript">
     <title>Medusa</title>
     <script type="text/javascript" src="nt3d.js"></script>
     <script type="text/javascript">
+      function finger(params, finger_crosssection, ring_radius, finger_angle) {
+        var path = [];
+        for (var finger_point = 0; finger_point <= params.finger_points; finger_point++) {
+          var angle = (finger_angle + params.finger_twirl * finger_point / params.finger_points) * 2 * Math.PI;
+          var x = ring_radius * Math.cos(angle);
+          var y = ring_radius * Math.sin(angle);
+          path.push([x, y, params.finger_height * finger_point / params.finger_points]);
+        }
+        return nt3d.extrude(path, finger_crosssection, [0, 0, 1], nt3d.pathnormals_from_point(path, [0, 0, 0]));
+      }
       function medusa(params) {
         var finger_crosssection = nt3d.circle(params.finger_radius, params.finger_faces);
         var fingers = [];
       function medusa(params) {
         var finger_crosssection = nt3d.circle(params.finger_radius, params.finger_faces);
         var fingers = [];
           var ring_radius = params.first_ring_radius + ring_num * params.ring_spacing;
           for (var finger_num = 0; finger_num < params.num_fingers; finger_num++) {
             var finger_angle = finger_num / params.num_fingers;
           var ring_radius = params.first_ring_radius + ring_num * params.ring_spacing;
           for (var finger_num = 0; finger_num < params.num_fingers; finger_num++) {
             var finger_angle = finger_num / params.num_fingers;
-            var path = [];
-            for (var finger_point = 0; finger_point <= params.finger_points; finger_point++) {
-              var angle = (finger_angle + params.finger_twirl * finger_point / params.finger_points) * 2 * Math.PI;
-              var x = ring_radius * Math.cos(angle);
-              var y = ring_radius * Math.sin(angle);
-              path.push([x, y, params.finger_height * finger_point / params.finger_points]);
-            }
-            var finger = nt3d.extrude(path, finger_crosssection, [0, 0, 1], nt3d.pathnormals_from_point(path, [0, 0, 0]));
-            fingers = fingers.concat(finger);
+            fingers = fingers.concat(finger(params, finger_crosssection, ring_radius, finger_angle));
           }
         }
 
           }
         }