forked from kenilGamer/frostnetwork-pro2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (52 loc) · 1.56 KB
/
Copy pathscript.js
File metadata and controls
69 lines (52 loc) · 1.56 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
ctx.fillStyle = "rgba(0, 0, 0, 0.98)";
// ctx.fillStyle = "#000000f5";
ctx.fillRect(0, 0, canvas.width, canvas.height ,10);
ctx.lineJoin = "round";
ctx.lineCap = "round";
// Adjust the line width based on the device type
ctx.lineWidth = isMobile() ? 80 : 200;
ctx.globalCompositeOperation = "destination-out";
let isDrawing = false;
let lastX = 0;
let lastY = 0;
function draw(e) {
if (!isDrawing) return;
// Use touch events for mobile devices
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
const clientY = e.touches ? e.touches[0].clientY : e.clientY;
ctx.beginPath();
ctx.moveTo(lastX, lastY);
ctx.lineTo(clientX, clientY);
ctx.stroke();
lastX = clientX;
lastY = clientY;
}
canvas.addEventListener("mousedown", (e) => {
isDrawing = true;
lastX = e.clientX;
lastY = e.clientY;
});
canvas.addEventListener("touchstart", (e) => {
isDrawing = true;
lastX = e.touches[0].clientX;
lastY = e.touches[0].clientY;
});
canvas.addEventListener("mousemove", draw);
canvas.addEventListener("touchmove", draw);
canvas.addEventListener("mouseup", () => {
isDrawing = false;
});
canvas.addEventListener("touchend", () => {
isDrawing = false;
});
canvas.addEventListener("mouseout", () => {
isDrawing = false;
});
// Function to check if the device is a mobile device
function isMobile() {
return /Mobi|Android/i.test(navigator.userAgent);
}