// Generated by CoffeeScript 1.10.0 (function() { var GOSPER_ANGLE; GOSPER_ANGLE = Math.acos(5 * Math.sqrt(7) / 14) / Math.PI * 180; window.hept_tree_utils = { /* Rotates a point around the origin */ rotate_point: function(point, theta) { var new_point; theta = theta * Math.PI / 180; return new_point = { x: point.x * Math.cos(theta) - point.y * Math.sin(theta), y: point.x * Math.sin(theta) + point.y * Math.cos(theta) }; }, /* Returns the coordinates of a hexagon */ get_hept_coords: function(scale, index) { var a, coords, r; a = scale / Math.sqrt(7); r = a / Math.sin(Math.PI / 3); coords = [ { x: -a, y: r + r / 2 }, { x: a, y: r + r / 2 }, { x: 0, y: 0 }, { x: -2 * a, y: 0 }, { x: -a, y: -r - r / 2 }, { x: a, y: -r - r / 2 }, { x: 2 * a, y: 0 } ]; return coords[index]; }, /* Returns the rotation, translation and scale of a certain hexagon described as a base 7 number */ get_hex_data: function(indexes) { var hept_coords, i, index, j, len, rotation, scale, scale_i, translation; rotation = GOSPER_ANGLE * indexes.length; translation = { x: 0, y: 0 }; scale = 1 / Math.pow(Math.sqrt(7), indexes.length); for (i = j = 0, len = indexes.length; j < len; i = ++j) { index = indexes[i]; scale_i = 1 / Math.pow(Math.sqrt(7), i); hept_coords = hept_tree_utils.get_hept_coords(scale_i, index); hept_coords = hept_tree_utils.rotate_point(hept_coords, GOSPER_ANGLE * (i + 1)); translation.x += hept_coords.x; translation.y += hept_coords.y; } return { rotation: rotation, translation: translation, scale: scale }; }, /* Generates a haxagons using SVG path */ hex_generate_svg_path: function(a, theta) { var r; r = a / Math.sin(Math.PI / 3); return "M" + a + " " + (r / 2) + " L0 " + r + " L" + (-a) + " " + (r / 2) + " L" + (-a) + " " + (-r / 2) + " L0 " + (-r) + " L" + a + " " + (-r / 2) + " Z"; } }; }).call(this);