function getHalftone(cmykValues, width, height, color = 'k', spacing = 5, rotationDegrees = 0) {
const angle = rotationDegrees * Math.PI / 180;
const diagonal = Math.sqrt(width ** 2 + height ** 2);
const halfD = Math.floor(diagonal/2);
const halfW = Math.floor(width/2);
const halfH = Math.floor(height/2);
const minX = Math.floor((width - diagonal) / 2) - halfD;
const minY = Math.floor((height - diagonal) / 2) - halfD;
let fillStyle;
let colorIndex;
if (color === 'c') {
fillStyle = 'rgba(0,255,255,1)';
colorIndex = 0;
} else if (color === 'm') {
fillStyle = 'rgba(255,0,255,1)';
colorIndex = 1;
} else if (color === 'y') {
fillStyle = 'rgba(255,255,0,1)';
colorIndex = 2;
} else {
fillStyle = 'rgba(0,0,0,1)';
colorIndex = 3;
}
const canvas = DOM.canvas(width, height);
const ctx = canvas.getContext('2d');
ctx.fillStyle = fillStyle;
ctx.beginPath();
let count = 0;
for (let x = minX; x < diagonal; x += spacing) {
for (let y = minY; y < diagonal; y += spacing) {
count += 1;
const rotatedX = x * Math.cos(angle) - y * Math.sin(angle) + halfW;
const rotatedY = x * Math.sin(angle) + y * Math.cos(angle) + halfH;
if (rotatedX < 0 || rotatedY < 0 || rotatedX >= width || rotatedY >= height) continue;
const cmyk = cmykValues[Math.floor(rotatedY) * width + Math.floor(rotatedX)];
ctx.moveTo(rotatedX, rotatedY);
ctx.arc(rotatedX, rotatedY, dotScale(cmyk[colorIndex]), 0, Math.PI * 2, true);
}
}
console.log(count)
ctx.fill();
return canvas;
}