importation 'desktop/ERGGGGGG/chimère' to 'desktop/Holzwege' index.html, styles.css, script.js - correction <p>050226</p> : int(é)ressé, au(x), détail(s), anodin(s)
This commit is contained in:
43
script.js
Normal file
43
script.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const canvas = document.getElementById("mycanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
|
||||
/*taille du canvas*/
|
||||
function taillecanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
taillecanvas();
|
||||
window.addEventListener("resize", taillecanvas);
|
||||
|
||||
|
||||
/*tracé*/
|
||||
ctx.strokeStyle = "black";
|
||||
ctx.lineWidth = 0.5;
|
||||
|
||||
|
||||
/*mémorise la position du x et y précédent*/
|
||||
let lastX = null;
|
||||
let lastY = null;
|
||||
|
||||
document.addEventListener("mousemove", (e) => {
|
||||
if (lastX === null || lastY === null) {
|
||||
lastX = e.clientX;
|
||||
lastY = e.clientY;
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lastX, lastY);
|
||||
ctx.lineTo(e.clientX, e.clientY);
|
||||
ctx.stroke();
|
||||
|
||||
lastX = e.clientX;
|
||||
lastY = e.clientY;
|
||||
});
|
||||
|
||||
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = window.innerWidth * dpr;
|
||||
canvas.height = window.innerHeight * dpr;
|
||||
ctx.scale(dpr, dpr);
|
||||
|
||||
Reference in New Issue
Block a user