debug = {
let columns = 1;
let rows = 1;
let iwidth = 150;
let iheight = 150;
let width = iwidth * columns;
let height = iheight * rows;
let canvas = document.createElement("canvas");
let dpr = window.devicePixelRatio || 1;
canvas.width = width * dpr;
canvas.height = height * dpr;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
let ctx = canvas.getContext("2d");
ctx.scale(dpr, dpr);
let cells = [];
for (let r = 0; r < rows; r++) {
for (let c = 0; c < columns; c++) {
cells.push([c, r]);
}
}
for (let f = 0; f < cells.length; f++) {
let cell = cells[f];
let cx = cells[f][0] * iwidth + iwidth / 2;
let cy = cells[f][1] * iheight + iheight / 2;
ctx.fillStyle = "lightblue";
ctx.strokeStyle = "lightblue";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(cx, cy, 14, 0, 2 * Math.PI, false);
ctx.fill();
if (cell[1] < rows - 1) {
ctx.beginPath();
let next_y = cy + iheight;
for (let c = 0; c < columns; c++) {
ctx.moveTo(cx, cy);
let next_x = c * iwidth + iwidth / 2;
ctx.lineTo(next_x, next_y);
}
ctx.stroke();
}
}
ctx.strokeStyle = "black";
ctx.fillStyle = "black";
ctx.lineWidth = 1;
for (let f = 0; f < cells.length; f++) {
let offset_x = cells[f][0] * iwidth;
let offset_y = cells[f][1] * iheight;
let sides = 6;
let slice_offset = toRadians(180 / sides);
let side_size = (0.5 + Math.random() * 0.5) * iwidth;
side_size = iwidth;
let opposite = (Math.sin(slice_offset) * side_size) / 2;
let adjacent = (Math.cos(slice_offset) * side_size) / 2;
ctx.lineWidth = 2;
let spikes = [];
let spike_num = Math.floor(2 + Math.random() * 10);
let spike_step = side_size / 2 / spike_num;
for (let i = 1; i < spike_num + 1; i++) {
let distance = i * spike_step;
let offdist = distance - distance * 0.2;
let spike_opposite = Math.sin(slice_offset) * distance;
let spike_adjacent = Math.cos(slice_offset) * distance;
let off_opposite = Math.sin(slice_offset) * offdist;
let off_adjacent = Math.cos(slice_offset) * offdist;
let jitter = Math.random();
let x_dist = spike_adjacent - off_adjacent;
let y_dist = spike_opposite;
let new_x = iwidth / 2 + off_adjacent + x_dist * jitter;
let new_y = iheight / 2 + y_dist * jitter;
let new_other_y = iheight / 2 - y_dist * jitter;
spikes.push([
[new_x, new_y],
[iwidth / 2 + off_adjacent, iheight / 2],
[new_x, new_other_y]
]);
}
for (let i = 0; i < sides; i++) {
ctx.save();
ctx.translate(iwidth / 2 + offset_x, iheight / 2 + offset_y);
ctx.rotate((i / sides) * toRadians(360) + toRadians(90));
ctx.translate(-iwidth / 2, -iheight / 2);
ctx.beginPath();
ctx.moveTo(iwidth / 2, iheight / 2);
ctx.lineTo(iwidth / 2 + adjacent - adjacent * 0.2, iheight / 2);
for (let s = 0; s < spikes.length; s++) {
let spike = spikes[s];
ctx.moveTo(...spike[0]);
ctx.lineTo(...spike[1]);
ctx.lineTo(...spike[2]);
}
ctx.stroke();
ctx.restore();
}
}
return canvas;
}