[ Launch: Hexagon Construction ] 6957065 by munaf
-
-
Save munaf-zz/6957065 to your computer and use it in GitHub Desktop.
Hexagon Construction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"Hexagon Construction","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/dr7BNup.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg = d3.select('svg'); | |
var x = 269, | |
y = 186, | |
r = 120; | |
var radii = [ | |
{x: x, y: y}, | |
{x: x + r, y: y}, | |
{x: x + 2*r, y: y}, | |
{x: x + r/2, y: y + Math.sqrt((r*r)-(r/2)*(r/2))}, | |
{x: x + 3*r/2, y: y + Math.sqrt((r*r)-(r/2)*(r/2))} | |
]; | |
var guideCircles = svg.selectAll('circle').data(radii); | |
guideCircles.enter() | |
.append('circle') | |
.attr({ | |
cx: function(d) { return d.x }, | |
cy: function(d) { return d.y }, | |
r: r, | |
fill: 'rgba(255,255,255,0.1)', | |
stroke: '#888888', | |
'stroke-width': 1 | |
}); | |
// Draw the connecting lines | |
var lineColor = '#15C981', | |
lineWidth = 3; | |
var points = [ | |
{x: x, y: y}, | |
{x: x+r/2, y: y - Math.sqrt((r*r)-(r/2)*(r/2))}, | |
{x: x+3*r/2, y: y - Math.sqrt((r*r)-(r/2)*(r/2))}, | |
{x: x+2*r, y: y}, | |
{x: x+3*r/2, y: y + Math.sqrt((r*r)-(r/2)*(r/2))}, | |
{x: x+r/2, y: y + Math.sqrt((r*r)-(r/2)*(r/2))}, | |
{x: x, y: y} | |
]; | |
var lineFunction = d3.svg.line() | |
.x(function(d) { return d.x; }) | |
.y(function(d) { return d.y; }); | |
svg.append('path') | |
.attr({ | |
'd': lineFunction(points), | |
'fill': 'none', | |
'stroke': lineColor, | |
'stroke-width': '4' | |
}); | |
var dots = svg.selectAll('circle.points').data(points); | |
dots.enter().append('circle').classed('points', true) | |
.attr({ | |
cx: function(d) { return d.x; }, | |
cy: function(d) { return d.y; }, | |
r: 5, | |
fill: 'none', | |
'stroke': '#000000', | |
'stroke-width': 2 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment