cos_grid = {
const context = DOM.context2d(width, height);
context.clearRect(0, 0, width, height);
let points = new FastPoissonDiskSampling({
shape: [width, height],
radius: 8,
tries: 1
});
let noise = new noisejs.Noise();
noise.seed(d3.randomInt(65536)());
let voronoi = new d3.Delaunay(points.fill().flat()).voronoi([0, 0, width, height]);
let colors = d3.schemeSpectral[11];
let scale = d3.scaleQuantize()
.domain([0, 1])
.range([colors[11],colors[11],colors[10],colors[10],
colors[9],colors[9],colors[8],colors[8],
colors[7],colors[6],colors[5],colors[4],
colors[3],colors[2],colors[1]])
let { corners, triangles } = voronoi.delaunay;
let n_tri = triangles.length / 3;
let center_x = width / 2;
let center_y = height / 2;
let dist_factor = 0.5 * Math.sqrt( (width * width) + (height * height));
for (let i = 0; i < n_tri; i++) {
let polygon = voronoi.delaunay.trianglePolygon(i);
let x = polygon[0][0];
let y = polygon[0][1];
let noise_value = (noise.simplex2(x / 512, y / 384));
let noise_value_2 = (noise.simplex2(x / 32, y / 24));
let dist = Math.sqrt( (x - center_x) * (x - center_x) + (y - center_y) * (y - center_y) );
let dist_value = 1 - (dist / dist_factor);
let cos_dist = Math.cos(dist * Math.PI * 0.5 / dist_factor);
let n_val = noise_value > 0 ? noise_value : 0.0;
let comb_value = cos_dist * 0.3 + (n_val) * 0.9 * cos_dist;
if (comb_value <= 0.3) {
context.fillStyle = scale(0.2);
} else if (comb_value <= 0.8) {
context.fillStyle = scale(comb_value);
} else {
context.fillStyle = scale(0.8);
}
context.beginPath();
voronoi.delaunay.renderTriangle(i,context);
context.fill()
}
return context.canvas;
}