summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2024-03-05 12:51:29 +0200
committerMartial Simon <msimon_fr@hotmail.com>2024-03-05 12:51:29 +0200
commite78b671a3062d285cfa932589760c5326ba486a2 (patch)
tree4a39a829ddc5c4101f66e5efbb8c6ed96251d6f5 /index.js
parentded4a9e2075960c3ba08b63b882585ed4e3d5994 (diff)
meta: renamed description
Diffstat (limited to 'index.js')
-rw-r--r--index.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/index.js b/index.js
index cb2b1b3..e217344 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
const canvas = document.getElementById('drawing-board');
const ctx = canvas.getContext('2d');
+const hit = document.getElementById("check");
const canvasOffsetX = canvas.offsetLeft;
const canvasOffsetY = canvas.offsetTop;
@@ -11,48 +12,55 @@ let isPainting = false;
let lineWidth = 5;
let strokeColor = "skyblue"
let drawings = [];
+
+ctx.lineWidth = lineWidth;
+ctx.lineCap = 'round';
ctx.strokeStyle = strokeColor;
const draw = (x, y) => {
if (!isPainting) {
return;
}
-
+
ctx.lineWidth = lineWidth;
ctx.lineCap = 'round';
ctx.lineTo(x - canvasOffsetX, y - canvasOffsetY);
drawings.push({x : (x - canvasOffsetX)/canvas.width, y : (y - canvasOffsetY)/canvas.height});
ctx.stroke();
+ ctx.beginPath();
}
-
canvas.addEventListener('mousedown', (e) => {
isPainting = true;
+ hit.style.display = "";
+ setTimeout(() => {
+ hit.style.display = "none"
+ }, 2 * 1000);
});
-canvas.addEventListener('mouseup', (e) => {
+/* canvas.addEventListener('mouseup', (e) => {
isPainting = false;
drawings.push({x : -1, y : -1})
ctx.stroke();
ctx.beginPath();
-});
+}); */
-canvas.addEventListener('mousemove', (e) => draw(e.clientX, e.clientY));
+// canvas.addEventListener('mousemove', (e) => draw(e.clientX, e.clientY));
canvas.addEventListener('touchstart', (e) => {
- console.log(e);
isPainting = true;
+ draw(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
});
-canvas.addEventListener('touchend', (e) => {
+/* canvas.addEventListener('touchend', (e) => {
isPainting = false;
drawings.push({x : -1, y : -1})
ctx.stroke();
ctx.beginPath();
-});
+}); */
-canvas.addEventListener('touchmove', (e) => draw(e.targetTouches[0].clientX, e.targetTouches[0].clientY));
+// canvas.addEventListener('touchmove', (e) => draw(e.targetTouches[0].clientX, e.targetTouches[0].clientY));
function redrawCanvas() {
canvas.width = window.innerWidth - canvasOffsetX * 2;