mouseenter, mousedown 이벤트
if(!isDrawing) { // mousedown일 때만 실제로 그려짐
ctx.beginPath(); // 새로운 path 시작
ctx.moveTo(drawX, drawY); // 실시간 offset 감지, 안할시 마지막 path에서 이어짐
} else {
ctx.lineTo(drawX, drawY);
ctx.stroke(); // path에 stroke주기
}
clearRect (x좌표, y좌표, 너비, 높이)
function reset() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
CanvasRenderingContext2D
The CanvasRenderingContext2D interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a canvas element. It is used for drawing shapes, text, images, and other objects.
developer.mozilla.org
developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clearRect
CanvasRenderingContext2D.clearRect()
The CanvasRenderingContext2D.clearRect() method of the Canvas 2D API erases the pixels in a rectangular area by setting them to transparent black.
developer.mozilla.org
'javascript' 카테고리의 다른 글
storage에 객체 저장하고 꺼내기 (0) | 2020.11.08 |
---|---|
[Vanilla JS] 여러개의 요소에 AddEventListener 넣기 (0) | 2020.11.08 |
javascript prototype 스터디 (0) | 2020.11.02 |
배열을 객체로, 객체를 배열로 (0) | 2020.10.15 |
parameter(매개변수)와 argument(인자)의 차이 (0) | 2020.10.06 |
댓글