A simple representation of the Hilbert curve, using d3-hilbert layout. Use the slider to modify the curve order (number of iterations). On mouse hover, XY coordinates are reversely converted to curve distance. Zoom/pan the canvas using mouse-wheel/drag events.
See also Morton (Z-order) curve.
xxxxxxxxxx
<head>
<script src="//code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.2.6/d3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.1.3/bootstrap-slider.min.js"></script>
<script src="//unpkg.com/d3-hilbert"></script>
<script src="hilbert-demo.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.1.3/css/bootstrap-slider.min.css">
<style>
body {
text-align: center;
}
svg {
margin: 10px;
}
svg path {
fill: none;
stroke: #3A5894;
stroke-width: 0.3;
stroke-linecap: square;
}
svg path.skeleton {
stroke: #EEE;
stroke-width: 0.1;
}
#val-tooltip {
display: none;
position: absolute;
margin-top: 22px;
margin-left: -1px;
padding: 5px;
border-radius: 3px;
font: 11px sans-serif;
color: #eee;
background: rgba(0,0,140,0.9);
text-align: center;
pointer-events: none;
}
</style>
</head>
<body>
<svg id="hilbert-chart"></svg>
<div id="hilbert-controls">
<input id="hilbert-order"/>
</div>
<div id="val-tooltip"></div>
<script>
hilbertDemo();
</script>
</body>
https://code.jquery.com/jquery-3.1.0.min.js
https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.6/d3.min.js
https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/9.1.3/bootstrap-slider.min.js
https://unpkg.com/d3-hilbert