Skip to content

Instantly share code, notes, and snippets.

@jasondavies
Forked from jasondavies/README.md
Created September 21, 2012 21:59
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 jasondavies/3764187 to your computer and use it in GitHub Desktop.
Save jasondavies/3764187 to your computer and use it in GitHub Desktop.
Peirce Quincuncial Projection
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.
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>
body {
padding: 51px 281px;
}
.background {
fill: #a4bac7;
}
.foreground {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.graticule {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.graticule:nth-child(2n) {
stroke-dasharray: 2,2;
}
.land {
fill: #d7c7ad;
stroke: #766951;
}
.boundary {
fill: none;
stroke: #a5967e;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://raw.github.com/d3/d3-plugins/master/geo/projection/projection.js"></script>
<script>
var width = 397,
height = 397,
π = Math.PI;
var front = [90, 0],
back = [270, 0];
function sgn(x) {
return x > 0 ? 1 : x < 0 ? -1 : 0;
}
var guyou = d3.geo.guyou().translate([0, 0]).scale(1);
var projection = d3.geo.projection(function(λ, φ) {
var t = Math.abs(λ) < π / 2,
coordinates = guyou([(t ? λ : -sgn(λ) * (π - Math.abs(λ))) * 180 / π, φ * 180 / π]),
x = coordinates[0] / Math.SQRT2 - coordinates[1] / Math.SQRT2,
y = coordinates[1] / Math.SQRT2 + coordinates[0] / Math.SQRT2;
if (t) return [x, y];
var d = 2 * 1.311028777082283, // TODO unobfuscate
s = (x > 0) ^ (y > 0) ? -1 : 1;
return [s * x - sgn(y) * d, s * y - sgn(x) * d];
})
.scale(75)
.rotate([0, -90, 45])
.translate([width / 2 - .5, height / 2 - .5])
.clipAngle(180 - 1e-6);
var path = d3.geo.path()
.projection(projection);
var center = projection([0, 90]),
w = Math.abs(projection([90, 0])[0] - projection([-90, 0])[0]);
center[0] -= w / 2;
center[1] -= w / 2;
var graticule = d3.geo.graticule()
.step([15, 15]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(1.5,1.5)");
svg.append("rect")
.attr("class", "background")
.attr("x", center[0])
.attr("y", center[1])
.attr("width", w)
.attr("height", w);
svg.selectAll(".graticule")
.data(graticule.lines)
.enter().append("path")
.attr("class", "graticule")
.attr("d", path);
svg.append("rect")
.attr("class", "foreground")
.attr("x", center[0])
.attr("y", center[1])
.attr("width", w)
.attr("height", w);
d3.json("readme-boundaries.json", function(err, collection) {
svg.insert("g", ".graticule")
.attr("class", "boundary")
.selectAll("path")
.data(collection.geometries)
.enter().append("path")
.attr("d", path);
});
d3.json("readme-land.json", function(err, collection) {
svg.insert("g", ".graticule,.boundary")
.attr("class", "land")
.selectAll("path")
.data(collection.geometries)
.enter().append("path")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment