Skip to content

Instantly share code, notes, and snippets.

@heavysixer
Last active March 16, 2016 19:30
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 heavysixer/15f816958d3a54e9e798 to your computer and use it in GitHub Desktop.
Save heavysixer/15f816958d3a54e9e798 to your computer and use it in GitHub Desktop.
prototype: d3.geo topojson v1
{"description":"prototype: d3.geo topojson v1","endpoint":"","display":"svg","public":true,"require":[{"name":"topojson v1","url":"http://d3js.org/topojson.v1.min.js"},{"name":"topojson v1","url":"http://d3js.org/topojson.v1.min.js"},{"name":"clipper","url":"https://rawgit.com/Delapouite/JsClipper/blob/master/clipper.js"},{"name":"clipper","url":"https://rawgit.com/Delapouite/JsClipper/master/clipper.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"world110.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"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,"fullscreen":false,"thumbnail":"http://i.imgur.com/OtZ3o1y.png","ajax-caching":true}
var svg = d3.select("svg");
var width = tributary.sw;
var height = tributary.sh;
var center = {
x: width/2,
y: height/2
}
var world = tributary.world110;
var countries = topojson.feature(world, world.objects.land);
var projection = d3.geo.orthographic()
.scale(200)
.rotate([9,0,0])
.translate([width/2, height/2])
.clipAngle(90);
var path = d3.geo.path()
.projection(projection);
svg.append("path")
.attr("d", path(countries))
.classed("land", true);
var bbox = svg.select('.land')[0][0].getBBox();
var roundTo = function (input, sigdigs) {
return Math.round(input * Math.pow(10, sigdigs) ) / Math.pow(10, sigdigs);
}
var makeSpiralPoints = function(origin, revolutions, pointCount, clockwise, padding){
var direction = clockwise ? 1 : -1;
var circ = padding / (2 * Math.PI);
var step = (2 * Math.PI * revolutions) / pointCount;
var points = [], angle, x, y;
for (var i = 0; i <= pointCount ; i++){
angle = direction * step * i;
x = roundTo((circ * angle) * Math.cos(angle) + origin.x, 2);
y = roundTo((circ * angle) * Math.sin(angle) + origin.y, 2);
points.push(x + " " + y);
}
return('M ' + points.shift() + ' S ' + points.join(' '));
}
var spiral = svg.append("path")
.attr("d", makeSpiralPoints({x:center.x,y:center.y},bbox.height/8, 4000, false, 4))
.classed("spiral", true);
console.log(spiral.getTotalLength());
.land {
fill: none;
stroke: #000000;
}
.stroke {
fill: none;
stroke: #ff0000;
}
.spiral {
fill: #ffffff;
stroke: #CC0A48;
fill-opacity: 0.2
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment