]> git.scottworley.com Git - nt3d/blobdiff - medusa.html
Name finger_point / params.finger_points
[nt3d] / medusa.html
index 58319c006613cbe07b7ae80a088030499de7b65a..0576312144c3a38931b80f89f473e9a943138b7d 100644 (file)
@@ -3,31 +3,43 @@
     <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 medusa(base_ring_radius, num_fingers, finger_radius, finger_faces, finger_points, finger_twirl, finger_height) {
-        var finger_crosssection = nt3d.circle(finger_radius, finger_faces);
+      function finger(params, finger_crosssection, ring_num, ring_radius, finger_angle) {
+        var path = [];
+        var twirl_amplitute = Math.cos((ring_num * 2 * Math.PI) / params.finger_twirl_period);
+        var twirl_angle = twirl_amplitute * params.finger_twirl_distance / (ring_radius * 2 * Math.PI);
+        for (var finger_point = 0; finger_point <= params.finger_points; finger_point++) {
+          var finger_progress = finger_point / params.finger_points;
+          var angle = (finger_angle + twirl_angle * finger_progress) * 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_progress]);
+        }
+        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 = [];
         var fingers = [];
-        for (var i = 0; i < num_fingers; i++) {
-          var finger_angle = i / num_fingers;
-          var path = [];
-          for (var j = 0; j <= finger_points; j++) {
-            var angle = (finger_angle + finger_twirl * j / finger_points) * 2 * Math.PI;
-            var x = base_ring_radius * Math.cos(angle);
-            var y = base_ring_radius * Math.sin(angle);
-            path.push([x, y, finger_height * j / finger_points]);
+        for (var ring_num = 0; ring_num < params.num_rings; ring_num++) {
+          var ring_radius = params.first_ring_radius + ring_num * params.ring_spacing;
+          var num_fingers = Math.round((ring_radius * 2 * Math.PI) / params.finger_spacing);
+          for (var finger_num = 0; finger_num < num_fingers; finger_num++) {
+            var finger_angle = finger_num / num_fingers;
+            fingers = fingers.concat(finger(params, finger_crosssection, ring_num, ring_radius, finger_angle));
           }
           }
-          var finger = nt3d.extrude(path, finger_crosssection, [0, 0, 1], nt3d.pathnormals_from_point(path, [0, 0, 0]));
-          fingers = fingers.concat(finger);
         }
 
         return fingers;
       }
         }
 
         return fingers;
       }
-      var params = [["Base ring radius", 100],
-                    ["Number of fingers", 5],
-                    ["Finger radius", 3],
-                    ["Finger faces", 10],
-                    ["Finger points", 20],
-                    ["Finger twirl (in turns)", .1],
-                    ["Finger height", 100]];
+      var params = [["first_ring_radius", 20],
+                    ["num_rings", 4],
+                    ["ring_spacing", 10, "Space Between Rings"],
+                    ["finger_spacing", 10],
+                    ["finger_radius", 3],
+                    ["finger_faces", 3],
+                    ["finger_points", 20],
+                    ["finger_twirl_distance", 50],
+                    ["finger_twirl_period", 2, "Finger Twirl Period (1=same, 2=alternating)"],
+                    ["finger_height", 100]];
     </script>
   </head>
   <body onload="nt3d.framework(medusa, params)">
     </script>
   </head>
   <body onload="nt3d.framework(medusa, params)">