Watch the twig grow into a branch with leaves (jsFiddle)
Similar to Jason Davies' Koch Island
Example 1.2.9 in Jun Kigami's textbook, Analysis on Fractals
The tree is not stored optimally -- slow around 11 and 12 iterations.
Watch the twig grow into a branch with leaves (jsFiddle)
Similar to Jason Davies' Koch Island
Example 1.2.9 in Jun Kigami's textbook, Analysis on Fractals
The tree is not stored optimally -- slow around 11 and 12 iterations.
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
| <title> Hata's Tree-Like Set</title> | |
| <script type='text/javascript' src='http://d3js.org/d3.v3.min.js'></script> | |
| <script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script> | |
| <script type='text/javascript' src="http://d3js.org/d3.v3.min.js"></script> | |
| <style type='text/css'> | |
| body {font-family: Helvetica;} | |
| </style> | |
| <script type='text/javascript'>//<![CDATA[ | |
| // [email protected] | |
| function Controller($scope){ | |
| var leaves = [8]; | |
| for(var i = 0; i < 10; i++){ | |
| leaves.push( 3*leaves[leaves.length - 1] +2); | |
| } | |
| var len = 500; | |
| function L(z){ | |
| return {'x': 0.5*z.x + Math.sqrt(3)/6*z.y, 'y': Math.sqrt(3)/6*z.x - 0.5*z.y}; | |
| } | |
| function R(z){ | |
| return {'x': 2/3*z.x + 0*z.y + len*(1 - 2/3), 'y': 0*z.x - 2/3*z.y - 0 }; | |
| } | |
| var tree = [{'x': 0, 'y':0 },{'x': len, 'y':0 }]; | |
| for(var k = 0; k < 11; k++){ | |
| y = []; | |
| for(var i = 0; i < tree.length; i++){ | |
| y.push(L(tree[i])); | |
| } | |
| y.push(tree[0]); | |
| for(var i = 0; i < tree.length; i++){ | |
| y.push(R(tree[i])); | |
| } | |
| tree.push(tree[0]); | |
| tree = tree.concat(y); | |
| } | |
| var lineFunction = d3.svg.line() | |
| .x(function (d) { return d.x; }) | |
| .y(function (d) { return -1*d.y+150; }) | |
| .interpolate("linear"); | |
| function add(x, fig){ | |
| fig.append("path") | |
| .attr("d", lineFunction(x)) | |
| .attr("stroke-width", 1) | |
| .attr("stroke", "black") | |
| .attr("fill", "none"); | |
| } | |
| $scope.$watch("N",function(){ | |
| d3.select('svg').remove(); | |
| var N = $scope.N; | |
| var figure = d3.select(".tree").append("svg") | |
| .attr("width", len) | |
| .attr("height", len/2); | |
| add(tree.slice(0,leaves[N-1] ), figure); | |
| }); | |
| } | |
| //]]> | |
| </script> | |
| </head> | |
| <body> | |
| <div ng-app ng-init="N=1;" ng-controller="Controller"> | |
| <input type="range" min="1" max="11" step="1" ng-model="N"> | |
| <h2>{{N}}th Iteration</h2> | |
| <div class="tree"></div> | |
| </div> | |
| </body> | |
| </html> |