Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created January 29, 2013 23:48
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 enjalot/4669132 to your computer and use it in GitHub Desktop.
Save enjalot/4669132 to your computer and use it in GitHub Desktop.
heightmap
{"description":"heightmap","endpoint":"","display":"canvas","public":true,"require":[],"fileconfigs":{"inlet.js":{"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}},"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}
//http://bl.ocks.org/3289530
//grr crossdomain taining...
var color = d3.scale.linear()
.domain([15, 35, 132])
.range(["#d7191c", "#ffffbf", "#2c7bb6"])
.interpolate(d3.interpolateHcl);
var width = tributary.sw
var height = tributary.sh;
function render() {
var context = tributary.ctx;
context.drawImage(tributary.image, 0, 0, width, height);
image = context.getImageData(0, 0, width, height);
// Rescale the colors.
for (var c, i = 0, n = width * height * 4, d = image.data; i < n; i += 4) {
c = d3.rgb(color(d[i]));
d[i + 0] = c.r;
d[i + 1] = c.g;
d[i + 2] = c.b;
}
context.putImageData(image, 0, 0);
console.log("hi");
}
function getImage(path, callback) {
console.log("?");
var image = new Image;
//image.crossOrigin = "anonymous";
image.onload = function() { callback(image); };
image.src = path;
console.log(image);
}
if(!tributary.image) {
//var url = "http://bl.ocks.org/d/3289530/readme.png";
var url = "https://gist.github.com/raw/3289530/8a340942a9008d58ee8aaaa55f6a31dc6f63c7a7/readme.png";
getImage(url, function(image){
/*
var img = new Image;
for (var c, i = 0, n = width * height * 4, d = image.data; i < n; i += 4) {
img.data[i + 0] = c.r;
img.data[i + 1] = c.r;
img.data[i + 2] = c.r;
}
*/
tributary.image = image;
console.log("YAY");
render();
})
} else {
render();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment