The NASA Blue Marble is reprojected using a Florida-centric azimuthal projection. Based on View of the World from 9th Avenue
-
-
Save ryaninvents/36e309b929aba31f8f82e776add5fde0 to your computer and use it in GitHub Desktop.
View of the World from Florida
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
license: gpl-3.0 |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
background: #222; | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script> | |
<script> | |
function azimuthalRaw(scale) { | |
return function(x, y) { | |
var cx = Math.cos(x), | |
cy = Math.cos(y), | |
k = scale(cx * cy); | |
return [ | |
k * cy * Math.sin(x), | |
k * Math.sin(y) | |
]; | |
} | |
} | |
function azimuthalInvert(angle) { | |
return function(x, y) { | |
var z = Math.sqrt(x * x + y * y), | |
c = angle(z), | |
sc = Math.sin(c), | |
cc = Math.cos(c); | |
return [ | |
Math.atan2(x * sc, z * cc), | |
Math.asin(z && y * sc / z) | |
]; | |
} | |
} | |
const POWER = 3; | |
const POSITION = [30.4300065,-84.2842401]; | |
var azimuthalExpmtlRaw = azimuthalRaw(function(z) { | |
const c = Math.acos(z); | |
if (!c) return c; | |
return Math.pow(c, 1 / POWER) / Math.sin(c); | |
}); | |
azimuthalExpmtlRaw.invert = azimuthalInvert(function(z) { | |
return Math.pow(z, POWER); | |
}); | |
function azimuthalExperimental() { | |
return d3.geo.projection(azimuthalExpmtlRaw) | |
.scale(124.75) | |
.clipAngle(180 - 1e-3); | |
} | |
var width = 960, | |
height = 960; | |
var projection = azimuthalExperimental() | |
.scale(350) | |
.translate([width / 2, height / 2]) | |
.rotate([-POSITION[1], -POSITION[0]]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var canvas = d3.select("body").append("canvas") | |
.attr("width", width) | |
.attr("height", height); | |
var context = canvas.node().getContext("2d"); | |
var image = new Image; | |
image.onload = onload; | |
image.src = "readme-blue-marble.jpg"; | |
function onload() { | |
var dx = image.width, | |
dy = image.height; | |
canvas.attr('width', dx).attr('height', dy); | |
context.drawImage(image, 0, 0, dx, dy); | |
var sourceData = context.getImageData(0, 0, dx, dy).data, | |
target = context.createImageData(width, height), | |
targetData = target.data; | |
for (var y = 0, i = -1; y < height; ++y) { | |
for (var x = 0; x < width; ++x) { | |
var p = projection.invert([x, y]), λ = p[0], φ = p[1]; | |
if (λ > 180 || λ < -180 || φ > 90 || φ < -90) { i += 4; continue; } | |
var q = ((90 - φ) / 180 * dy | 0) * dx + ((180 + λ) / 360 * dx | 0) << 2; | |
targetData[++i] = sourceData[q]; | |
targetData[++i] = sourceData[++q]; | |
targetData[++i] = sourceData[++q]; | |
targetData[++i] = 255; | |
} | |
} | |
canvas | |
.attr("width", width) | |
.attr("height", height); | |
context.clearRect(0, 0, width, height); | |
context.putImageData(target, 0, 0); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment