본문 바로가기
javascript

canvas context 학습내용1

by 바나냥 2020. 11. 7.

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

 

댓글