A simple implementation of fog of war using voronoi polygons drawn from the underlying data. Mouseover the darkened regions to reveal the data beneath.
Last active
March 16, 2016 15:37
-
-
Save emeeks/fb6c0a5cc8d6646a36d0 to your computer and use it in GitHub Desktop.
Fog of War I
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> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Fog of War with Voronoi</title> | |
<style> | |
</style> | |
</head> | |
<body> | |
<svg width="500" height="500" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js" charset="utf-8" type="text/javascript"></script> | |
<script type="text/javascript"> | |
vertices = [[162, 332], [182, 299], [141, 292], [158, 264], [141, 408], [160, 400], [177, 430], [151, 442], [155, 425], [134, 430], [126, 447], [139, 466], [160, 471], [167, 447], [182, 466], [192, 442], [187, 413], [173, 403], [168, 425], [153, 413], [179, 275], [163, 292], [134, 270], [143, 315], [177, 320], [163, 311], [162, 281], [182, 255], [141, 226], [156, 235], [173, 207], [187, 230], [204, 194], [165, 189], [145, 201], [158, 167], [190, 165], [206, 145], [179, 153], [204, 114], [221, 138], [243, 112], [248, 139], [177, 122], [179, 99], [196, 82], [219, 90], [240, 75], [218, 61], [228, 53], [211, 34], [197, 51], [179, 65], [155, 70], [165, 85], [134, 80], [124, 58], [153, 44], [173, 34], [192, 27], [156, 19], [119, 32], [128, 17], [138, 36], [100, 58], [112, 73], [100, 92], [78, 100], [83, 78], [61, 63], [80, 44], [100, 26], [60, 39], [43, 71], [34, 54], [32, 90], [53, 104], [60, 82], [66, 99], [247, 94], [187, 180], [221, 168]]; | |
voronoi = d3.geom.voronoi() | |
.x(function (d) {return d[0]}) | |
.y(function (d) {return d[1]}) | |
.clipExtent([[0,0],[500,500]]) | |
d3.select("svg").selectAll("circle") | |
.data(vertices) | |
.enter() | |
.append("circle") | |
.attr("cx", function (d) {return d[0]}) | |
.attr("cy", function (d) {return d[1]}) | |
.style("fill", "#001276") | |
.attr("r", 2); | |
d3.select("svg").selectAll("path") | |
.data(voronoi(vertices)) | |
.enter() | |
.append("path") | |
.attr("d", function (d) {return "M" + d.join("L") + "Z"; }) | |
.style("fill", "#001276") | |
.style("stroke", "#001276") | |
.on("mouseover", defog) | |
function defog(d) { | |
d3.select(this) | |
.transition() | |
.duration(1000) | |
.style("opacity", 0) | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment