Skip to content

Instantly share code, notes, and snippets.

@jasondavies
Forked from mbostock/.block
Created July 9, 2012 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasondavies/3076432 to your computer and use it in GitHub Desktop.
Save jasondavies/3076432 to your computer and use it in GitHub Desktop.
Spinny Globe
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.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
circle,
path {
fill: none;
stroke: #000;
}
circle {
stroke-width: 2px;
}
</style>
<body>
<script src="http://d3js.org/d3.v2.min.js"></script>
<script src="https://raw.github.com/d3/d3-plugins/clip/geo/clip/clip.js"></script>
<script>
var width = 960,
height = 500,
radius = 240;
var origin = [-71, 42],
velocity = [.010, -.002],
t0 = Date.now();
var projection = d3.geo.azimuthal()
.mode("orthographic")
.scale(radius)
.translate([width / 2, height / 2]);
var clip = d3.geo.clip();
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("readme.json", function(err, geometry) {
var feature = svg.append("path")
.datum(geometry)
.attr("d", draw);
d3.timer(function() {
var t = Date.now() - t0,
o = [origin[0] + velocity[0] * t, origin[1] + velocity[1] * t];
projection.origin(o);
clip.origin(o);
feature.attr("d", draw);
});
function draw(d) {
return path(clip(d));
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment