// Generated by CoffeeScript 1.10.0 (function() { var GOSPER_ANGLE, INITIAL_A, draw_hexes, get_coordinates, height, rotate_point, svg, vis, width; width = 960; height = 500; INITIAL_A = height / 2.4; GOSPER_ANGLE = Math.acos(5 * Math.sqrt(7) / 14) / Math.PI * 180; svg = d3.select('svg').attr({ width: width, height: height, viewBox: (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); vis = svg.append('g'); 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) }; }; get_coordinates = function(a, index) { var coordinates_0, r; r = a / Math.sin(Math.PI / 3); return coordinates_0 = [ { 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 } ]; }; draw_hexes = function(index, order, max_order) { var a, coordinates, g, i, j, k, len, point, ref, results, rotate, transform; transform = ""; for (i = j = ref = index.length - 1; ref <= 0 ? j <= 0 : j >= 0; i = ref <= 0 ? ++j : --j) { a = INITIAL_A / Math.pow(Math.sqrt(7), order - i); coordinates = get_coordinates(a, index[i]); rotate = i === index.length - 1 ? "" : "rotate(" + GOSPER_ANGLE + ")"; transform += rotate + ("translate(" + coordinates[index[i]].x + ", " + coordinates[index[i]].y + ")"); } g = vis.append('g'); g.append('path').attr({ "class": 'hex hex_' + order, d: hept_tree_utils.hex_generate_svg_path(a), transform: transform }); results = []; while (order < max_order && order < index.length) { for (i = k = 0, len = coordinates.length; k < len; i = ++k) { point = coordinates[i]; draw_hexes([i].concat(index), order + 1, max_order); } results.push(order += 1); } return results; }; draw_hexes([2], 0, Math.random() * 4); }).call(this);