fillRect(3)


HTML


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload = function(){
var canvas = document.getElementById('canvas');
if(canvas.getContext){
//Context 객체가 그림을 그려줌
var context = canvas.getContext('2d');
//채우기 색상 지정
context.fillStyle ='rgb(200,0,0)';
//색이 칠해져 있는 사각형
context.fillRect(10,10,100,100); //x,y,w,h
//채우기 색상 및 투명도 지정
context.fillStyle = 'rgba(0,0,200,0.5)';
context.fillRect(50,50,100,100); //x,y,w,h
//특정 영역을 지우고 완전 투명
context.clearRect(60,60,40,40);
//선의 색상지정
context.strokeStyle = 'rgb(200,0,250)';
//테두리만 있는 사각형
context.strokeRect(200,50,70,150);
}else{
alert('브라우저가 캔버스를 지원하지 않습니다.');
}
};
</script>
</head>
<body>
<canvas id="canvas" width="500" height="300"></canvas>
</body>
</html>


결과






+ Recent posts