-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlines_api.js
36 lines (28 loc) · 1.02 KB
/
lines_api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function drawLines(linesData) {
const { strokeWidth, gap, angle, foregroundColor, backgroundColor } = linesData;
const canvas = document.getElementById("projectionCanvas");
const ctx = canvas.getContext("2d");
// Clear the canvas
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Calculate the center of the canvas
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
// Rotate the canvas about its center
ctx.translate(centerX, centerY);
ctx.rotate((angle * Math.PI) / 180);
ctx.translate(-centerX, -centerY);
// Set the stroke style and line width
ctx.strokeStyle = foregroundColor;
ctx.lineWidth = strokeWidth;
// Draw the horizontal lines
const lineSpacing = strokeWidth + gap;
for (let y = -centerY; y < centerY + canvas.height; y += lineSpacing) {
ctx.beginPath();
ctx.moveTo(-centerX, y);
ctx.lineTo(centerX + canvas.width, y);
ctx.stroke();
}
// Reset the canvas transformation
ctx.setTransform(1, 0, 0, 1, 0, 0);
}