Skip to content

Instantly share code, notes, and snippets.

@grahampullan
Last active January 10, 2018 22:17
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 grahampullan/0e751f3c2f11f3befd94d2690cce6ab7 to your computer and use it in GitHub Desktop.
Save grahampullan/0e751f3c2f11f3befd94d2690cce6ab7 to your computer and use it in GitHub Desktop.
dbslice.threeSurf3d
license: mit

A minimal dbslice.threeSurf3d plot example.

The github repository for dbslice is here.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<div id = "target" style = "width:500px"> </div>
<script src="https://threejs.org/build/three.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="http://dbslice.org/dbslice.js"></script>
<script>
var n = 50;
var m = 50;
var xgrid = new Array(n * m);
var ygrid = new Array(n * m);
var zgrid = new Array(n * m);
var vgrid = new Array(n * m);
// Populate plot data
for (var j = 0., k = 0; j < m; ++j) {
for (var i = 0.; i < n; ++i, ++k) {
xgrid[ k ] = i/n;
ygrid[ k ] = j/m;
var h = 0.125 * Math.cos( i/n * 2 * Math.PI) * (1 - Math.cos( j/m * 2 * Math.PI) );
zgrid[ k ] = h;
vgrid[ k ] = h;
}
}
var data = { surfaces: [ { x : xgrid, y : ygrid, z : zgrid, v : vgrid, size : [m,n] } ] };
var layout = { height : 500 };
dbslice.threeSurf3d.make( document.getElementById("target"), dbslice.threeMeshFromStruct( data ), layout );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment