Skip to content

Instantly share code, notes, and snippets.

@georules
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georules/701aebdf05d2cf886e4d to your computer and use it in GitHub Desktop.
Save georules/701aebdf05d2cf886e4d to your computer and use it in GitHub Desktop.
hexes
{"description":"hexes","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}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/cPwGVcR.png","fullscreen":false,"ajax-caching":true,"inline-console":false}
var svg = d3.select("svg")
svg.append("rect")
.attr({
width: 100,
height: 100,
x: 200,
y: 62,
fill: "#3BA360"
});
var Hex = function() {}
Hex.convpoints = function(d) {
return d.map(function(d) {
return [d.x,d.y].join(",");
}).join(" ")
}
Hex.svgData = function(x,y,r) {
return Hex.convpoints(Hex.hexPoints(x,y,r))
}
Hex.hexPoints = function(x,y,r) {
h = Math.sqrt(3)/2
hexagonData = [
{x : r+x, y: y},
{x : r/2+x, y: r*h+y},
{x : -r/2+x, y: r*h+y},
{x : -r+x, y: y},
{x : -r/2+x, y: -r*h+y},
{x : r/2+x, y: -r*h+y}
]
return hexagonData
}
//points = hex(100,100,76)
//newp = convpoints(points)
newp = Hex.svgData(135,204,108)
//newp = ["100,100","70,367","300,300"]
svg.append("polygon").attr({
"points":newp,
"stroke-width":2,
fill: "#ff7f7f",
stroke: "#ef0000"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment