JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://d3js.org/d3.v4.min.js"></script>
<svg width="400" height="400"></svg>

JavaScript

var svg = d3.select("svg"),
    width = +svg.attr("width"),
    height = +svg.attr("height");

var npoints = 1000;
var sites = d3.range(npoints)
    .map(function(d) { return [Math.random() * width, Math.random() * height]; });


// values  at data points / colors being mapped = "zvals"
var kx = 3.14159/(width*0.5);
var ky = 3.14159/(height*0.5);
var zvals = d3.range(npoints)
for (i = 0; i < npoints; i++) { 
    zvals[i] = (1.0 + Math.cos(kx*sites[i][0]) * Math.cos(ky*sites[i][1]))/2.0;
    zvals[i] *= zvals[i];
}

var g = svg.append("g")
    .attr("transform", "translate(" + 0+ "," + 0 + ")");

var voronoi = d3.voronoi()
    .extent([[-1, -1], [width + 1, height + 1]]);

var polygon = svg.append("g")
    .attr("class", "polygons")
    .selectAll("path")
    .data(voronoi.polygons(sites))
    .enter().append("path")
    .style('fill', function(d,i){ return d3.hsl( zvals[i]*310,        1, .5); })
    .call(redrawPolygon);

function redrawPolygon(polygon) {
  polygon
      .attr("d", function(d) { return d ? "M" + d.join("L") + "Z" : null; });
}