canvas 의 clearRect : 해당하는 영역만큼 지운다



html)

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
    <script type="text/javascript">
    window.onload = function(){
        var canvas = document.getElementById("canvas");
        if(canvas.getContext){
            var draw = canvas.getContext("2d");
            
            draw.beginPath();
            //rect(왼쪽위 x, 왼쪽위 y, 가로크기, 세로크기)
            draw.rect(50,50,200,200);
            draw.lineWidth = 10;
            draw.strokeStyle = "green";
            draw.fillStyle = "#6799FF";
            //fill : 채우기
            draw.fill();
            //stroke : 선그리기
            draw.stroke();
            
            
            draw.beginPath();
            //clearRect(왼쪽위 x, 왼쪽위 y, 가로크기, 세로크기) : 해당하는 영역만큼 지운다
            draw.clearRect(100,100,100,100);
            draw.fill();
        }
    }
    </script>
</head>
 
<body>
    <canvas id="canvas" width="300px" height="400px"></canvas>
</body>
</html>
cs



결과

+ Recent posts