path


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){
var context = canvas.getContext('2d');
/*
선 그리기
1. 패스 시작
2. 지정한 패스를 그리기/채우기 메서드 이용
3. 패스 닫기
*/
context.beginPath(); //path 시작
context.moveTo(50,50); //시작점을 옮기는 역할
context.lineTo(80,80); //왼쪽 작은 직선
context.moveTo(140,80);
context.lineTo(170,50);
context.moveTo(60,150);
context.lineTo(170,150);
context.closePath();
context.stroke(); //이거 없으면 안나옴 매우중요함.
}else{
alert('브라우저가 캔버스를 지원하지 않습니다.');
}
};
</script>
</head>
<body>
<canvas id="canvas" width="500" height="300"></canvas>
</body>
</html>


결과











+ Recent posts